diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-08 20:35:20 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-11-08 20:35:20 +0400 |
commit | e73408f2474f7e6d9f1ff880f7f07c678f28e0ce (patch) | |
tree | 550e46facb2837f7841b5ef148b48d8a77b85bdc /intern/cycles/kernel/svm | |
parent | 4063db3f612d6cf0dc3fd63878c18d61bc51f066 (diff) |
Cycles: add strength input for normal map node.
Diffstat (limited to 'intern/cycles/kernel/svm')
-rw-r--r-- | intern/cycles/kernel/svm/svm_tex_coord.h | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/intern/cycles/kernel/svm/svm_tex_coord.h b/intern/cycles/kernel/svm/svm_tex_coord.h index a9449c0ded9..8ca7dff3970 100644 --- a/intern/cycles/kernel/svm/svm_tex_coord.h +++ b/intern/cycles/kernel/svm/svm_tex_coord.h @@ -227,12 +227,14 @@ __device void svm_node_tex_coord_bump_dy(KernelGlobals *kg, ShaderData *sd, floa __device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) { - uint color_offset, normal_offset, space; - decode_node_uchar4(node.y, &color_offset, &normal_offset, &space, NULL); + uint color_offset, strength_offset, normal_offset, space; + decode_node_uchar4(node.y, &color_offset, &strength_offset, &normal_offset, &space); float3 color = stack_load_float3(stack, color_offset); color = 2.0f*make_float3(color.x - 0.5f, color.y - 0.5f, color.z - 0.5f); + float3 N; + if(space == NODE_NORMAL_MAP_TANGENT) { /* tangent space */ if(sd->object == ~0) { @@ -257,19 +259,26 @@ __device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *stac tangent = cross(sd->N, normalize(cross(tangent, sd->N)));; float3 B = sign * cross(sd->N, tangent); - float3 N = color.x * tangent + color.y * B + color.z * sd->N; - - stack_store_float3(stack, normal_offset, normalize(N)); + N = normalize(color.x * tangent + color.y * B + color.z * sd->N); } else { /* object, world space */ - float3 N = color; + N = color; if(space == NODE_NORMAL_MAP_OBJECT) object_normal_transform(kg, sd, &N); - stack_store_float3(stack, normal_offset, normalize(N)); + N = normalize(N); + } + + float strength = stack_load_float(stack, strength_offset); + + if(strength != 1.0f) { + strength = max(strength, 0.0f); + N = normalize(sd->N + (N - sd->N)*strength); } + + stack_store_float3(stack, normal_offset, normalize(N)); } __device void svm_node_tangent(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) |