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-18 22:07:06 +0300
committerBrecht Van Lommel <brecht@blender.org>2022-08-09 19:42:01 +0300
commit79f1cc601cdbcf142e1bf4c1966f64dcf93b030f (patch)
treec52d15593d4417bc4f6cec958ed123fc4c9d449b /intern/cycles/kernel/bvh
parent230f9ade64844a50ea02461cfa005f364de09aa9 (diff)
Cycles: improve ray tracing precision near triangle edges
Detect cases where a ray-intersection would miss the current triangle, which if the intersection is strictly watertight, implies that a neighboring triangle would incorrectly be hit instead. When that is detected, apply a ray-offset. The idea being that we only want to introduce potential error from ray offsets if we really need to. This work for BVH2 and Embree, as we are able to match the ray-interesction bit-for-bit, though doing so for Embree requires ugly hacks. Tiny differences like fused-multiply-add or dot product intrinstics in matrix inversion and ray intersection needed to be matched exactly, so this is fragile. Unfortunately we're not able to do the same for OptiX or MetalRT, since those implementations are unknown (and possibly impossible to match as hardware instructions). Still artifacts are much reduced, though not eliminated. Ref T97259 Differential Revision: https://developer.blender.org/D15559
Diffstat (limited to 'intern/cycles/kernel/bvh')
-rw-r--r--intern/cycles/kernel/bvh/util.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/intern/cycles/kernel/bvh/util.h b/intern/cycles/kernel/bvh/util.h
index b67c9394bea..a57703a8b8c 100644
--- a/intern/cycles/kernel/bvh/util.h
+++ b/intern/cycles/kernel/bvh/util.h
@@ -33,6 +33,30 @@ ccl_device_forceinline float intersection_t_offset(const float t)
return __uint_as_float(bits);
}
+/* Ray offset to avoid self intersection.
+ *
+ * This function can be used to compute a modified ray start position for rays
+ * leaving from a surface. This is from:
+ * "A Fast and Robust Method for Avoiding Self-Intersection"
+ * Ray Tracing Gems, chapter 6.
+ */
+ccl_device_inline float3 ray_offset(const float3 P, const float3 Ng)
+{
+ const float int_scale = 256.0f;
+ const int3 of_i = make_int3(
+ (int)(int_scale * Ng.x), (int)(int_scale * Ng.y), (int)(int_scale * Ng.z));
+
+ const float3 p_i = make_float3(
+ __int_as_float(__float_as_int(P.x) + ((P.x < 0) ? -of_i.x : of_i.x)),
+ __int_as_float(__float_as_int(P.y) + ((P.y < 0) ? -of_i.y : of_i.y)),
+ __int_as_float(__float_as_int(P.z) + ((P.z < 0) ? -of_i.z : of_i.z)));
+ const float origin = 1.0f / 32.0f;
+ const float float_scale = 1.0f / 65536.0f;
+ return make_float3(fabsf(P.x) < origin ? P.x + float_scale * Ng.x : p_i.x,
+ fabsf(P.y) < origin ? P.y + float_scale * Ng.y : p_i.y,
+ fabsf(P.z) < origin ? P.z + float_scale * Ng.z : p_i.z);
+}
+
#ifndef __KERNEL_GPU__
ccl_device int intersections_compare(const void *a, const void *b)
{