提交 fb1c4106 编写于 作者: M Matt Pharr

Remove "Handle" from assorted variable names.

上级 eec95f75
......@@ -121,10 +121,10 @@ void CPURender(ParsedScene &parsedScene) {
[&](const std::vector<ShapeSceneEntity> &shapes) -> std::vector<Primitive> {
// Parallelize Shape::Create calls, which will in turn
// parallelize PLY file loading, etc...
pstd::vector<pstd::vector<Shape>> shapeHandleVectors(shapes.size());
pstd::vector<pstd::vector<Shape>> shapeVectors(shapes.size());
ParallelFor(0, shapes.size(), [&](int64_t i) {
const auto &sh = shapes[i];
shapeHandleVectors[i] =
shapeVectors[i] =
Shape::Create(sh.name, sh.renderFromObject, sh.objectFromRender,
sh.reverseOrientation, sh.parameters, &sh.loc, alloc);
});
......@@ -132,7 +132,7 @@ void CPURender(ParsedScene &parsedScene) {
std::vector<Primitive> primitives;
for (size_t i = 0; i < shapes.size(); ++i) {
const auto &sh = shapes[i];
pstd::vector<Shape> &shapes = shapeHandleVectors[i];
pstd::vector<Shape> &shapes = shapeVectors[i];
if (shapes.empty())
continue;
......@@ -155,25 +155,24 @@ void CPURender(ParsedScene &parsedScene) {
for (auto &s : shapes) {
// Possibly create area light for shape
Light areaHandle = nullptr;
Light area = nullptr;
if (sh.lightIndex != -1) {
CHECK_LT(sh.lightIndex, parsedScene.areaLights.size());
const auto &areaLightEntity = parsedScene.areaLights[sh.lightIndex];
Light area = Light::CreateArea(
area = Light::CreateArea(
areaLightEntity.name, areaLightEntity.parameters,
*sh.renderFromObject, mi, s, &areaLightEntity.loc, Allocator{});
areaHandle = area;
if (area) {
std::lock_guard<std::mutex> lock(lightsMutex);
lights.push_back(area);
}
}
if (areaHandle == nullptr && !mi.IsMediumTransition() && !alphaTex)
if (area == nullptr && !mi.IsMediumTransition() && !alphaTex)
primitives.push_back(new SimplePrimitive(s, mtl));
else
primitives.push_back(
new GeometricPrimitive(s, mtl, areaHandle, mi, alphaTex));
new GeometricPrimitive(s, mtl, area, mi, alphaTex));
}
}
return primitives;
......@@ -217,7 +216,7 @@ void CPURender(ParsedScene &parsedScene) {
std::vector<Primitive> prims;
for (auto &s : shapes) {
// Possibly create area light for shape
Light areaHandle = nullptr;
Light area = nullptr;
if (sh.lightIndex != -1) {
CHECK_LT(sh.lightIndex, parsedScene.areaLights.size());
const auto &areaLightEntity = parsedScene.areaLights[sh.lightIndex];
......@@ -226,18 +225,16 @@ void CPURender(ParsedScene &parsedScene) {
if (sh.renderFromObject.IsAnimated())
ErrorExit(&sh.loc, "Animated area lights are not supported.");
Light area = Light::CreateArea(
area = Light::CreateArea(
areaLightEntity.name, areaLightEntity.parameters,
sh.renderFromObject.startTransform, mi, s, &sh.loc, Allocator{});
areaHandle = area;
if (area)
lights.push_back(area);
}
if (areaHandle == nullptr && !mi.IsMediumTransition() && !alphaTex)
if (area == nullptr && !mi.IsMediumTransition() && !alphaTex)
prims.push_back(new SimplePrimitive(s, mtl));
else
prims.push_back(
new GeometricPrimitive(s, mtl, areaHandle, mi, alphaTex));
prims.push_back(new GeometricPrimitive(s, mtl, area, mi, alphaTex));
}
// TODO: could try to be greedy or even segment them according
......
......@@ -146,12 +146,12 @@ static FloatTexture getAlphaTexture(
const ShapeSceneEntity &shape,
const std::map<std::string, FloatTexture> &floatTextures,
Allocator alloc) {
FloatTexture alphaTextureHandle;
FloatTexture alphaTexture;
std::string alphaTexName = shape.parameters.GetTexture("alpha");
if (alphaTexName.empty()) {
if (Float alpha = shape.parameters.GetOneFloat("alpha", 1.f); alpha < 1.f)
alphaTextureHandle = alloc.new_object<FloatConstantTexture>(alpha);
alphaTexture = alloc.new_object<FloatConstantTexture>(alpha);
else
return nullptr;
} else {
......@@ -159,28 +159,28 @@ static FloatTexture getAlphaTexture(
if (iter == floatTextures.end())
ErrorExit(&shape.loc, "%s: alpha texture not defined.", alphaTexName);
alphaTextureHandle = iter->second;
alphaTexture = iter->second;
}
if (!BasicTextureEvaluator().CanEvaluate({alphaTextureHandle}, {})) {
if (!BasicTextureEvaluator().CanEvaluate({alphaTexture}, {})) {
// It would be nice to just use the UniversalTextureEvaluator (maybe
// always), but optix complains "Error: Found call graph recursion"...
Warning(&shape.loc,
"%s: alpha texture too complex for BasicTextureEvaluator "
"(need fallback path). Ignoring for now.",
alphaTexName);
alphaTextureHandle = nullptr;
alphaTexture = nullptr;
}
return alphaTextureHandle;
return alphaTexture;
}
static int getOptixGeometryFlags(bool isTriangle, FloatTexture alphaTextureHandle,
Material materialHandle) {
if (materialHandle && materialHandle.HasSubsurfaceScattering())
static int getOptixGeometryFlags(bool isTriangle, FloatTexture alphaTexture,
Material material) {
if (material && material.HasSubsurfaceScattering())
return OPTIX_GEOMETRY_FLAG_REQUIRE_SINGLE_ANYHIT_CALL;
else if ((alphaTextureHandle && isTriangle) ||
(materialHandle && materialHandle.IsTransparent()))
else if ((alphaTexture && isTriangle) ||
(material && material.IsTransparent()))
// Need anyhit
return OPTIX_GEOMETRY_FLAG_NONE;
else
......@@ -312,8 +312,8 @@ OptixTraversableHandle GPUAccel::createGASForTriangles(
const auto &shape = shapes[shapeIndex];
FloatTexture alphaTextureHandle = getAlphaTexture(shape, floatTextures, alloc);
Material materialHandle = getMaterial(shape, namedMaterials, materials);
FloatTexture alphaTexture = getAlphaTexture(shape, floatTextures, alloc);
Material material = getMaterial(shape, namedMaterials, materials);
OptixBuildInput input = {};
......@@ -331,7 +331,7 @@ OptixTraversableHandle GPUAccel::createGASForTriangles(
input.triangleArray.indexBuffer = CUdeviceptr(mesh->vertexIndices);
triangleInputFlags[buildIndex] =
getOptixGeometryFlags(true, alphaTextureHandle, materialHandle);
getOptixGeometryFlags(true, alphaTexture, material);
input.triangleArray.flags = &triangleInputFlags[buildIndex];
input.triangleArray.numSbtRecords = 1;
......@@ -344,8 +344,8 @@ OptixTraversableHandle GPUAccel::createGASForTriangles(
HitgroupRecord hgRecord;
OPTIX_CHECK(optixSbtRecordPackHeader(intersectPG, &hgRecord));
hgRecord.triRec.mesh = mesh;
hgRecord.triRec.material = materialHandle;
hgRecord.triRec.alphaTexture = alphaTextureHandle;
hgRecord.triRec.material = material;
hgRecord.triRec.alphaTexture = alphaTexture;
hgRecord.triRec.areaLights = {};
if (shape.lightIndex != -1) {
// Note: this will hit if we try to have an instance as an area
......@@ -417,16 +417,16 @@ OptixTraversableHandle GPUAccel::createGASForBLPs(
*gasBounds = Union(*gasBounds, shapeBounds);
Material materialHandle = getMaterial(shape, namedMaterials, materials);
FloatTexture alphaTextureHandle = getAlphaTexture(shape, floatTextures, alloc);
Material material = getMaterial(shape, namedMaterials, materials);
FloatTexture alphaTexture = getAlphaTexture(shape, floatTextures, alloc);
flags.push_back(getOptixGeometryFlags(false, alphaTextureHandle, materialHandle));
flags.push_back(getOptixGeometryFlags(false, alphaTexture, material));
HitgroupRecord hgRecord;
OPTIX_CHECK(optixSbtRecordPackHeader(intersectPG, &hgRecord));
hgRecord.bilinearRec.mesh = mesh;
hgRecord.bilinearRec.material = materialHandle;
hgRecord.bilinearRec.alphaTexture = alphaTextureHandle;
hgRecord.bilinearRec.material = material;
hgRecord.bilinearRec.alphaTexture = alphaTexture;
hgRecord.bilinearRec.areaLights = {};
if (shape.lightIndex != -1) {
auto iter = shapeIndexToAreaLights.find(shapeIndex);
......@@ -477,17 +477,17 @@ OptixTraversableHandle GPUAccel::createGASForQuadrics(
std::vector<unsigned int> flags;
for (size_t shapeIndex = 0; shapeIndex < shapes.size(); ++shapeIndex) {
const auto &shape = shapes[shapeIndex];
if (shape.name != "sphere" && shape.name != "cylinder" && shape.name != "disk")
const auto &s = shapes[shapeIndex];
if (s.name != "sphere" && s.name != "cylinder" && s.name != "disk")
continue;
pstd::vector<Shape> shapeHandles = Shape::Create(
shape.name, shape.renderFromObject, shape.objectFromRender,
shape.reverseOrientation, shape.parameters, &shape.loc, alloc);
if (shapeHandles.empty())
pstd::vector<Shape> shapes = Shape::Create(
s.name, s.renderFromObject, s.objectFromRender,
s.reverseOrientation, s.parameters, &s.loc, alloc);
if (shapes.empty())
continue;
CHECK_EQ(1, shapeHandles.size());
Shape shapeHandle = shapeHandles[0];
CHECK_EQ(1, shapes.size());
Shape shape = shapes[0];
OptixBuildInput buildInput = {};
memset(&buildInput, 0, sizeof(buildInput));
......@@ -499,7 +499,7 @@ OptixTraversableHandle GPUAccel::createGASForQuadrics(
buildInputs.push_back(buildInput);
Bounds3f shapeBounds = shapeHandle.Bounds();
Bounds3f shapeBounds = shape.Bounds();
OptixAabb aabb = {shapeBounds.pMin.x, shapeBounds.pMin.y, shapeBounds.pMin.z,
shapeBounds.pMax.x, shapeBounds.pMax.y, shapeBounds.pMax.z};
shapeAABBs.push_back(aabb);
......@@ -507,17 +507,17 @@ OptixTraversableHandle GPUAccel::createGASForQuadrics(
*gasBounds = Union(*gasBounds, shapeBounds);
// Find alpha texture, if present.
Material materialHandle = getMaterial(shape, namedMaterials, materials);
FloatTexture alphaTextureHandle = getAlphaTexture(shape, floatTextures, alloc);
flags.push_back(getOptixGeometryFlags(false, alphaTextureHandle, materialHandle));
Material material = getMaterial(s, namedMaterials, materials);
FloatTexture alphaTexture = getAlphaTexture(s, floatTextures, alloc);
flags.push_back(getOptixGeometryFlags(false, alphaTexture, material));
HitgroupRecord hgRecord;
OPTIX_CHECK(optixSbtRecordPackHeader(intersectPG, &hgRecord));
hgRecord.quadricRec.shape = shapeHandle;
hgRecord.quadricRec.material = materialHandle;
hgRecord.quadricRec.alphaTexture = alphaTextureHandle;
hgRecord.quadricRec.shape = shape;
hgRecord.quadricRec.material = material;
hgRecord.quadricRec.alphaTexture = alphaTexture;
hgRecord.quadricRec.areaLight = nullptr;
if (shape.lightIndex != -1) {
if (s.lightIndex != -1) {
auto iter = shapeIndexToAreaLights.find(shapeIndex);
// Note: this will hit if we try to have an instance as an area
// light.
......@@ -525,7 +525,7 @@ OptixTraversableHandle GPUAccel::createGASForQuadrics(
CHECK_EQ(iter->second->size(), 1);
hgRecord.quadricRec.areaLight = (*iter->second)[0];
}
hgRecord.quadricRec.mediumInterface = getMediumInterface(shape, media, alloc);
hgRecord.quadricRec.mediumInterface = getMediumInterface(s, media, alloc);
intersectHGRecords.push_back(hgRecord);
......
......@@ -124,18 +124,18 @@ GPUPathIntegrator::GPUPathIntegrator(Allocator alloc, const ParsedScene &scene)
const auto &areaLightEntity = scene.areaLights[shape.lightIndex];
AnimatedTransform renderFromLight(*shape.renderFromObject);
pstd::vector<Shape> shapeHandles =
pstd::vector<Shape> shapes =
Shape::Create(shape.name, shape.renderFromObject, shape.objectFromRender,
shape.reverseOrientation, shape.parameters, &shape.loc, alloc);
if (shapeHandles.empty())
if (shapes.empty())
continue;
Medium outsideMedium = findMedium(shape.outsideMedium, &shape.loc);
pstd::vector<Light> *lightsForShape =
alloc.new_object<pstd::vector<Light>>(alloc);
for (Shape sh : shapeHandles) {
for (Shape sh : shapes) {
if (renderFromLight.IsAnimated())
ErrorExit(&shape.loc, "Animated lights are not supported.");
DiffuseAreaLight *area = DiffuseAreaLight::Create(
......
......@@ -24,7 +24,7 @@ namespace pbrt {
// LightHash Definition
struct LightHash {
PBRT_CPU_GPU
size_t operator()(Light lightHandle) const { return Hash(lightHandle.ptr()); }
size_t operator()(Light light) const { return Hash(light.ptr()); }
};
// UniformLightSampler Definition
......
......@@ -538,19 +538,19 @@ Material Material::Create(const std::string &name,
else if (name == "subsurface")
material = SubsurfaceMaterial::Create(parameters, normalMap, loc, alloc);
else if (name == "mix") {
std::vector<std::string> materials = parameters.GetStringArray("materials");
if (materials.size() != 2)
std::vector<std::string> materialNames = parameters.GetStringArray("materials");
if (materialNames.size() != 2)
ErrorExit(
"Must provide two values for \"string materials\" for mix material.");
Material materialHandles[2];
Material materials[2];
for (int i = 0; i < 2; ++i) {
auto iter = namedMaterials.find(materials[i]);
auto iter = namedMaterials.find(materialNames[i]);
if (iter == namedMaterials.end())
ErrorExit("%s: named material not found.", materials[i]);
materialHandles[i] = iter->second;
ErrorExit("%s: named material not found.", materialNames[i]);
materials[i] = iter->second;
}
material = MixMaterial::Create(materialHandles, parameters, loc, alloc);
material = MixMaterial::Create(materials, parameters, loc, alloc);
} else
ErrorExit(loc, "%s: material type unknown.", name);
......
......@@ -122,8 +122,7 @@ pstd::optional<Spectrum> PiecewiseLinearSpectrum::Read(const std::string &fn,
lambda.push_back(vals[2 * i]);
v.push_back(vals[2 * i + 1]);
}
Spectrum handle = alloc.new_object<PiecewiseLinearSpectrum>(lambda, v, alloc);
return handle;
return Spectrum(alloc.new_object<PiecewiseLinearSpectrum>(lambda, v, alloc));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册