Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brecht@blender.org>2022-07-26 17:07:50 +0300
committerBrecht Van Lommel <brecht@blender.org>2022-07-27 22:03:33 +0300
commit38af5b0501005d8ee84a59f027417bf6a31fcc5e (patch)
tree0856dd31787e59abe9300a8d4b3c6b37be3cfbc8 /intern/cycles/util/math_intersect.h
parent69f2732a1391680d252c86365b2df62b084ceeb8 (diff)
Cycles: switch Cycles triangle barycentric convention to match Embree/OptiX
Simplifies intersection code a little and slightly improves precision regarding self intersection. The parametric texture coordinate in shader nodes is still the same as before for compatibility.
Diffstat (limited to 'intern/cycles/util/math_intersect.h')
-rw-r--r--intern/cycles/util/math_intersect.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/intern/cycles/util/math_intersect.h b/intern/cycles/util/math_intersect.h
index 3e5891b2507..37bdc5f1ccf 100644
--- a/intern/cycles/util/math_intersect.h
+++ b/intern/cycles/util/math_intersect.h
@@ -120,9 +120,9 @@ ccl_device_forceinline bool ray_triangle_intersect(const float3 ray_P,
* in Embree. */
/* Calculate vertices relative to ray origin. */
- const float3 v0 = tri_c - ray_P;
- const float3 v1 = tri_a - ray_P;
- const float3 v2 = tri_b - ray_P;
+ const float3 v0 = tri_a - ray_P;
+ const float3 v1 = tri_b - ray_P;
+ const float3 v2 = tri_c - ray_P;
/* Calculate triangle edges. */
const float3 e0 = v2 - v0;
@@ -130,11 +130,12 @@ ccl_device_forceinline bool ray_triangle_intersect(const float3 ray_P,
const float3 e2 = v1 - v2;
/* Perform edge tests. */
- const float U = dot(cross(v2 + v0, e0), ray_D);
- const float V = dot(cross(v0 + v1, e1), ray_D);
- const float W = dot(cross(v1 + v2, e2), ray_D);
+ const float U = dot(cross(e0, v2 + v0), ray_D);
+ const float V = dot(cross(e1, v0 + v1), ray_D);
+ const float W = dot(cross(e2, v1 + v2), ray_D);
- const float eps = FLT_EPSILON * fabsf(U + V + W);
+ const float UVW = U + V + W;
+ const float eps = FLT_EPSILON * fabsf(UVW);
const float minUVW = min(U, min(V, W));
const float maxUVW = max(U, max(V, W));
@@ -158,8 +159,9 @@ ccl_device_forceinline bool ray_triangle_intersect(const float3 ray_P,
return false;
}
- *isect_u = U / den;
- *isect_v = V / den;
+ const float rcp_UVW = (fabsf(UVW) < 1e-18f) ? 0.0f : 1.0f / UVW;
+ *isect_u = min(U * rcp_UVW, 1.0f);
+ *isect_v = min(V * rcp_UVW, 1.0f);
*isect_t = t;
return true;
}