diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-23 15:11:02 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-23 15:19:32 +0300 |
commit | 41cc2ae62639bc6c8480beef86269c5b7fbd11fa (patch) | |
tree | 0ae885cebce8fe72caf2c1acdf172f2fd870bce5 /intern/cycles/render | |
parent | 4ebcdff873cb71bb031155a9bddcc92dde8e6370 (diff) | |
parent | 4a3ddd8a7a5bc1851f832869310b5340a6b41d46 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/graph.cpp | 31 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 41 | ||||
-rw-r--r-- | intern/cycles/render/nodes.h | 14 |
3 files changed, 78 insertions, 8 deletions
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index 56434b39da5..fb2e34c2fc7 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -526,10 +526,10 @@ void ShaderGraph::constant_fold() * that happens to ensure there is still a valid graph for displacement. */ if(has_displacement && !output()->input("Displacement")->link) { - ValueNode *value = (ValueNode*)add(new ValueNode()); + ColorNode *value = (ColorNode*)add(new ColorNode()); value->value = output()->displacement; - connect(value->output("Value"), output()->input("Displacement")); + connect(value->output("Color"), output()->input("Displacement")); } } @@ -861,7 +861,7 @@ void ShaderGraph::bump_from_displacement(bool use_object_space) if(!displacement_in->link) return; - + /* find dependencies for the given input */ ShaderNodeSet nodes_displace; find_dependencies(nodes_displace, displacement_in); @@ -893,15 +893,34 @@ void ShaderGraph::bump_from_displacement(bool use_object_space) /* add bump node and connect copied graphs to it */ BumpNode *bump = (BumpNode*)add(new BumpNode()); bump->use_object_space = use_object_space; + bump->distance = 1.0f; ShaderOutput *out = displacement_in->link; ShaderOutput *out_center = nodes_center[out->parent]->output(out->name()); ShaderOutput *out_dx = nodes_dx[out->parent]->output(out->name()); ShaderOutput *out_dy = nodes_dy[out->parent]->output(out->name()); - connect(out_center, bump->input("SampleCenter")); - connect(out_dx, bump->input("SampleX")); - connect(out_dy, bump->input("SampleY")); + /* convert displacement vector to height */ + VectorMathNode *dot_center = (VectorMathNode*)add(new VectorMathNode()); + VectorMathNode *dot_dx = (VectorMathNode*)add(new VectorMathNode()); + VectorMathNode *dot_dy = (VectorMathNode*)add(new VectorMathNode()); + + dot_center->type = NODE_VECTOR_MATH_DOT_PRODUCT; + dot_dx->type = NODE_VECTOR_MATH_DOT_PRODUCT; + dot_dy->type = NODE_VECTOR_MATH_DOT_PRODUCT; + + GeometryNode *geom = (GeometryNode*)add(new GeometryNode()); + connect(geom->output("Normal"), dot_center->input("Vector2")); + connect(geom->output("Normal"), dot_dx->input("Vector2")); + connect(geom->output("Normal"), dot_dy->input("Vector2")); + + connect(out_center, dot_center->input("Vector1")); + connect(out_dx, dot_dx->input("Vector1")); + connect(out_dy, dot_dy->input("Vector1")); + + connect(dot_center->output("Value"), bump->input("SampleCenter")); + connect(dot_dx->output("Value"), bump->input("SampleX")); + connect(dot_dy->output("Value"), bump->input("SampleY")); /* connect the bump out to the set normal in: */ connect(bump->output("Normal"), set_normal->input("Direction")); diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 4452fadaf02..14c0dbab9f3 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -4780,7 +4780,7 @@ NODE_DEFINE(OutputNode) SOCKET_IN_CLOSURE(surface, "Surface"); SOCKET_IN_CLOSURE(volume, "Volume"); - SOCKET_IN_FLOAT(displacement, "Displacement", 0.0f); + SOCKET_IN_VECTOR(displacement, "Displacement", make_float3(0.0f, 0.0f, 0.0f)); SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f)); return type; @@ -5644,4 +5644,43 @@ void BevelNode::compile(OSLCompiler& compiler) compiler.add(this, "node_bevel"); } +/* Displacement */ + +NODE_DEFINE(DisplacementNode) +{ + NodeType* type = NodeType::add("displacement", create, NodeType::SHADER); + + SOCKET_IN_FLOAT(height, "Height", 0.0f); + SOCKET_IN_FLOAT(scale, "Scale", 1.0f); + SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); + + SOCKET_OUT_VECTOR(displacement, "Displacement"); + + return type; +} + +DisplacementNode::DisplacementNode() +: ShaderNode(node_type) +{ +} + +void DisplacementNode::compile(SVMCompiler& compiler) +{ + ShaderInput *height_in = input("Height"); + ShaderInput *scale_in = input("Scale"); + ShaderInput *normal_in = input("Normal"); + ShaderOutput *displacement_out = output("Displacement"); + + compiler.add_node(NODE_DISPLACEMENT, + compiler.encode_uchar4(compiler.stack_assign(height_in), + compiler.stack_assign(scale_in), + compiler.stack_assign_if_linked(normal_in), + compiler.stack_assign(displacement_out))); +} + +void DisplacementNode::compile(OSLCompiler& compiler) +{ + compiler.add(this, "node_displacement"); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index 64d7522a23a..578451cbcfa 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -154,7 +154,7 @@ public: void *surface; void *volume; - float displacement; + float3 displacement; float3 normal; /* Don't allow output node de-duplication. */ @@ -1027,6 +1027,18 @@ public: int samples; }; +class DisplacementNode : public ShaderNode { +public: + SHADER_NODE_CLASS(DisplacementNode) + virtual int get_feature() { + return NODE_FEATURE_BUMP; + } + + float height; + float scale; + float3 normal; +}; + CCL_NAMESPACE_END #endif /* __NODES_H__ */ |