From 6f23e4484d03f75ba1618f76114b3f81d5db0ae7 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 29 Sep 2021 19:32:42 +0200 Subject: Fix non-finite curve normal causing Cycles to crash Similar to the previous change in the area: need to avoid ray point and direction becoming a non-finite value. Use the view direction when the geometrical normal can not be calculated. Collaboration and sanity inspiration with Brecht! Differential Revision: https://developer.blender.org/D12703 --- intern/cycles/kernel/geom/geom_curve_intersect.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'intern') diff --git a/intern/cycles/kernel/geom/geom_curve_intersect.h b/intern/cycles/kernel/geom/geom_curve_intersect.h index b2101034bb6..a068e93790a 100644 --- a/intern/cycles/kernel/geom/geom_curve_intersect.h +++ b/intern/cycles/kernel/geom/geom_curve_intersect.h @@ -764,8 +764,10 @@ ccl_device_inline void curve_shader_setup(const KernelGlobals *kg, /* Thick curves, compute normal using direction from inside the curve. * This could be optimized by recording the normal in the intersection, * however for Optix this would go beyond the size of the payload. */ + /* NOTE: It is possible that P will be the same as P_inside (precision issues, or very small + * radius). In this case use the view direction to approximate the normal. */ const float3 P_inside = float4_to_float3(catmull_rom_basis_eval(P_curve, sd->u)); - const float3 Ng = normalize(P - P_inside); + const float3 Ng = (!isequal_float3(P, P_inside)) ? normalize(P - P_inside) : -sd->I; sd->N = Ng; sd->Ng = Ng; -- cgit v1.2.3