Cycles: Fixed zero sized normals when certain attributes were missing.

The Normal Map node was falling back to (0, 0, 0) when it was missing
the required attributes to calculate a new normal.
(0, 0, 0) is not a valid normal and can lead to NaNs when it is
normalized later in the shader. Instead, we now return sd->N,
the unperturbed surface normal.
This commit is contained in:
Stefan Werner
2020-11-19 23:15:09 +01:00
parent 72a199e148
commit fdd3032f8f

View File

@@ -268,7 +268,8 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st
if (space == NODE_NORMAL_MAP_TANGENT) {
/* tangent space */
if (sd->object == OBJECT_NONE) {
stack_store_float3(stack, normal_offset, make_float3(0.0f, 0.0f, 0.0f));
/* Fallback to unperturbed normal. */
stack_store_float3(stack, normal_offset, sd->N);
return;
}
@@ -279,7 +280,8 @@ ccl_device void svm_node_normal_map(KernelGlobals *kg, ShaderData *sd, float *st
if (attr.offset == ATTR_STD_NOT_FOUND || attr_sign.offset == ATTR_STD_NOT_FOUND ||
attr_normal.offset == ATTR_STD_NOT_FOUND) {
stack_store_float3(stack, normal_offset, make_float3(0.0f, 0.0f, 0.0f));
/* Fallback to unperturbed normal. */
stack_store_float3(stack, normal_offset, sd->N);
return;
}