Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2018-01-20 04:01:07 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-01-23 14:49:35 +0300
commitb129ea843a7332ddd96554a8c59be379dabf2210 (patch)
tree8555be190fb59f9eab84b2de2c5a89731e349a0d /intern/cycles/render/graph.cpp
parent4a5ee1a5a2adc8032cf710357081d3a1e3fcad95 (diff)
Cycles: change material output displacement to vector.
Previously only scalar displacement along the normal was supported, now displacement can go in any direction. For backwards compatibility, a Displacement node will be automatically inserted in existing files. This will make it possible to support vector displacement maps in the future. It's already possible to use them to some extent, but requires a manual shader node setup. For tangent space maps the right tangent may also not be available yet, depends on the map. Differential Revision: https://developer.blender.org/D3015
Diffstat (limited to 'intern/cycles/render/graph.cpp')
-rw-r--r--intern/cycles/render/graph.cpp31
1 files changed, 25 insertions, 6 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"));