diff --git a/src/pbrt/cpu/render.cpp b/src/pbrt/cpu/render.cpp index 4793b22b409a2363a4aa81f3b6f42a802bd63a00..fd8079bf34b394c6ef34fa9bb6c7e7f1d073ba1b 100644 --- a/src/pbrt/cpu/render.cpp +++ b/src/pbrt/cpu/render.cpp @@ -121,10 +121,10 @@ void CPURender(ParsedScene &parsedScene) { [&](const std::vector &shapes) -> std::vector { // Parallelize Shape::Create calls, which will in turn // parallelize PLY file loading, etc... - pstd::vector> shapeHandleVectors(shapes.size()); + pstd::vector> 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 primitives; for (size_t i = 0; i < shapes.size(); ++i) { const auto &sh = shapes[i]; - pstd::vector &shapes = shapeHandleVectors[i]; + pstd::vector &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 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 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 diff --git a/src/pbrt/gpu/accel.cpp b/src/pbrt/gpu/accel.cpp index 0291d42acfc365009c9dac5c715a584a2f20f5ec..2cd81c354ae56e094704341815fcc191ad8eb0cf 100644 --- a/src/pbrt/gpu/accel.cpp +++ b/src/pbrt/gpu/accel.cpp @@ -146,12 +146,12 @@ static FloatTexture getAlphaTexture( const ShapeSceneEntity &shape, const std::map &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(alpha); + alphaTexture = alloc.new_object(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 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 shapeHandles = Shape::Create( - shape.name, shape.renderFromObject, shape.objectFromRender, - shape.reverseOrientation, shape.parameters, &shape.loc, alloc); - if (shapeHandles.empty()) + pstd::vector 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); diff --git a/src/pbrt/gpu/pathintegrator.cpp b/src/pbrt/gpu/pathintegrator.cpp index fc017afe8a9f92c8497cfffba26ded69c16fcbdc..a9c64d1125649aa1e41f5f70192c0f717c1535e3 100644 --- a/src/pbrt/gpu/pathintegrator.cpp +++ b/src/pbrt/gpu/pathintegrator.cpp @@ -124,18 +124,18 @@ GPUPathIntegrator::GPUPathIntegrator(Allocator alloc, const ParsedScene &scene) const auto &areaLightEntity = scene.areaLights[shape.lightIndex]; AnimatedTransform renderFromLight(*shape.renderFromObject); - pstd::vector shapeHandles = + pstd::vector 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 *lightsForShape = alloc.new_object>(alloc); - for (Shape sh : shapeHandles) { + for (Shape sh : shapes) { if (renderFromLight.IsAnimated()) ErrorExit(&shape.loc, "Animated lights are not supported."); DiffuseAreaLight *area = DiffuseAreaLight::Create( diff --git a/src/pbrt/lightsamplers.h b/src/pbrt/lightsamplers.h index 3c2f3036533296e70f2008ceba2ca08154a3dd22..99c4b52af9c28dbb3232f21cef0bc2f798163317 100644 --- a/src/pbrt/lightsamplers.h +++ b/src/pbrt/lightsamplers.h @@ -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 diff --git a/src/pbrt/materials.cpp b/src/pbrt/materials.cpp index 49e3ccb88fa85d1f71a6b3edf3e8b44e4c6408a2..9ad92d09dbe8190422e793a7a28e59cbf39c27e6 100644 --- a/src/pbrt/materials.cpp +++ b/src/pbrt/materials.cpp @@ -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 materials = parameters.GetStringArray("materials"); - if (materials.size() != 2) + std::vector 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); diff --git a/src/pbrt/util/spectrum.cpp b/src/pbrt/util/spectrum.cpp index f80bb063ba3c98c157635600746b0214ab9a4991..5e8b9ff8f2dc44f759328419742e7c10d1344668 100644 --- a/src/pbrt/util/spectrum.cpp +++ b/src/pbrt/util/spectrum.cpp @@ -122,8 +122,7 @@ pstd::optional PiecewiseLinearSpectrum::Read(const std::string &fn, lambda.push_back(vals[2 * i]); v.push_back(vals[2 * i + 1]); } - Spectrum handle = alloc.new_object(lambda, v, alloc); - return handle; + return Spectrum(alloc.new_object(lambda, v, alloc)); } }