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.
This commit is contained in:
Brecht Van Lommel 2013-05-09 14:05:37 +00:00
parent d326d92b2f
commit d236b4d60f
3 changed files with 12 additions and 8 deletions

@ -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);
}

@ -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
}

@ -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, "" }