Code refactor: improve attribute handling for optional volume attributes.

A volume shader should be able to request attributes, and still be rendered
as homogeneous if no volume attributes are available for the object.
This commit is contained in:
Brecht Van Lommel
2018-02-18 03:20:39 +01:00
parent 4448ed6c5e
commit a963c7d48d
14 changed files with 126 additions and 41 deletions

View File

@@ -744,6 +744,10 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath)
current_shader->has_object_dependency = true;
}
if(node->has_attribute_dependency()) {
current_shader->has_attribute_dependency = true;
}
if(node->has_integrator_dependency()) {
current_shader->has_integrator_dependency = true;
}
@@ -991,6 +995,14 @@ void OSLCompiler::parameter_color_array(const char *name, const array<float3>& f
ss->Parameter(name, type, table.data());
}
void OSLCompiler::parameter_attribute(const char *name, ustring s)
{
if(Attribute::name_standard(s.c_str()))
parameter(name, (string("geom:") + s.c_str()).c_str());
else
parameter(name, s.c_str());
}
void OSLCompiler::find_dependencies(ShaderNodeSet& dependencies, ShaderInput *input)
{
ShaderNode *node = (input->link)? input->link->parent: NULL;
@@ -1124,6 +1136,7 @@ void OSLCompiler::compile(Scene *scene, OSLGlobals *og, Shader *shader)
shader->has_surface_spatial_varying = false;
shader->has_volume_spatial_varying = false;
shader->has_object_dependency = false;
shader->has_attribute_dependency = false;
shader->has_integrator_dependency = false;
/* generate surface shader */