Cycles: avoid making NaNs in Vector Math node by normalizing zero vectors.
Since inputs are user controlled, the node can't assume they aren't zero.
This commit is contained in:
parent
c2a7317d1f
commit
a7f6f900f3
|
@ -32,21 +32,17 @@ ccl_device void svm_vector_math(float *Fac, float3 *Vector, NodeVectorMath type,
|
|||
*Fac = average_fac(*Vector);
|
||||
}
|
||||
else if(type == NODE_VECTOR_MATH_AVERAGE) {
|
||||
*Fac = len(Vector1 + Vector2);
|
||||
*Vector = normalize(Vector1 + Vector2);
|
||||
*Vector = safe_normalize_len(Vector1 + Vector2, Fac);
|
||||
}
|
||||
else if(type == NODE_VECTOR_MATH_DOT_PRODUCT) {
|
||||
*Fac = dot(Vector1, Vector2);
|
||||
*Vector = make_float3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
else if(type == NODE_VECTOR_MATH_CROSS_PRODUCT) {
|
||||
float3 c = cross(Vector1, Vector2);
|
||||
*Fac = len(c);
|
||||
*Vector = normalize(c);
|
||||
*Vector = safe_normalize_len(cross(Vector1, Vector2), Fac);
|
||||
}
|
||||
else if(type == NODE_VECTOR_MATH_NORMALIZE) {
|
||||
*Fac = len(Vector1);
|
||||
*Vector = normalize(Vector1);
|
||||
*Vector = safe_normalize_len(Vector1, Fac);
|
||||
}
|
||||
else {
|
||||
*Fac = 0.0f;
|
||||
|
|
|
@ -572,6 +572,12 @@ ccl_device_inline float3 safe_normalize(const float3 a)
|
|||
return (t != 0.0f)? a/t: a;
|
||||
}
|
||||
|
||||
ccl_device_inline float3 safe_normalize_len(const float3 a, float *t)
|
||||
{
|
||||
*t = len(a);
|
||||
return (*t != 0.0f)? a/(*t): a;
|
||||
}
|
||||
|
||||
#ifndef __KERNEL_OPENCL__
|
||||
|
||||
ccl_device_inline bool operator==(const float3 a, const float3 b)
|
||||
|
|
Loading…
Reference in New Issue