diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-20 04:01:07 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-23 14:49:35 +0300 |
commit | b129ea843a7332ddd96554a8c59be379dabf2210 (patch) | |
tree | 8555be190fb59f9eab84b2de2c5a89731e349a0d /source/blender | |
parent | 4a5ee1a5a2adc8032cf710357081d3a1e3fcad95 (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 'source/blender')
4 files changed, 18 insertions, 3 deletions
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index f95b1963a91..c99da724794 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -28,7 +28,7 @@ * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 279 -#define BLENDER_SUBVERSION 1 +#define BLENDER_SUBVERSION 2 /* Several breakages with 270, e.g. constraint deg vs rad */ #define BLENDER_MINVERSION 270 #define BLENDER_MINSUBVERSION 6 diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index b89317da84a..b54bd213b74 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -3823,7 +3823,7 @@ void node_displacement(float height, float dist, vec3 N, out vec3 result) /* output */ -void node_output_material(vec4 surface, vec4 volume, float displacement, out vec4 result) +void node_output_material(vec4 surface, vec4 volume, vec3 displacement, out vec4 result) { result = surface; } diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index b4cdb158526..8fa074c5cb7 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -449,6 +449,21 @@ static void ntree_shader_relink_displacement(bNodeTree *ntree, * cycles in the Cycles material :) */ nodeRemLink(ntree, displacement_link); + + /* Convert displacement vector to bump height. */ + bNode *dot_node = nodeAddStaticNode(NULL, ntree, SH_NODE_VECT_MATH); + bNode *geo_node = nodeAddStaticNode(NULL, ntree, SH_NODE_NEW_GEOMETRY); + dot_node->custom1 = 3; /* dot product */ + + nodeAddLink(ntree, + displacement_node, displacement_socket, + dot_node, dot_node->inputs.first); + nodeAddLink(ntree, + geo_node, ntree_shader_node_find_output(geo_node, "Normal"), + dot_node, dot_node->inputs.last); + displacement_node = dot_node; + displacement_socket = ntree_shader_node_find_output(dot_node, "Value"); + /* We can't connect displacement to normal directly, use bump node for that * and hope that it gives good enough approximation. */ diff --git a/source/blender/nodes/shader/nodes/node_shader_output_material.c b/source/blender/nodes/shader/nodes/node_shader_output_material.c index 336536b21ee..aeb8b546eed 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_material.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_material.c @@ -32,7 +32,7 @@ static bNodeSocketTemplate sh_node_output_material_in[] = { { SOCK_SHADER, 1, N_("Surface")}, { SOCK_SHADER, 1, N_("Volume")}, - { SOCK_FLOAT, 1, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { SOCK_VECTOR, 1, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, { -1, 0, "" } }; |