diff options
author | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-09-12 18:42:13 +0300 |
---|---|---|
committer | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-09-12 18:42:13 +0300 |
commit | 2ea82e86ca60c1c268c6074ecba10524cebd97ed (patch) | |
tree | bf355c2a930f584685f68a833ce620ad15e63a70 /intern/cycles/render | |
parent | f80018b5f7497d7ed0fe79783c4cd76f05ec1c7c (diff) |
Shading: Add Vertex Color node.
This patch adds a new Vertex Color node. The node also returns the alpha
of the vertex color layer as an output.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D5767
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/attribute.cpp | 3 | ||||
-rw-r--r-- | intern/cycles/render/mesh.cpp | 10 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 58 | ||||
-rw-r--r-- | intern/cycles/render/nodes.h | 16 |
4 files changed, 86 insertions, 1 deletions
diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp index f1341d50b9d..0fa1142f354 100644 --- a/intern/cycles/render/attribute.cpp +++ b/intern/cycles/render/attribute.cpp @@ -48,7 +48,8 @@ void Attribute::set(ustring name_, TypeDesc type_, AttributeElement element_) /* string and matrix not supported! */ assert(type == TypeDesc::TypeFloat || type == TypeDesc::TypeColor || type == TypeDesc::TypePoint || type == TypeDesc::TypeVector || - type == TypeDesc::TypeNormal || type == TypeDesc::TypeMatrix || type == TypeFloat2); + type == TypeDesc::TypeNormal || type == TypeDesc::TypeMatrix || type == TypeFloat2 || + type == TypeRGBA); } void Attribute::resize(Mesh *mesh, AttributePrimitive prim, bool reserve_only) diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index 3d2cc98d38b..9be078b6fca 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -1223,6 +1223,8 @@ void MeshManager::update_osl_attributes(Device *device, osl_attr.type = TypeDesc::TypeMatrix; else if (req.triangle_type == TypeFloat2) osl_attr.type = TypeFloat2; + else if (req.triangle_type == TypeRGBA) + osl_attr.type = TypeRGBA; else osl_attr.type = TypeDesc::TypeColor; @@ -1246,6 +1248,8 @@ void MeshManager::update_osl_attributes(Device *device, osl_attr.type = TypeDesc::TypeMatrix; else if (req.curve_type == TypeFloat2) osl_attr.type = TypeFloat2; + else if (req.curve_type == TypeRGBA) + osl_attr.type = TypeRGBA; else osl_attr.type = TypeDesc::TypeColor; @@ -1269,6 +1273,8 @@ void MeshManager::update_osl_attributes(Device *device, osl_attr.type = TypeDesc::TypeMatrix; else if (req.subd_type == TypeFloat2) osl_attr.type = TypeFloat2; + else if (req.subd_type == TypeRGBA) + osl_attr.type = TypeRGBA; else osl_attr.type = TypeDesc::TypeColor; @@ -1341,6 +1347,8 @@ void MeshManager::update_svm_attributes(Device *, attr_map[index].w = NODE_ATTR_MATRIX; else if (req.triangle_type == TypeFloat2) attr_map[index].w = NODE_ATTR_FLOAT2; + else if (req.triangle_type == TypeRGBA) + attr_map[index].w = NODE_ATTR_RGBA; else attr_map[index].w = NODE_ATTR_FLOAT3; @@ -1379,6 +1387,8 @@ void MeshManager::update_svm_attributes(Device *, attr_map[index].w = NODE_ATTR_MATRIX; else if (req.subd_type == TypeFloat2) attr_map[index].w = NODE_ATTR_FLOAT2; + else if (req.triangle_type == TypeRGBA) + attr_map[index].w = NODE_ATTR_RGBA; else attr_map[index].w = NODE_ATTR_FLOAT3; diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 1d98fabbc9f..71f1863ea49 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -4342,6 +4342,64 @@ void VolumeInfoNode::compile(OSLCompiler &) { } +NODE_DEFINE(VertexColorNode) +{ + NodeType *type = NodeType::add("vertex_color", create, NodeType::SHADER); + + SOCKET_STRING(layer_name, "Layer Name", ustring()); + SOCKET_OUT_COLOR(color, "Color"); + SOCKET_OUT_FLOAT(alpha, "Alpha"); + + return type; +} + +VertexColorNode::VertexColorNode() : ShaderNode(node_type) +{ +} + +void VertexColorNode::attributes(Shader *shader, AttributeRequestSet *attributes) +{ + if (!(output("Color")->links.empty() && output("Alpha")->links.empty())) { + attributes->add_standard(layer_name); + } + ShaderNode::attributes(shader, attributes); +} + +void VertexColorNode::compile(SVMCompiler &compiler) +{ + ShaderOutput *color_out = output("Color"); + ShaderOutput *alpha_out = output("Alpha"); + int layer_id = compiler.attribute(layer_name); + + ShaderNodeType node; + + if (bump == SHADER_BUMP_DX) + node = NODE_VERTEX_COLOR_BUMP_DX; + else if (bump == SHADER_BUMP_DY) + node = NODE_VERTEX_COLOR_BUMP_DY; + else { + node = NODE_VERTEX_COLOR; + } + + compiler.add_node( + node, layer_id, compiler.stack_assign(color_out), compiler.stack_assign(alpha_out)); +} + +void VertexColorNode::compile(OSLCompiler &compiler) +{ + if (bump == SHADER_BUMP_DX) { + compiler.parameter("bump_offset", "dx"); + } + else if (bump == SHADER_BUMP_DY) { + compiler.parameter("bump_offset", "dy"); + } + else { + compiler.parameter("bump_offset", "center"); + } + compiler.parameter("layer_name", layer_name.c_str()); + compiler.add(this, "node_vertex_color"); +} + /* Value */ NODE_DEFINE(ValueNode) diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index 171568644fb..13e9b65fa07 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -979,6 +979,22 @@ class VolumeInfoNode : public ShaderNode { void expand(ShaderGraph *graph); }; +class VertexColorNode : public ShaderNode { + public: + SHADER_NODE_CLASS(VertexColorNode) + void attributes(Shader *shader, AttributeRequestSet *attributes); + bool has_attribute_dependency() + { + return true; + } + bool has_spatial_varying() + { + return true; + } + + ustring layer_name; +}; + class ValueNode : public ShaderNode { public: SHADER_NODE_CLASS(ValueNode) |