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

WavefrontIntegrator: use ParsedScene::CreateLights() to create lights

This gets rid of a bunch of unnecessarily duplicated code...
(And removes a long-obsolete assumption that all area lights are
DiffuseAreaLights.)
上级 5d700450
......@@ -1163,9 +1163,13 @@ std::vector<Light> 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)
......
......@@ -149,97 +149,16 @@ WavefrontPathIntegrator::WavefrontPathIntegrator(
LOG_VERBOSE("Starting to create lights");
pstd::vector<Light> allLights;
std::map<int, pstd::vector<Light> *> shapeIndexToAreaLights;
infiniteLights = alloc.new_object<pstd::vector<Light>>(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<UniformInfiniteLight>() || l.Is<ImageInfiniteLight>() ||
l.Is<PortalImageInfiniteLight>())
infiniteLights->push_back(l);
allLights.push_back(l);
}
// Area lights...
std::map<int, pstd::vector<Light> *> shapeIndexToAreaLights;
std::set<std::string> 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<Shape> 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<FloatConstantTexture>(alpha);
pstd::vector<Light> *lightsForShape =
alloc.new_object<pstd::vector<Light>>(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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册