---
id: "ray-offsetting-self-intersection"
title: "Robust ray origin offsetting (self-intersection avoidance)"
aliases: [shadow acne in ray tracing, ray epsilon, adaptive ray bias, spawn ray offset]
domain: "gi"
stage: "lighting"
realtime: "realtime"
platforms: [cuda, desktop-gpu, cpu, webgpu, blender, unreal]
year_introduced: 2019
inputs: [mesh]
outputs: [visibility-mask]
style: "photoreal"
dynamic: "both"
cost: "cheap"
authority: "Wächter & Binder, 2019"
url: "https://texelatlas.vercel.app/t/ray-offsetting-self-intersection/"
sources_verified_at: "2026-11-29"
---
# Robust ray origin offsetting (self-intersection avoidance) (Wächter & Binder, 2019)

> 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.

## 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

## 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 use it

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](shadow-mapping) style depth bias only for raster shadows, where the bias must be tuned per light. Prefer [ray-traced-shadows](ray-traced-shadows) and [ray-traced-ambient-occlusion](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](three-mesh-bvh) style CPU or WebGPU tracers with the same scheme.

## Cost

cheap — A few integer or float operations when spawning each ray; no extra memory or traversal.
Measured GPU Weight: 26.28× baseline (heavy) — 0.8645 ms median / 0.8729 ms p95 on Tesla T4/PCIe/SSE2 @ 1920x1080 (opengl-timer-query).
Ada L4 scaling: 24.59× baseline (heavy) — 0.391 ms median (2.21× faster on L4).
Ampere A100 scaling: 16.66× baseline (moderate) — 0.4797 ms median (1.8× faster on A100).

## Failure modes

- 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

## Engine support

- godot: builtin — `LightmapGI.bias offsets ray origins during GPU lightmap ray tracing (bake_params.bias in lm_compute.glsl)` (evidence: https://github.com/godotengine/godot/blob/4.7.2-stable/modules/lightmapper_rd/lm_compute.glsl, checked 2026-12-01)

## Dataflow

- Inputs: mesh
- Outputs: visibility-mask
- Platforms: cuda, desktop-gpu, cpu, webgpu, blender, unreal

## Presets

### Robust Ray Offsetting — fixed-epsilon shadow acne & light leaks (left) vs scale- & normal-aware offset (right) (glsl-fragment; rendered 2026-11-30)

```json
{
  "P_NAIVE_EPS": 0.35,
  "P_GRAZING_ANG": 0.52,
  "P_SUN_ORBIT": 0.4,
  "P_SPLIT": 0.48
}
```

```glsl
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.

## Combines with

- [Ray-Traced Shadows](https://texelatlas.vercel.app/t/ray-traced-shadows.md): 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)](https://texelatlas.vercel.app/t/next-event-estimation.md): Every shadow ray cast from a path vertex needs a robust origin so occlusion tests do not self-hit.

## Sources

1. [primary] Carsten Wächter, Nikolaus Binder (2019) A Fast and Robust Method for Avoiding Self-Intersection. Ray Tracing Gems. https://doi.org/10.1007/978-1-4842-4427-2_6 (verified via crossref on 2026-11-29)
2. [tutorial] NVIDIA Solving Self-Intersection Artifacts in DirectX Raytracing. developer.nvidia.com. https://developer.nvidia.com/blog/solving-self-intersection-artifacts-in-directx-raytracing (verified via http on 2026-11-29)

## Cite this entry

Texel. "Robust ray origin offsetting (self-intersection avoidance)." https://texelatlas.vercel.app/t/ray-offsetting-self-intersection/ (accessed 2026-12-01).
