diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-08-21 01:05:07 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-08-21 01:09:16 +0300 |
commit | 47d1f67eab9bffa53fb8f498b1478094f0039f3a (patch) | |
tree | 346653c61ca70b632f9d32f7db2fd588b06815d2 /source | |
parent | 41e6068c76447e7c3b9c281f508eae03d3dea804 (diff) |
Fix T52473: blender internal Fresnel and Layer Weight only work with linked normal.
Please backport this to 2.79.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_fresnel.c | 19 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_layer_weight.c | 19 |
2 files changed, 28 insertions, 10 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_fresnel.c b/source/blender/nodes/shader/nodes/node_shader_fresnel.c index 5a9e33a4053..8262b70fc44 100644 --- a/source/blender/nodes/shader/nodes/node_shader_fresnel.c +++ b/source/blender/nodes/shader/nodes/node_shader_fresnel.c @@ -51,14 +51,23 @@ static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *UNUSED(node), bNodeE return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION)); } -static void node_shader_exec_fresnel(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_fresnel(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) { ShadeInput *shi = ((ShaderCallData *)data)->shi; - float eta = max_ff(in[0]->vec[0], 0.00001); + + /* Compute IOR. */ + float eta; + nodestack_get_vec(&eta, SOCK_FLOAT, in[0]); + eta = max_ff(eta, 0.00001); + eta = shi->flippednor ? 1 / eta : eta; + + /* Get normal from socket, but only if linked. */ + bNodeSocket *sock_normal = node->inputs.first; + sock_normal = sock_normal->next; float n[3]; - if (in[1]->hasinput) { - copy_v3_v3(n, in[1]->vec); + if (sock_normal->link) { + nodestack_get_vec(n, SOCK_VECTOR, in[1]); } else { copy_v3_v3(n, shi->vn); @@ -68,7 +77,7 @@ static void node_shader_exec_fresnel(void *data, int UNUSED(thread), bNode *UNUS mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), n); } - out[0]->vec[0] = RE_fresnel_dielectric(shi->view, n, shi->flippednor ? 1 / eta : eta); + out[0]->vec[0] = RE_fresnel_dielectric(shi->view, n, eta); } /* node type definition */ diff --git a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c index a0b2408a7bb..998e1a5687e 100644 --- a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c +++ b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c @@ -52,24 +52,33 @@ static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *UNUSED(node), b return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION)); } -static void node_shader_exec_layer_weight(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) +static void node_shader_exec_layer_weight(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out) { ShadeInput *shi = ((ShaderCallData *)data)->shi; - float blend = in[0]->vec[0]; + + /* Compute IOR. */ + float blend; + nodestack_get_vec(&blend, SOCK_FLOAT, in[0]); float eta = max_ff(1 - blend, 0.00001); + eta = shi->flippednor ? eta : 1 / eta; + + /* Get normal from socket, but only if linked. */ + bNodeSocket *sock_normal = node->inputs.first; + sock_normal = sock_normal->next; float n[3]; - if (in[1]->hasinput) { - copy_v3_v3(n, in[1]->vec); + if (sock_normal->link) { + nodestack_get_vec(n, SOCK_VECTOR, in[1]); } else { copy_v3_v3(n, shi->vn); } + if (shi->use_world_space_shading) mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), n); - out[0]->vec[0] = RE_fresnel_dielectric(shi->view, n, shi->flippednor ? eta : 1 / eta); + out[0]->vec[0] = RE_fresnel_dielectric(shi->view, n, eta); float facing = fabs(dot_v3v3(shi->view, n)); if (blend != 0.5) { |