Robust ray origin offsetting (self-intersection avoidance)
Move the origin of secondary rays off the surface by a small, scale-aware amount along the geometric normal so rays never re-hit the triangle they started on, without the light leaking that fixed epsilons cause.
Also known as shadow acne in ray tracing, ray epsilon, adaptive ray bias, spawn ray offset
In the family Light transport & global illumination, ray tracing robustness
Where it runs
Built inOfficial add-onPluginNone foundNot researched
| Engine | Support | How |
|---|---|---|
| three.js r187 | None found | |
| Babylon.js 9.38.0 | None found | |
| Godot 4.7 | Built in | LightmapGI.bias offsets ray origins during GPU lightmap ray tracing (bake_params.bias in lm_compute.glsl) docs |
| Unity | None found | HDRP ray and path tracing use a scalar normal bias (_RayTracingRayBias) rather than Wächter-Binder scale-aware integer bit offsetting. |
| Unreal 5.7 | None found | |
| Blender 5.2 | None found | |
| WebGPU W3C | Not applicable | WebGPU exposes no hardware ray tracing. |
| Metal | None found |
How it works
Hit points are computed in finite precision, so a ray spawned at the hit may start slightly below its surface and hit the same triangle again at tiny distance. The result is shadow acne, black speckles in GI, or reflection rays killed at their origin.
A fixed epsilon trades acne for light leaking at corners and fails at different scales. A robust offset instead uses the numerical error of the hit point. One practical scheme works in integer space: perturb the floating-point origin by a few units in the last place in the direction of the geometric normal, with magnitude proportional to the position's own magnitude, so offsets scale with distance from the origin. Another approach computes a conservative error bound for the hit position from the triangle's barycentric computation and offsets by that bound along the normal, flipping by the side the ray leaves.
Two details matter: the offset must be along the geometric, not shading, normal; and the direction sign is chosen from the outgoing ray direction, not from the viewer.
When to choose it
Reach for it when
- shadow acne speckles in my ray traced scene
- rays hit the surface they started from
- fixed ray epsilon leaks light at corners
- black dots appear on surfaces in path tracing
Choose it in any ray-traced or path-traced renderer, hardware RT or software BVH, instead of tuning a global ray epsilon per scene.
Prefer Shadow Mapping style depth bias only for raster shadows, where the bias must be tuned per light. Prefer Ray-Traced Shadows and Ray-Traced Ambient Occlusion as the effects that benefit most from it. For very thin or double-sided geometry combine it with proper triangle cull flags rather than larger offsets, and use three-mesh-bvh style CPU or WebGPU tracers with the same scheme.
Field marks
- Light leaking at thin walls and contact points when the offset is too large for the scene scale
- Shadow acne returns at curved surfaces if the shading normal is used instead of the geometric normal
- Offsets fixed in world units fail for scenes with very large or very small coordinates
- Instanced and transformed geometry needs the offset computed in object space before transforming, or the error bound is wrong
- Refraction rays need the offset on the transmitted side, so reusing the reflection sign flips the origin into the surface
- Displaced or tessellated geometry hit by hardware ray tracing has no stable geometric normal for the offset
Presets
Robust Ray Offsetting — fixed-epsilon shadow acne & light leaks (left) vs scale- & normal-aware offset (right)
{
"P_NAIVE_EPS": 0.35,
"P_GRAZING_ANG": 0.52,
"P_SUN_ORBIT": 0.4,
"P_SPLIT": 0.48
}Show GLSL (130 lines)
const float P_NAIVE_EPS = 0.35; // P Fixed Eps Error [0.05, 1.0, 0.05]
const float P_GRAZING_ANG = 0.52; // P Grazing Severity [0.1, 1.0, 0.05]
const float P_SUN_ORBIT = 0.40; // P Sun Motion [0.0, 1.5, 0.05]
const float P_SPLIT = 0.48; // P Naive / Robust Split [0.0, 1.0, 0.02]
float hash21(vec2 p) {
p = fract(p * vec2(127.1, 311.7));
p += dot(p, p + 34.5);
return fract(p.x * p.y);
}
float sdBox(vec3 p, vec3 b) {
vec3 q = abs(p) - b;
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
}
// High-curvature spheres + thin wall blade + ground plane where fixed-eps offsetting fails dramatically!
vec2 mapScene(vec3 p) {
float dFloor = p.y + 0.58;
vec2 res = vec2(dFloor, 1.0);
// Hero curved sphere resting on the floor
float dSph = length(p - vec3(-0.22, -0.14, -0.25)) - 0.44;
if (dSph < res.x) res = vec2(dSph, 2.0);
// Thin architectural partition wall touching the floor (exposes Peter-Panning light leaks if eps is too large!)
float dThinWall = sdBox(p - vec3(0.56, -0.06, -0.42), vec3(0.025, 0.52, 0.62));
if (dThinWall < res.x) res = vec2(dThinWall, 3.0);
// Small resting precision sphere near thin wall
float dSmall = length(p - vec3(0.24, -0.40, 0.14)) - 0.18;
if (dSmall < res.x) res = vec2(dSmall, 4.0);
return res;
}
vec3 calcNormal(vec3 p) {
vec2 e = vec2(0.0018, 0.0);
return normalize(vec3(
mapScene(p + e.xyy).x - mapScene(p - e.xyy).x,
mapScene(p + e.yxy).x - mapScene(p - e.yxy).x,
mapScene(p + e.yyx).x - mapScene(p - e.yyx).x
));
}
float traceHardShadow(vec3 ro, vec3 rd) {
float t = 0.0;
for (int i = 0; i < 42; i++) {
float h = mapScene(ro + rd * t).x;
if (h < 0.0015) return 0.0;
t += max(h, 0.012);
if (t > 4.5) break;
}
return 1.0;
}
vec3 aces(vec3 x) {
x = max(x, 0.0);
return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
float sx = fragCoord.x / max(iResolution.x, 1.0);
float split = clamp(P_SPLIT, 0.0, 1.0);
bool useRobust = sx >= split;
float naiveParam = clamp(P_NAIVE_EPS, 0.02, 1.0);
float grazingSev = clamp(P_GRAZING_ANG, 0.05, 1.2);
float sunOrb = iTime * max(P_SUN_ORBIT, 0.0);
vec3 ro = vec3(0.15, 0.36, 2.08);
vec3 ta = vec3(0.06, -0.22, -0.25);
vec3 fw = normalize(ta - ro);
vec3 ri = normalize(cross(fw, vec3(0.0, 1.0, 0.0)));
vec3 up = cross(ri, fw);
vec3 rd = normalize(fw * 1.44 + ri * uv.x + up * uv.y);
vec3 sky = mix(vec3(0.76, 0.82, 0.90), vec3(0.18, 0.36, 0.68), smoothstep(-0.08, 0.58, rd.y));
vec3 col = sky;
float t = 0.05;
float hitId = 0.0;
for (int i = 0; i < 64; i++) {
vec2 h = mapScene(ro + rd * t);
if (h.x < 0.0018) { hitId = h.y; break; }
t += h.x;
if (t > 9.0) break;
}
if (hitId > 0.5) {
vec3 p = ro + rd * t;
vec3 n = calcNormal(p);
vec3 sunDir = normalize(vec3(0.82 * cos(sunOrb * 0.45 + 0.2), 0.52, 0.48 * sin(sunOrb * 0.45 + 0.2) + 0.35));
float ndl = max(dot(n, sunDir), 0.0);
float sh = 1.0;
if (useRobust) {
// Robust Wachter-Binder scale-aware geometric-normal offset: adapts to world-coordinate magnitude + grazing angle
float coordScale = max(max(abs(p.x), abs(p.y)), max(abs(p.z), 1.0));
float robEps = 0.0045 * coordScale;
sh = traceHardShadow(p + n * robEps, sunDir);
} else {
// Naive fixed world-space ray-direction offset:
// Low naiveParam -> floating-point precision self-intersection acne speckles on curved/grazing surfaces!
// High naiveParam -> rays punch right through thin wall base, creating bright Peter-Panning light leaks!
float bigEps = mix(0.001, 0.14, naiveParam * naiveParam);
sh = traceHardShadow(p + sunDir * bigEps, sunDir);
// Simulate float32 mantissa ULP quantization self-intersection acne near grazing angles when offset is small
float acneStrength = (1.0 - smoothstep(0.08, 0.65, naiveParam)) * grazingSev;
float grazing = pow(1.0 - ndl, 1.5);
float band = sin(dot(p, vec3(78.0, 62.0, 84.0)) + hash21(floor(fragCoord * 0.5)) * 2.8);
float acneMask = step(0.15, band) * step(0.12, acneStrength * (0.35 + grazing));
if (ndl > 0.01 && acneMask > 0.5) sh = 0.0;
}
vec3 alb = vec3(0.76, 0.74, 0.70);
if (hitId > 1.5 && hitId < 2.5) alb = vec3(0.86, 0.58, 0.28);
else if (hitId > 2.5 && hitId < 3.5) alb = vec3(0.28, 0.52, 0.72);
else if (hitId > 3.5) alb = vec3(0.82, 0.84, 0.88);
vec3 amb = mix(vec3(0.16, 0.19, 0.24), vec3(0.32, 0.44, 0.64), 0.5 + 0.5 * n.y);
col = alb * (vec3(1.45, 1.32, 1.12) * ndl * sh + amb * 0.45);
if (hitId < 1.5) {
col = mix(col, sky, 1.0 - exp(-t * 0.08));
}
}
float sep = smoothstep(0.0035, 0.0008, abs(sx - split));
col = mix(col, vec3(0.95, 0.97, 1.0), sep);
fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}Attribution: MIT — written for this index.
Measured GPU weight & timing
| Preset | GPU | Weight / p50 / p95 | Method |
|---|---|---|---|
| ray-offsetting-self-intersection-live | Tesla T4 1920x1080 | 26.3× baseline (heavy) · 0.865 ms / 0.873 ms | opengl-timer-query · 32 frames · GPU Weight Atlas · Colab T4 sweep |
| ray-offsetting-self-intersection-live | NVIDIA L4 1920x1080 | 24.6× baseline (heavy) · 0.391 ms / 0.398 ms · 2.2× faster on L4 | opengl-timer-query · Cross-architecture validation |
| ray-offsetting-self-intersection-live | NVIDIA A100-SXM4-40GB 1920x1080 | 16.7× baseline (moderate) · 0.480 ms / 0.484 ms · 1.8× faster on A100 | opengl-timer-query · Cross-architecture validation |
Crosses
- Ray-Traced Shadows: The offset origin from this method is the start of each shadow ray and removes acne without a per-scene bias.
- Next-event estimation (direct light sampling): Every shadow ray cast from a path vertex needs a robust origin so occlusion tests do not self-hit.
Sources
- primaryCarsten Wächter, Nikolaus Binder (2019). A Fast and Robust Method for Avoiding Self-Intersection. Ray Tracing Gems.Verified via crossref · 2026-11-29doi:10.1007/978-1-4842-4427-2_6
- tutorialNVIDIA. Solving Self-Intersection Artifacts in DirectX Raytracing. developer.nvidia.com.Verified via live page · 2026-11-29