From d236b4d60fb188fcd2bc0aba1ebdff58c8220f60 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 9 May 2013 14:05:37 +0000 Subject: [PATCH] Cycles bump node: change the Strength value to work better, previously it would give results that were either too weak or too strong, this makes it give more predictable results. The downside is that it breaks backwards compatibility but the previous behavior was almost broken. --- intern/cycles/kernel/shaders/node_bump.osl | 4 +++- intern/cycles/kernel/svm/svm_displace.h | 14 ++++++++------ .../blender/nodes/shader/nodes/node_shader_bump.c | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/intern/cycles/kernel/shaders/node_bump.osl b/intern/cycles/kernel/shaders/node_bump.osl index 27770beb776..a7dd805149f 100644 --- a/intern/cycles/kernel/shaders/node_bump.osl +++ b/intern/cycles/kernel/shaders/node_bump.osl @@ -40,10 +40,12 @@ surface node_bump( float det = dot(dPdx, Rx); vector surfgrad = (SampleX - SampleCenter) * Rx + (SampleY - SampleCenter) * Ry; - surfgrad *= Strength; float absdet = fabs(det); + + float strength = clamp(Strength, 0.0, 1.0); /* compute and output perturbed normal */ NormalOut = normalize(absdet * NormalIn - sign(det) * surfgrad); + NormalOut = normalize(strength*NormalOut + (1.0 - strength)*NormalIn); } diff --git a/intern/cycles/kernel/svm/svm_displace.h b/intern/cycles/kernel/svm/svm_displace.h index 92f23990ad1..5d0300c5855 100644 --- a/intern/cycles/kernel/svm/svm_displace.h +++ b/intern/cycles/kernel/svm/svm_displace.h @@ -31,8 +31,8 @@ __device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stack, float3 Ry = cross(normal_in, sd->dP.dx); /* get bump values */ - uint c_offset, x_offset, y_offset, intensity_offset; - decode_node_uchar4(node.z, &c_offset, &x_offset, &y_offset, &intensity_offset); + uint c_offset, x_offset, y_offset, strength_offset; + decode_node_uchar4(node.z, &c_offset, &x_offset, &y_offset, &strength_offset); float h_c = stack_load_float(stack, c_offset); float h_x = stack_load_float(stack, x_offset); @@ -41,14 +41,16 @@ __device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stack, /* compute surface gradient and determinant */ float det = dot(sd->dP.dx, Rx); float3 surfgrad = (h_x - h_c)*Rx + (h_y - h_c)*Ry; - float intensity = stack_load_float(stack, intensity_offset); - surfgrad *= intensity; float absdet = fabsf(det); + float strength = stack_load_float(stack, strength_offset); + strength = clamp(strength, 0.0f, 1.0f); + /* compute and output perturbed normal */ - float3 outN = normalize(absdet*normal_in - signf(det)*surfgrad); - stack_store_float3(stack, node.w, outN); + float3 normal_out = normalize(absdet*normal_in - signf(det)*surfgrad); + normal_out = normalize(strength*normal_out + (1.0f - strength)*normal_in); + stack_store_float3(stack, node.w, normal_out); #endif } diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.c b/source/blender/nodes/shader/nodes/node_shader_bump.c index 63fd2137af1..b5b093ac7fa 100644 --- a/source/blender/nodes/shader/nodes/node_shader_bump.c +++ b/source/blender/nodes/shader/nodes/node_shader_bump.c @@ -36,7 +36,7 @@ /* **************** BUMP ******************** */ static bNodeSocketTemplate sh_node_bump_in[] = { - { SOCK_FLOAT, 1, N_("Strength"), 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 10.0f}, + { SOCK_FLOAT, 1, N_("Strength"), 0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, { SOCK_FLOAT, 1, N_("Height"), 1.0f, 1.0f, 1.0f, 1.0f, -1000.0f, 1000.0f, PROP_NONE, SOCK_HIDE_VALUE}, { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, { -1, 0, "" }