diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-23 21:02:49 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-23 21:02:49 +0300 |
commit | a44b08a6c473c0aae9f98dc13f9d000e5ea639bc (patch) | |
tree | 6b70d6026827b5cf6eed3af1c56a38329c2497bf /intern/cycles/render | |
parent | 0305fc30b3ba6a1b24e2c9c182ae2e76d553f341 (diff) | |
parent | 0aec2dcd3ae0ed382ffe7b3311a4e30fc88398e4 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/attribute.cpp | 35 | ||||
-rw-r--r-- | intern/cycles/render/attribute.h | 1 | ||||
-rw-r--r-- | intern/cycles/render/graph.h | 1 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 166 | ||||
-rw-r--r-- | intern/cycles/render/nodes.h | 33 | ||||
-rw-r--r-- | intern/cycles/render/object.cpp | 9 | ||||
-rw-r--r-- | intern/cycles/render/osl.cpp | 13 | ||||
-rw-r--r-- | intern/cycles/render/osl.h | 2 | ||||
-rw-r--r-- | intern/cycles/render/shader.cpp | 3 | ||||
-rw-r--r-- | intern/cycles/render/shader.h | 1 | ||||
-rw-r--r-- | intern/cycles/render/svm.cpp | 11 | ||||
-rw-r--r-- | intern/cycles/render/svm.h | 1 |
12 files changed, 239 insertions, 37 deletions
diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp index 2c22db8189d..6816f8ca3f3 100644 --- a/intern/cycles/render/attribute.cpp +++ b/intern/cycles/render/attribute.cpp @@ -281,6 +281,8 @@ const char *Attribute::standard_name(AttributeStandard std) return "flame"; case ATTR_STD_VOLUME_HEAT: return "heat"; + case ATTR_STD_VOLUME_TEMPERATURE: + return "temperature"; case ATTR_STD_VOLUME_VELOCITY: return "velocity"; case ATTR_STD_POINTINESS: @@ -296,9 +298,13 @@ const char *Attribute::standard_name(AttributeStandard std) AttributeStandard Attribute::name_standard(const char *name) { - for(int std = ATTR_STD_NONE; std < ATTR_STD_NUM; std++) - if(strcmp(name, Attribute::standard_name((AttributeStandard)std)) == 0) - return (AttributeStandard)std; + if(name) { + for(int std = ATTR_STD_NONE; std < ATTR_STD_NUM; std++) { + if(strcmp(name, Attribute::standard_name((AttributeStandard)std)) == 0) { + return (AttributeStandard)std; + } + } + } return ATTR_STD_NONE; } @@ -425,6 +431,7 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name) case ATTR_STD_VOLUME_DENSITY: case ATTR_STD_VOLUME_FLAME: case ATTR_STD_VOLUME_HEAT: + case ATTR_STD_VOLUME_TEMPERATURE: attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL); break; case ATTR_STD_VOLUME_COLOR: @@ -612,9 +619,11 @@ bool AttributeRequestSet::modified(const AttributeRequestSet& other) void AttributeRequestSet::add(ustring name) { - foreach(AttributeRequest& req, requests) - if(req.name == name) + foreach(AttributeRequest& req, requests) { + if(req.name == name) { return; + } + } requests.push_back(AttributeRequest(name)); } @@ -638,6 +647,22 @@ void AttributeRequestSet::add(AttributeRequestSet& reqs) } } +void AttributeRequestSet::add_standard(ustring name) +{ + if(!name) { + return; + } + + AttributeStandard std = Attribute::name_standard(name.c_str()); + + if(std) { + add(std); + } + else { + add(name); + } +} + bool AttributeRequestSet::find(ustring name) { foreach(AttributeRequest& req, requests) diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h index d15ee401a72..9e23345675d 100644 --- a/intern/cycles/render/attribute.h +++ b/intern/cycles/render/attribute.h @@ -159,6 +159,7 @@ public: void add(ustring name); void add(AttributeStandard std); void add(AttributeRequestSet& reqs); + void add_standard(ustring name); bool find(ustring name); bool find(AttributeStandard std); diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h index 7ed292b5b96..2c134932b3c 100644 --- a/intern/cycles/render/graph.h +++ b/intern/cycles/render/graph.h @@ -156,6 +156,7 @@ public: virtual bool has_bssrdf_bump() { return false; } virtual bool has_spatial_varying() { return false; } virtual bool has_object_dependency() { return false; } + virtual bool has_attribute_dependency() { return false; } virtual bool has_integrator_dependency() { return false; } virtual bool has_volume_support() { return false; } virtual bool has_raytrace() { return false; } diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 56c9e669a5c..7006fb6fe1d 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -208,7 +208,7 @@ NODE_DEFINE(ImageTextureNode) TEXTURE_MAPPING_DEFINE(ImageTextureNode); - SOCKET_STRING(filename, "Filename", ustring("")); + SOCKET_STRING(filename, "Filename", ustring()); static NodeEnum color_space_enum; color_space_enum.insert("none", NODE_COLOR_SPACE_NONE); @@ -419,7 +419,7 @@ NODE_DEFINE(EnvironmentTextureNode) TEXTURE_MAPPING_DEFINE(EnvironmentTextureNode); - SOCKET_STRING(filename, "Filename", ustring("")); + SOCKET_STRING(filename, "Filename", ustring()); static NodeEnum color_space_enum; color_space_enum.insert("none", NODE_COLOR_SPACE_NONE); @@ -1348,7 +1348,7 @@ NODE_DEFINE(PointDensityTextureNode) { NodeType* type = NodeType::add("point_density_texture", create, NodeType::SHADER); - SOCKET_STRING(filename, "Filename", ustring("")); + SOCKET_STRING(filename, "Filename", ustring()); static NodeEnum space_enum; space_enum.insert("object", NODE_TEX_VOXEL_SPACE_OBJECT); @@ -2844,6 +2844,120 @@ void ScatterVolumeNode::compile(OSLCompiler& compiler) compiler.add(this, "node_scatter_volume"); } +/* Principled Volume Closure */ + +NODE_DEFINE(PrincipledVolumeNode) +{ + NodeType* type = NodeType::add("principled_volume", create, NodeType::SHADER); + + SOCKET_IN_STRING(density_attribute, "Density Attribute", ustring()); + SOCKET_IN_STRING(color_attribute, "Color Attribute", ustring()); + SOCKET_IN_STRING(temperature_attribute, "Temperature Attribute", ustring()); + + SOCKET_IN_COLOR(color, "Color", make_float3(0.5f, 0.5f, 0.5f)); + SOCKET_IN_FLOAT(density, "Density", 1.0f); + SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.0f); + SOCKET_IN_COLOR(absorption_color, "Absorption Color", make_float3(0.0f, 0.0f, 0.0f)); + SOCKET_IN_FLOAT(emission_strength, "Emission Strength", 0.0f); + SOCKET_IN_COLOR(emission_color, "Emission Color", make_float3(1.0f, 1.0f, 1.0f)); + SOCKET_IN_FLOAT(blackbody_intensity, "Blackbody Intensity", 0.0f); + SOCKET_IN_COLOR(blackbody_tint, "Blackbody Tint", make_float3(1.0f, 1.0f, 1.0f)); + SOCKET_IN_FLOAT(temperature, "Temperature", 1500.0f); + SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL); + + SOCKET_OUT_CLOSURE(volume, "Volume"); + + return type; +} + +PrincipledVolumeNode::PrincipledVolumeNode() +: VolumeNode(node_type) +{ + closure = CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID; +} + +void PrincipledVolumeNode::attributes(Shader *shader, AttributeRequestSet *attributes) +{ + if(shader->has_volume) { + ShaderInput *density_in = input("Density"); + ShaderInput *blackbody_in = input("Blackbody Intensity"); + + if(density_in->link || density > 0.0f) { + attributes->add_standard(density_attribute); + attributes->add_standard(color_attribute); + } + + if(blackbody_in->link || blackbody_intensity > 0.0f) { + attributes->add_standard(temperature_attribute); + } + + attributes->add(ATTR_STD_GENERATED_TRANSFORM); + } + + ShaderNode::attributes(shader, attributes); +} + +void PrincipledVolumeNode::compile(SVMCompiler& compiler) +{ + ShaderInput *color_in = input("Color"); + ShaderInput *density_in = input("Density"); + ShaderInput *anisotropy_in = input("Anisotropy"); + ShaderInput *absorption_color_in = input("Absorption Color"); + ShaderInput *emission_in = input("Emission Strength"); + ShaderInput *emission_color_in = input("Emission Color"); + ShaderInput *blackbody_in = input("Blackbody Intensity"); + ShaderInput *blackbody_tint_in = input("Blackbody Tint"); + ShaderInput *temperature_in = input("Temperature"); + + if(color_in->link) + compiler.add_node(NODE_CLOSURE_WEIGHT, compiler.stack_assign(color_in)); + else + compiler.add_node(NODE_CLOSURE_SET_WEIGHT, color); + + compiler.add_node(NODE_PRINCIPLED_VOLUME, + compiler.encode_uchar4( + compiler.stack_assign_if_linked(density_in), + compiler.stack_assign_if_linked(anisotropy_in), + compiler.stack_assign(absorption_color_in), + compiler.closure_mix_weight_offset()), + compiler.encode_uchar4( + compiler.stack_assign_if_linked(emission_in), + compiler.stack_assign(emission_color_in), + compiler.stack_assign_if_linked(blackbody_in), + compiler.stack_assign(temperature_in)), + compiler.stack_assign(blackbody_tint_in)); + + int attr_density = compiler.attribute_standard(density_attribute); + int attr_color = compiler.attribute_standard(color_attribute); + int attr_temperature = compiler.attribute_standard(temperature_attribute); + + compiler.add_node( + __float_as_int(density), + __float_as_int(anisotropy), + __float_as_int(emission_strength), + __float_as_int(blackbody_intensity)); + + compiler.add_node( + attr_density, + attr_color, + attr_temperature); +} + +void PrincipledVolumeNode::compile(OSLCompiler& compiler) +{ + if(Attribute::name_standard(density_attribute.c_str())) { + density_attribute = ustring("geom:" + density_attribute.string()); + } + if(Attribute::name_standard(color_attribute.c_str())) { + color_attribute = ustring("geom:" + color_attribute.string()); + } + if(Attribute::name_standard(temperature_attribute.c_str())) { + temperature_attribute = ustring("geom:" + temperature_attribute.string()); + } + + compiler.add(this, "node_principled_volume"); +} + /* Hair BSDF Closure */ NODE_DEFINE(HairBsdfNode) @@ -3167,7 +3281,7 @@ NODE_DEFINE(UVMapNode) { NodeType* type = NodeType::add("uvmap", create, NodeType::SHADER); - SOCKET_IN_STRING(attribute, "attribute", ustring("")); + SOCKET_STRING(attribute, "attribute", ustring()); SOCKET_IN_BOOLEAN(from_dupli, "from dupli", false); SOCKET_OUT_POINT(UV, "UV"); @@ -4465,7 +4579,7 @@ NODE_DEFINE(AttributeNode) { NodeType* type = NodeType::add("attribute", create, NodeType::SHADER); - SOCKET_STRING(attribute, "Attribute", ustring("")); + SOCKET_STRING(attribute, "Attribute", ustring()); SOCKET_OUT_COLOR(color, "Color"); SOCKET_OUT_VECTOR(vector, "Vector"); @@ -4486,16 +4600,12 @@ void AttributeNode::attributes(Shader *shader, AttributeRequestSet *attributes) ShaderOutput *fac_out = output("Fac"); if(!color_out->links.empty() || !vector_out->links.empty() || !fac_out->links.empty()) { - AttributeStandard std = Attribute::name_standard(attribute.c_str()); - - if(std != ATTR_STD_NONE) - attributes->add(std); - else - attributes->add(attribute); + attributes->add_standard(attribute); } - if(shader->has_volume) + if(shader->has_volume) { attributes->add(ATTR_STD_GENERATED_TRANSFORM); + } ShaderNode::attributes(shader, attributes); } @@ -4506,13 +4616,7 @@ void AttributeNode::compile(SVMCompiler& compiler) ShaderOutput *vector_out = output("Vector"); ShaderOutput *fac_out = output("Fac"); ShaderNodeType attr_node = NODE_ATTR; - AttributeStandard std = Attribute::name_standard(attribute.c_str()); - int attr; - - if(std != ATTR_STD_NONE) - attr = compiler.attribute(std); - else - attr = compiler.attribute(attribute); + int attr = compiler.attribute_standard(attribute);; if(bump == SHADER_BUMP_DX) attr_node = NODE_ATTR_BUMP_DX; @@ -5470,7 +5574,7 @@ NODE_DEFINE(NormalMapNode) space_enum.insert("blender_world", NODE_NORMAL_MAP_BLENDER_WORLD); SOCKET_ENUM(space, "Space", space_enum, NODE_TANGENT_RADIAL); - SOCKET_STRING(attribute, "Attribute", ustring("")); + SOCKET_STRING(attribute, "Attribute", ustring()); SOCKET_IN_NORMAL(normal_osl, "NormalIn", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL); SOCKET_IN_FLOAT(strength, "Strength", 1.0f); @@ -5489,7 +5593,7 @@ NormalMapNode::NormalMapNode() void NormalMapNode::attributes(Shader *shader, AttributeRequestSet *attributes) { if(shader->has_surface && space == NODE_NORMAL_MAP_TANGENT) { - if(attribute == ustring("")) { + if(attribute.empty()) { attributes->add(ATTR_STD_UV_TANGENT); attributes->add(ATTR_STD_UV_TANGENT_SIGN); } @@ -5512,7 +5616,7 @@ void NormalMapNode::compile(SVMCompiler& compiler) int attr = 0, attr_sign = 0; if(space == NODE_NORMAL_MAP_TANGENT) { - if(attribute == ustring("")) { + if(attribute.empty()) { attr = compiler.attribute(ATTR_STD_UV_TANGENT); attr_sign = compiler.attribute(ATTR_STD_UV_TANGENT_SIGN); } @@ -5534,7 +5638,7 @@ void NormalMapNode::compile(SVMCompiler& compiler) void NormalMapNode::compile(OSLCompiler& compiler) { if(space == NODE_NORMAL_MAP_TANGENT) { - if(attribute == ustring("")) { + if(attribute.empty()) { compiler.parameter("attr_name", ustring("geom:tangent")); compiler.parameter("attr_sign_name", ustring("geom:tangent_sign")); } @@ -5565,7 +5669,7 @@ NODE_DEFINE(TangentNode) axis_enum.insert("z", NODE_TANGENT_AXIS_Z); SOCKET_ENUM(axis, "Axis", axis_enum, NODE_TANGENT_AXIS_X); - SOCKET_STRING(attribute, "Attribute", ustring("")); + SOCKET_STRING(attribute, "Attribute", ustring()); SOCKET_IN_NORMAL(normal_osl, "NormalIn", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL); SOCKET_OUT_NORMAL(tangent, "Tangent"); @@ -5582,7 +5686,7 @@ void TangentNode::attributes(Shader *shader, AttributeRequestSet *attributes) { if(shader->has_surface) { if(direction_type == NODE_TANGENT_UVMAP) { - if(attribute == ustring("")) + if(attribute.empty()) attributes->add(ATTR_STD_UV_TANGENT); else attributes->add(ustring((string(attribute.c_str()) + ".tangent").c_str())); @@ -5600,7 +5704,7 @@ void TangentNode::compile(SVMCompiler& compiler) int attr; if(direction_type == NODE_TANGENT_UVMAP) { - if(attribute == ustring("")) + if(attribute.empty()) attr = compiler.attribute(ATTR_STD_UV_TANGENT); else attr = compiler.attribute(ustring((string(attribute.c_str()) + ".tangent").c_str())); @@ -5618,7 +5722,7 @@ void TangentNode::compile(SVMCompiler& compiler) void TangentNode::compile(OSLCompiler& compiler) { if(direction_type == NODE_TANGENT_UVMAP) { - if(attribute == ustring("")) + if(attribute.empty()) compiler.parameter("attr_name", ustring("geom:tangent")); else compiler.parameter("attr_name", ustring((string(attribute.c_str()) + ".tangent").c_str())); @@ -5731,7 +5835,7 @@ NODE_DEFINE(VectorDisplacementNode) space_enum.insert("world", NODE_NORMAL_MAP_WORLD); SOCKET_ENUM(space, "Space", space_enum, NODE_NORMAL_MAP_TANGENT); - SOCKET_STRING(attribute, "Attribute", ustring("")); + SOCKET_STRING(attribute, "Attribute", ustring()); SOCKET_IN_COLOR(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f)); SOCKET_IN_FLOAT(midlevel, "Midlevel", 0.0f); @@ -5750,7 +5854,7 @@ VectorDisplacementNode::VectorDisplacementNode() void VectorDisplacementNode::attributes(Shader *shader, AttributeRequestSet *attributes) { if(shader->has_surface && space == NODE_NORMAL_MAP_TANGENT) { - if(attribute == ustring("")) { + if(attribute.empty()) { attributes->add(ATTR_STD_UV_TANGENT); attributes->add(ATTR_STD_UV_TANGENT_SIGN); } @@ -5774,7 +5878,7 @@ void VectorDisplacementNode::compile(SVMCompiler& compiler) int attr = 0, attr_sign = 0; if(space == NODE_NORMAL_MAP_TANGENT) { - if(attribute == ustring("")) { + if(attribute.empty()) { attr = compiler.attribute(ATTR_STD_UV_TANGENT); attr_sign = compiler.attribute(ATTR_STD_UV_TANGENT_SIGN); } @@ -5797,7 +5901,7 @@ void VectorDisplacementNode::compile(SVMCompiler& compiler) void VectorDisplacementNode::compile(OSLCompiler& compiler) { if(space == NODE_NORMAL_MAP_TANGENT) { - if(attribute == ustring("")) { + if(attribute.empty()) { compiler.parameter("attr_name", ustring("geom:tangent")); compiler.parameter("attr_sign_name", ustring("geom:tangent_sign")); } diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index f664ebf545d..33df2866341 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -82,6 +82,7 @@ public: ~ImageTextureNode(); ShaderNode *clone() const; void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } ImageManager *image_manager; int is_float; @@ -112,6 +113,7 @@ public: ~EnvironmentTextureNode(); ShaderNode *clone() const; void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } virtual int get_group() { return NODE_GROUP_LEVEL_2; } ImageManager *image_manager; @@ -257,6 +259,7 @@ public: ~PointDensityTextureNode(); ShaderNode *clone() const; void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } bool has_spatial_varying() { return true; } bool has_object_dependency() { return true; } @@ -361,6 +364,7 @@ public: ClosureType get_closure_type() { return distribution; } void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } }; class DiffuseBsdfNode : public BsdfNode { @@ -394,6 +398,7 @@ public: bool has_integrator_dependency(); void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } }; class TranslucentBsdfNode : public BsdfNode { @@ -556,6 +561,25 @@ public: float anisotropy; }; +class PrincipledVolumeNode : public VolumeNode { +public: + SHADER_NODE_CLASS(PrincipledVolumeNode) + void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } + + ustring density_attribute; + ustring color_attribute; + ustring temperature_attribute; + + float anisotropy; + float3 absorption_color; + float emission_strength; + float3 emission_color; + float blackbody_intensity; + float3 blackbody_tint; + float temperature; +}; + class HairBsdfNode : public BsdfNode { public: SHADER_NODE_CLASS(HairBsdfNode) @@ -572,6 +596,7 @@ class GeometryNode : public ShaderNode { public: SHADER_NODE_CLASS(GeometryNode) void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } bool has_spatial_varying() { return true; } float3 normal_osl; @@ -581,6 +606,7 @@ class TextureCoordinateNode : public ShaderNode { public: SHADER_NODE_CLASS(TextureCoordinateNode) void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } bool has_spatial_varying() { return true; } bool has_object_dependency() { return use_transform; } @@ -594,6 +620,7 @@ class UVMapNode : public ShaderNode { public: SHADER_NODE_CLASS(UVMapNode) void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } bool has_spatial_varying() { return true; } virtual int get_group() { return NODE_GROUP_LEVEL_1; } @@ -627,6 +654,7 @@ class ParticleInfoNode : public ShaderNode { public: SHADER_NODE_CLASS(ParticleInfoNode) void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } virtual int get_group() { return NODE_GROUP_LEVEL_1; } }; @@ -635,6 +663,7 @@ public: SHADER_NODE_CLASS(HairInfoNode) void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } bool has_spatial_varying() { return true; } virtual int get_group() { return NODE_GROUP_LEVEL_1; } virtual int get_feature() { @@ -796,6 +825,7 @@ class AttributeNode : public ShaderNode { public: SHADER_NODE_CLASS(AttributeNode) void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } bool has_spatial_varying() { return true; } ustring attribute; @@ -993,6 +1023,7 @@ class NormalMapNode : public ShaderNode { public: SHADER_NODE_CLASS(NormalMapNode) void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } bool has_spatial_varying() { return true; } virtual int get_group() { return NODE_GROUP_LEVEL_3; } @@ -1007,6 +1038,7 @@ class TangentNode : public ShaderNode { public: SHADER_NODE_CLASS(TangentNode) void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } bool has_spatial_varying() { return true; } virtual int get_group() { return NODE_GROUP_LEVEL_3; } @@ -1046,6 +1078,7 @@ class VectorDisplacementNode : public ShaderNode { public: SHADER_NODE_CLASS(VectorDisplacementNode) void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() { return true; } virtual int get_feature() { return NODE_FEATURE_BUMP; } diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index e03160954bc..b981d2b8849 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -604,9 +604,16 @@ void ObjectManager::device_update_flags(Device *, foreach(Object *object, scene->objects) { if(object->mesh->has_volume) { object_flag[object_index] |= SD_OBJECT_HAS_VOLUME; + object_flag[object_index] &= ~SD_OBJECT_HAS_VOLUME_ATTRIBUTES; + + foreach(Attribute& attr, object->mesh->attributes.attributes) { + if(attr.element == ATTR_ELEMENT_VOXEL) { + object_flag[object_index] |= SD_OBJECT_HAS_VOLUME_ATTRIBUTES; + } + } } else { - object_flag[object_index] &= ~SD_OBJECT_HAS_VOLUME; + object_flag[object_index] &= ~(SD_OBJECT_HAS_VOLUME|SD_OBJECT_HAS_VOLUME_ATTRIBUTES); } if(object->is_shadow_catcher) { object_flag[object_index] |= SD_OBJECT_SHADOW_CATCHER; diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index 4d066c89b76..9e931280691 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -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 */ diff --git a/intern/cycles/render/osl.h b/intern/cycles/render/osl.h index 2be1126fdd3..95e35dd857b 100644 --- a/intern/cycles/render/osl.h +++ b/intern/cycles/render/osl.h @@ -140,6 +140,8 @@ public: void parameter_array(const char *name, const float f[], int arraylen); void parameter_color_array(const char *name, const array<float3>& f); + void parameter_attribute(const char *name, ustring s); + ShaderType output_type() { return current_type; } bool background; diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp index a1ebb26eba3..578c61a3e79 100644 --- a/intern/cycles/render/shader.cpp +++ b/intern/cycles/render/shader.cpp @@ -191,6 +191,7 @@ Shader::Shader() has_surface_spatial_varying = false; has_volume_spatial_varying = false; has_object_dependency = false; + has_attribute_dependency = false; has_integrator_dependency = false; has_volume_connected = false; @@ -463,6 +464,8 @@ void ShaderManager::device_update_common(Device *device, flag |= SD_HAS_ONLY_VOLUME; if(shader->heterogeneous_volume && shader->has_volume_spatial_varying) flag |= SD_HETEROGENEOUS_VOLUME; + if(shader->has_attribute_dependency) + flag |= SD_NEED_ATTRIBUTES; if(shader->has_bssrdf_bump) flag |= SD_HAS_BSSRDF_BUMP; if(device->info.has_volume_decoupled) { diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h index 4a48c1347da..abd483caabc 100644 --- a/intern/cycles/render/shader.h +++ b/intern/cycles/render/shader.h @@ -121,6 +121,7 @@ public: bool has_surface_spatial_varying; bool has_volume_spatial_varying; bool has_object_dependency; + bool has_attribute_dependency; bool has_integrator_dependency; /* displacement */ diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp index b678277433b..c5b4060d5c3 100644 --- a/intern/cycles/render/svm.cpp +++ b/intern/cycles/render/svm.cpp @@ -399,6 +399,12 @@ uint SVMCompiler::attribute(AttributeStandard std) return shader_manager->get_attribute_id(std); } +uint SVMCompiler::attribute_standard(ustring name) +{ + AttributeStandard std = Attribute::name_standard(name.c_str()); + return (std)? attribute(std): attribute(name); +} + bool SVMCompiler::node_skip_input(ShaderNode * /*node*/, ShaderInput *input) { /* nasty exception .. */ @@ -447,6 +453,10 @@ void SVMCompiler::generate_node(ShaderNode *node, ShaderNodeSet& done) 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; } @@ -830,6 +840,7 @@ void SVMCompiler::compile(Scene *scene, 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 bump shader */ diff --git a/intern/cycles/render/svm.h b/intern/cycles/render/svm.h index 0e9905957c7..18be0fa9a22 100644 --- a/intern/cycles/render/svm.h +++ b/intern/cycles/render/svm.h @@ -117,6 +117,7 @@ public: void add_node(const float4& f); uint attribute(ustring name); uint attribute(AttributeStandard std); + uint attribute_standard(ustring name); uint encode_uchar4(uint x, uint y = 0, uint z = 0, uint w = 0); uint closure_mix_weight_offset() { return mix_weight_offset; } |