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 | |
parent | 4063db3f612d6cf0dc3fd63878c18d61bc51f066 (diff) |
Cycles: add strength input for normal map node.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/kernel/shaders/node_normal_map.osl | 4 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_tex_coord.h | 23 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 5 |
3 files changed, 25 insertions, 7 deletions
diff --git a/intern/cycles/kernel/shaders/node_normal_map.osl b/intern/cycles/kernel/shaders/node_normal_map.osl index e238313509e..d101ee870b7 100644 --- a/intern/cycles/kernel/shaders/node_normal_map.osl +++ b/intern/cycles/kernel/shaders/node_normal_map.osl @@ -20,6 +20,7 @@ shader node_normal_map( normal NormalIn = N, + float Strength = 1.0, color Color = color(0.5, 0.5, 1.0), string space = "Tangent", string attr_name = "geom:tangent", @@ -44,5 +45,8 @@ shader node_normal_map( Normal = normalize(transform("object", "world", vector(mcolor))); else if (space == "World") Normal = normalize(vector(mcolor)); + + if (Strength != 1.0) + Normal = normalize(NormalIn + (Normal - NormalIn)*max(Strength, 0.0)); } 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) diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 4f50de11edf..82afab4dc1a 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -3032,7 +3032,9 @@ NormalMapNode::NormalMapNode() attribute = ustring(""); add_input("NormalIn", SHADER_SOCKET_NORMAL, ShaderInput::NORMAL, true); + add_input("Strength", SHADER_SOCKET_FLOAT, 1.0f); add_input("Color", SHADER_SOCKET_COLOR); + add_output("Normal", SHADER_SOCKET_NORMAL); } @@ -3055,6 +3057,7 @@ void NormalMapNode::attributes(AttributeRequestSet *attributes) void NormalMapNode::compile(SVMCompiler& compiler) { ShaderInput *color_in = input("Color"); + ShaderInput *strength_in = input("Strength"); ShaderOutput *normal_out = output("Normal"); int attr = 0, attr_sign = 0; @@ -3070,11 +3073,13 @@ void NormalMapNode::compile(SVMCompiler& compiler) } compiler.stack_assign(color_in); + compiler.stack_assign(strength_in); compiler.stack_assign(normal_out); compiler.add_node(NODE_NORMAL_MAP, compiler.encode_uchar4( color_in->stack_offset, + strength_in->stack_offset, normal_out->stack_offset, space_enum[space]), attr, attr_sign); |