diff --git a/src/pbrt/scene.cpp b/src/pbrt/scene.cpp index 1be3d5fc1189d7e100f38e9e1254186de9572edd..2aedc51bf15a521bee3de62fbc632bc0492db797 100644 --- a/src/pbrt/scene.cpp +++ b/src/pbrt/scene.cpp @@ -1163,9 +1163,13 @@ std::vector ParsedScene::CreateLights( std::string alphaTexName = parameters.GetTexture("alpha"); if (!alphaTexName.empty()) { if (auto iter = textures.floatTextures.find(alphaTexName); - iter != textures.floatTextures.end()) + iter != textures.floatTextures.end()) { + if (Options->useGPU && + !BasicTextureEvaluator().CanEvaluate({iter->second}, {})) + // A warning will be issued elsewhere... + return nullptr; return iter->second; - else + } else ErrorExit(loc, "%s: couldn't find float texture for \"alpha\" parameter.", alphaTexName); } else if (Float alpha = parameters.GetOneFloat("alpha", 1.f); alpha < 1.f) diff --git a/src/pbrt/wavefront/integrator.cpp b/src/pbrt/wavefront/integrator.cpp index 357aa7f81431c4105fe67443b2bb9d86e46baaf1..faa2e6ad38119ff28e67dc51f437d9fde93ebb39 100644 --- a/src/pbrt/wavefront/integrator.cpp +++ b/src/pbrt/wavefront/integrator.cpp @@ -149,97 +149,16 @@ WavefrontPathIntegrator::WavefrontPathIntegrator( LOG_VERBOSE("Starting to create lights"); pstd::vector allLights; - + std::map *> shapeIndexToAreaLights; infiniteLights = alloc.new_object>(alloc); - for (const auto &light : scene.lights) { - Medium outsideMedium = findMedium(light.medium, &light.loc); - if (light.renderFromObject.IsAnimated()) - Warning(&light.loc, - "Animated lights aren't supported. Using the start transform."); - - Light l = Light::Create( - light.name, light.parameters, light.renderFromObject.startTransform, - scene.camera.cameraTransform, outsideMedium, &light.loc, alloc); + for (Light l : scene.CreateLights(alloc, media, textures, &shapeIndexToAreaLights)) { if (l.Is() || l.Is() || l.Is()) infiniteLights->push_back(l); allLights.push_back(l); } - - // Area lights... - std::map *> shapeIndexToAreaLights; - - std::set namedMaterialsThatAreInterfaces; - for (auto iter = scene.namedMaterials.begin(); iter != scene.namedMaterials.end(); - ++iter) { - std::string materialName = iter->second.parameters.GetOneString("type", ""); - if (materialName == "interface" || materialName == "none" || materialName.empty()) - namedMaterialsThatAreInterfaces.insert(iter->first); - } - - for (size_t i = 0; i < scene.shapes.size(); ++i) { - const auto &shape = scene.shapes[i]; - if (shape.lightIndex == -1) - continue; - - auto isInterface = [&]() { - if (shape.materialIndex != -1) { - std::string materialName = scene.materials[shape.materialIndex].name; - return (materialName == "interface" || materialName == "none" || - materialName.empty()); - } else - return (namedMaterialsThatAreInterfaces.find(shape.materialName) != - namedMaterialsThatAreInterfaces.end()); - }; - if (isInterface()) - continue; - - CHECK_LT(shape.lightIndex, scene.areaLights.size()); - const auto &areaLightEntity = scene.areaLights[shape.lightIndex]; - AnimatedTransform renderFromLight(*shape.renderFromObject); - - pstd::vector shapes = - Shape::Create(shape.name, shape.renderFromObject, shape.objectFromRender, - shape.reverseOrientation, shape.parameters, - textures.floatTextures, &shape.loc, alloc); - - if (shapes.empty()) - continue; - - Medium outsideMedium = findMedium(shape.outsideMedium, &shape.loc); - - FloatTexture alphaTex; - std::string alphaTexName = shape.parameters.GetTexture("alpha"); - if (!alphaTexName.empty()) { - if (textures.floatTextures.find(alphaTexName) != - textures.floatTextures.end()) { - alphaTex = textures.floatTextures[alphaTexName]; - if (!BasicTextureEvaluator().CanEvaluate({alphaTex}, {})) - // A warning will be issued elsewhere... - alphaTex = nullptr; - } else - ErrorExit(&shape.loc, - "%s: couldn't find float texture for \"alpha\" parameter.", - alphaTexName); - } else if (Float alpha = shape.parameters.GetOneFloat("alpha", 1.f); alpha < 1.f) - alphaTex = alloc.new_object(alpha); - - pstd::vector *lightsForShape = - alloc.new_object>(alloc); - for (Shape sh : shapes) { - if (renderFromLight.IsAnimated()) - ErrorExit(&shape.loc, "Animated lights are not supported."); - DiffuseAreaLight *area = DiffuseAreaLight::Create( - renderFromLight.startTransform, outsideMedium, areaLightEntity.parameters, - areaLightEntity.parameters.ColorSpace(), &areaLightEntity.loc, alloc, sh, - alphaTex); - allLights.push_back(area); - lightsForShape->push_back(area); - } - shapeIndexToAreaLights[i] = lightsForShape; - } LOG_VERBOSE("Done creating lights"); LOG_VERBOSE("Starting to create materials");