{
 "id": "planar-reflections-oblique-clipping",
 "title": "Planar reflections with oblique near-plane clipping",
 "aliases": [
  "mirror reflection pass",
  "water plane reflection render",
  "oblique frustum clipping",
  "Lengyel oblique clipping"
 ],
 "domain": "gi",
 "subdomain": "specular reflections",
 "stage": "lighting",
 "realtime": "realtime",
 "platforms": [
  "webgl2",
  "webgpu",
  "desktop-gpu",
  "mobile-gpu",
  "unity",
  "unreal",
  "godot"
 ],
 "year_introduced": 2004,
 "inputs": [
  "mesh"
 ],
 "outputs": [
  "radiance",
  "texture"
 ],
 "style": "both",
 "dynamic": "dynamic",
 "summary": "Render the scene a second time from a camera mirrored across a plane, with the near clipping plane replaced by the mirror plane so nothing behind it is drawn. The texture then supplies exact reflections for a flat surface.",
 "how_it_works": "For a flat reflector, the reflection equals the scene seen from a virtual camera reflected through the plane. Build the reflected view matrix, render into a texture, and sample that texture on the mirror in screen space (optionally offset by a normal map for water ripples).\n\nTwo problems need care. Geometry between the reflected camera and the mirror, which lies behind the real mirror plane, must be clipped or it appears in the reflection. User clip planes are not always available and cost shader work, so the standard fix modifies the projection matrix: the near plane is replaced by the mirror plane, giving an oblique frustum. The projection is adjusted by Lengyel's method, which rewrites the third row of the matrix from the clip-space plane and scales it to keep the far plane in range.\n\nRender triangle winding flips with the mirrored transform, so culling must be reversed. Cost is a second scene pass, so use a lower resolution, fewer shadow casters and a layer mask.",
 "when_to_use": "Choose it for a single flat reflector with exact, dynamic reflections: mirrors, calm water, polished floors, TV screens.\n\nPrefer [screen-space-reflections](screen-space-reflections) when several surfaces need glossy reflections without extra passes and some missing off-screen content is acceptable. Prefer [reflection-probes-parallax-corrected-cubemaps](reflection-probes-parallax-corrected-cubemaps) for many rough or curved reflectors where one cubemap approximation is enough. Prefer [hybrid-ray-traced-reflections](hybrid-ray-traced-reflections) for arbitrary geometry on ray-tracing hardware. For rippling water combine with [gerstner-waves](gerstner-waves) or [flow-map-water](flow-map-water) normals.",
 "cost": {
  "class": "medium",
  "notes": "A full second geometry pass at reduced resolution; cost grows with scene complexity and shadow casters visible in the mirror."
 },
 "failure_modes": [
  "Objects below the water or behind the mirror leak into the reflection when the oblique clip is missing or wrong",
  "Depth precision collapses if the oblique near plane is steep, so distant reflected geometry z-fights",
  "Culling winding is not flipped, giving inside-out reflected meshes or missing faces",
  "Reflection texture is a frame late when the camera moves quickly, producing a visible lag at the mirror's edges",
  "Multiple mirrors need one pass each, and recursive mirror-in-mirror views blow up cost",
  "Roughness cannot be handled without blur; a single sharp texture makes frosted floors look like perfect mirrors"
 ],
 "sources": [
  {
   "role": "primary",
   "key": "url:http://www.terathon.com/lengyel/Lengyel-Oblique.pdf",
   "type": "web",
   "title": "Oblique View Frustum Depth Projection and Clipping",
   "authors": [
    "Eric Lengyel"
   ],
   "year": 2005,
   "venue": "Journal of Game Development, 2005",
   "url": "http://www.terathon.com/lengyel/Lengyel-Oblique.pdf",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261030074350/https://terathon.com/lengyel/Lengyel-Oblique.pdf",
     "timestamp": "20261030074350"
    },
    "page_title": null,
    "host": "terathon.com",
    "title_confirmed_by_page": false,
    "title_unconfirmed": false
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET http://www.terathon.com/lengyel/Lengyel-Oblique.pdf → 200",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "venue": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-30T17:59:51.239Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-30T17:59:51.239Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-30T17:59:51.239Z",
   "title_sim": null,
   "__bib": "lengyel2005oblique"
  },
  {
   "role": "implementation",
   "key": "url:https://github.com/mrdoob/three.js/blob/dev/examples/jsm/objects/Reflector.js",
   "type": "web",
   "title": "three.js Reflector, planar reflection with oblique near-plane clipping",
   "authors": [
    "three.js contributors"
   ],
   "year": null,
   "venue": "github.com",
   "url": "https://github.com/mrdoob/three.js/blob/dev/examples/jsm/objects/Reflector.js",
   "ids": {},
   "license": null,
   "extra": {
    "http_status": 200,
    "live": true,
    "archive": {
     "url": "http://web.archive.org/web/20261108021601/https://github.com/mrdoob/three.js/blob/dev/examples/jsm/objects/Reflector.js",
     "timestamp": "20261108021601"
    },
    "page_title": "three.js/examples/jsm/objects/Reflector.js at dev · mrdoob/three.js",
    "host": "github.com",
    "title_confirmed_by_page": false,
    "title_unconfirmed": true
   },
   "provenance": {
    "title": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "url": {
     "authority": "http",
     "endpoint": "GET https://github.com/mrdoob/three.js/blob/dev/examples/jsm/objects/Reflector.js → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "authors": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "venue": {
     "authority": "http",
     "endpoint": "GET https://github.com/mrdoob/three.js/blob/dev/examples/jsm/objects/Reflector.js → 200",
     "checked_at": "2026-11-29T15:51:27.588Z"
    },
    "year": {
     "authority": "research-draft",
     "endpoint": "title_hint/author_hint, checked against page title where available",
     "checked_at": "2026-11-29T15:51:27.588Z"
    }
   },
   "status": "verified",
   "checked_at": "2026-11-29T15:51:27.588Z",
   "title_sim": 0.35294117647058826,
   "__bib": "contributorsthree"
  }
 ],
 "presets": [
  {
   "id": "planar-reflections-oblique-clipping-live",
   "title": "Planar Reflections & Oblique Clipping — unclipped submerged leak (left) vs oblique-clipped mirror (right)",
   "runtime": "glsl-fragment",
   "params": {
    "P_RIPPLE_AMP": 0.35,
    "P_SUBMERGED_VIS": 1,
    "P_SUN_ANGLE": 0.65,
    "P_SPLIT": 0.48
   },
   "basis": "original",
   "license_note": "MIT — written for this index.",
   "code": "const float P_RIPPLE_AMP = 0.35; // P Water Ripple [0.0, 1.2, 0.03]\nconst float P_SUBMERGED_VIS = 1.0; // P Leak Contrast [0.2, 1.8, 0.05]\nconst float P_SUN_ANGLE = 0.65; // P Orbit Speed [0.0, 2.0, 0.05]\nconst float P_SPLIT = 0.48; // P Unclipped / Oblique [0.0, 1.0, 0.02]\n\nmat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }\n\nfloat sdTorus(vec3 p, vec2 t) {\n  vec2 q = vec2(length(p.xz) - t.x, p.y);\n  return length(q) - t.y;\n}\n\nfloat sdBox(vec3 p, vec3 b) {\n  vec3 q = abs(p) - b;\n  return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);\n}\n\n// Scene above reflection plane (y > 0) AND submerged red-orange obstacle below plane (y < 0)!\nvec2 mapWorld(vec3 p, float t, bool clipBelow) {\n  // Above-water rotating golden torus sculpture + glowing cyan ring + pillars\n  vec3 q = p - vec3(0.0, 0.56, -0.35);\n  q.xz = rot2(t * 0.75) * q.xz;\n  q.xy = rot2(0.55) * q.xy;\n  vec2 res = vec2(sdTorus(q, vec2(0.36, 0.11)), 2.0);\n\n  float dOrb = length(p - vec3(0.0, 0.56 + 0.08 * sin(t * 1.8), -0.35)) - 0.15;\n  if (dOrb < res.x) res = vec2(dOrb, 3.0);\n\n  float dPilL = sdBox(p - vec3(-0.92, 0.48, -0.85), vec3(0.14, 0.48, 0.14)) - 0.02;\n  if (dPilL < res.x) res = vec2(dPilL, 4.0);\n  float dPilR = sdBox(p - vec3(0.92, 0.48, -0.85), vec3(0.14, 0.48, 0.14)) - 0.02;\n  if (dPilR < res.x) res = vec2(dPilR, 4.0);\n\n  // Submerged bright crimson truss/box sitting BELOW y = 0 between mirrored camera and reflection plane!\n  // Without oblique near-plane clipping, the mirrored camera hits this submerged box and corrupts the reflection!\n  if (!clipBelow) {\n    float dSub = sdBox(p - vec3(0.0, -0.44, 0.45), vec3(0.58, 0.28, 0.22));\n    if (dSub < res.x) res = vec2(dSub, 5.0);\n  }\n  return res;\n}\n\nvec3 calcNormal(vec3 p, float t, bool clipBelow) {\n  vec2 e = vec2(0.0025, 0.0);\n  return normalize(vec3(\n    mapWorld(p + e.xyy, t, clipBelow).x - mapWorld(p - e.xyy, t, clipBelow).x,\n    mapWorld(p + e.yxy, t, clipBelow).x - mapWorld(p - e.yxy, t, clipBelow).x,\n    mapWorld(p + e.yyx, t, clipBelow).x - mapWorld(p - e.yyx, t, clipBelow).x\n  ));\n}\n\nvec3 shadeSky(vec3 rd) {\n  float h = clamp(rd.y * 0.5 + 0.5, 0.0, 1.0);\n  vec3 sky = mix(vec3(0.09, 0.14, 0.24), vec3(0.24, 0.42, 0.72), pow(h, 0.8));\n  vec3 sun = normalize(vec3(0.55, 0.42, -0.72));\n  sky += vec3(1.8, 1.25, 0.75) * pow(max(dot(rd, sun), 0.0), 28.0);\n  return sky;\n}\n\nvec3 traceScene(vec3 ro, vec3 rd, float t, bool clipBelow, float leakGain) {\n  float dSum = 0.0;\n  float matId = 0.0;\n  bool hit = false;\n  for (int i = 0; i < 56; i++) {\n    vec3 p = ro + rd * dSum;\n    vec2 h = mapWorld(p, t, clipBelow);\n    if (h.x < 0.0022) { hit = true; matId = h.y; break; }\n    dSum += h.x;\n    if (dSum > 8.5) break;\n  }\n  if (!hit) return shadeSky(rd);\n\n  vec3 p = ro + rd * dSum;\n  vec3 n = calcNormal(p, t, clipBelow);\n  vec3 lDir = normalize(vec3(0.55, 0.80, 0.35));\n  float diff = max(dot(n, lDir), 0.0);\n  float spec = pow(max(dot(n, normalize(lDir - rd)), 0.0), 48.0);\n\n  if (matId > 4.5) {\n    // Corrupted submerged geometry leaking into unclipped reflection\n    float stripe = smoothstep(0.45, 0.55, sin((p.x + p.y) * 32.0));\n    return mix(vec3(0.95, 0.16, 0.12), vec3(1.15, 0.55, 0.10), stripe) * (0.55 + 0.65 * diff) * leakGain;\n  }\n  if (matId > 2.5 && matId < 3.5) {\n    return vec3(0.22, 1.45, 1.85) * (0.65 + 0.5 * diff) + vec3(0.9) * spec;\n  }\n  vec3 alb = (matId < 2.5) ? vec3(0.92, 0.68, 0.24) : vec3(0.62, 0.68, 0.78);\n  return alb * (0.24 + 0.85 * diff) + vec3(1.0, 0.95, 0.85) * spec * 0.65;\n}\n\nvec3 aces(vec3 x) {\n  x = max(x, 0.0);\n  return (x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14);\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n  vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;\n  float screenX = fragCoord.x / max(iResolution.x, 1.0);\n  float split = clamp(P_SPLIT, 0.0, 1.0);\n  bool useObliqueClip = screenX >= split;\n  float ripple = clamp(P_RIPPLE_AMP, 0.0, 1.2);\n  float leakGain = clamp(P_SUBMERGED_VIS, 0.2, 2.0);\n  float t = iTime * max(P_SUN_ANGLE, 0.0);\n\n  vec3 ro = vec3(0.0, 0.68, 2.18);\n  vec3 rd = normalize(vec3(uv - vec2(0.0, 0.04), -1.48));\n\n  // First trace primary camera above plane y = 0\n  float tPlane = (rd.y < -0.001) ? ((0.0 - ro.y) / rd.y) : 1e5;\n  float dPrimary = 0.0;\n  float matId = 0.0;\n  bool hitAbove = false;\n  for (int i = 0; i < 56; i++) {\n    vec3 p = ro + rd * dPrimary;\n    if (dPrimary > tPlane) break;\n    vec2 h = mapWorld(p, t, true);\n    if (h.x < 0.0022) { hitAbove = true; matId = h.y; break; }\n    dPrimary += h.x;\n    if (dPrimary > 8.5) break;\n  }\n\n  vec3 col = vec3(0.0);\n  if (hitAbove) {\n    col = traceScene(ro, rd, t, true, leakGain);\n  } else if (tPlane < 12.0) {\n    // Hit glossy water/marble mirror plane y = 0\n    vec3 pFloor = ro + rd * tPlane;\n    vec2 wGrad = vec2(\n      cos(pFloor.x * 7.5 + t * 2.1) * sin(pFloor.z * 6.2 - t * 1.4),\n      sin(pFloor.x * 6.4 - t * 1.6) * cos(pFloor.z * 8.1 + t * 1.9)\n    ) * 0.045 * ripple;\n    vec3 nPlane = normalize(vec3(wGrad.x, 1.0, wGrad.y));\n\n    // Mirrored virtual camera across y = 0: ro_m = (ro.x, -ro.y, ro.z)\n    vec3 roMirror = vec3(ro.x, -ro.y, ro.z);\n    vec3 rdMirror = normalize(pFloor - roMirror + vec3(wGrad.x, 0.0, wGrad.y) * 0.8);\n\n    // Core technique:\n    // Left (no oblique clip): ray starts at mirrored camera BELOW y=0 and hits submerged box!\n    // Right (oblique near plane at y=0): ray starts clipped at pFloor on y=0, rejecting everything below!\n    vec3 reflCol = useObliqueClip\n      ? traceScene(pFloor + vec3(0.0, 0.004, 0.0), rdMirror, t, true, leakGain)\n      : traceScene(roMirror, rdMirror, t, false, leakGain);\n\n    float fresnel = 0.16 + 0.84 * pow(1.0 - max(dot(nPlane, -rd), 0.0), 4.0);\n    float tile = mod(floor(pFloor.x * 1.8) + floor(pFloor.z * 1.8), 2.0);\n    vec3 floorBase = mix(vec3(0.04, 0.07, 0.11), vec3(0.08, 0.12, 0.18), tile);\n    col = mix(floorBase, reflCol, clamp(fresnel * 0.92, 0.25, 0.96));\n  } else {\n    col = shadeSky(rd);\n  }\n\n  float sep = smoothstep(0.0035, 0.0008, abs(screenX - split));\n  col = mix(col, vec3(0.95, 0.97, 1.0), sep);\n\n  fragColor = vec4(pow(clamp(aces(col), 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}",
   "execution_fidelity": "reduced-sandbox",
   "proof": {
    "kind": "rendered",
    "label": "rendered 2026-11-30",
    "ok": true,
    "proof": {
     "ok": true,
     "technique": "planar-reflections-oblique-clipping",
     "runtime": "glsl-fragment",
     "checked_at": "2026-11-30T19:53:33.000Z",
     "renderer": "Headless EGL Tesla T4/PCIe/SSE2, OpenGL 3.30 Core, 512×512, iTime=1.5",
     "stats": {
      "mean": 0.6445,
      "std": 0.1015,
      "min": 0.3761,
      "max": 0.9288
     },
     "image": "/specimens/planar-reflections-oblique-clipping-live.webp",
     "reason": null
    }
   }
  }
 ],
 "related": [
  "screen-space-reflections",
  "reflection-probes-parallax-corrected-cubemaps",
  "hybrid-ray-traced-reflections",
  "gerstner-waves",
  "flow-map-water",
  "water-caustics-realtime"
 ],
 "extends": [],
 "supersedes": [],
 "combines_with": [
  {
   "id": "gerstner-waves",
   "why": "Wave normals distort the planar reflection lookup so the water surface looks rippled."
  },
  {
   "id": "flow-map-water",
   "why": "A flowing normal map perturbs the reflected texture coordinates for moving water."
  }
 ],
 "provenance": {
  "prose": "original text written for this index (research draft, editorially reviewed)",
  "sources_verified_at": "2026-11-29T15:51:27.588Z",
  "draft": "data/drafts/gi/planar-reflections-oblique-clipping.json"
 },
 "solves": [
  "need exact mirror or water reflections on a flat plane",
  "objects below the water show up in the reflection",
  "reflection render includes geometry behind the mirror",
  "want a cheap clean reflection for a polished floor"
 ],
 "authority": "Lengyel, 2005",
 "url": "https://texelatlas.vercel.app/t/planar-reflections-oblique-clipping/",
 "execution_fidelity": "reduced-sandbox",
 "fidelity_label": "Analytic Sandbox",
 "benchmark_eligible": true,
 "gpu_weight": {
  "weight_x": 19.67,
  "tier": "moderate",
  "p50_ms": 0.6098,
  "p95_ms": 0.6509,
  "baseline_p50_ms": 0.0329,
  "gpu": "Tesla T4/PCIe/SSE2",
  "resolution": "1920x1080",
  "method": "opengl-timer-query",
  "frames": 36,
  "preset_id": "planar-reflections-oblique-clipping-live",
  "execution_fidelity": "reduced-sandbox",
  "fidelity_label": "Analytic Sandbox",
  "benchmark_eligible": true,
  "generated_at": "2026-11-30T21:07:47Z",
  "l4": {
   "weight_x": 17.47,
   "tier": "moderate",
   "p50_ms": 0.2777,
   "p95_ms": 0.281,
   "speedup_x": 2.2,
   "gpu": "NVIDIA L4/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0159
  },
  "a100": {
   "weight_x": 12.83,
   "tier": "moderate",
   "p50_ms": 0.3695,
   "p95_ms": 0.3722,
   "speedup_x": 1.65,
   "gpu": "NVIDIA A100-SXM4-40GB/PCIe/SSE2",
   "resolution": "1920x1080",
   "baseline_p50_ms": 0.0288
  }
 }
}