Texel A field guide to 3D techniques

Photon Mapping × Planar reflections with oblique near-plane clipping

Mirrored refractive caustics via photon mapping and oblique planar reflections. Combining a caustic photon map with an oblique-clipped planar mirror pass renders sharp, physically focused refractive caustics both on diffuse floors and cleanly reflected inside polished marble tables, mirrors, or still water basins.

Open in StudioReproduced39.1× · 1.21 ms

Photon MappingLighting · Offlinein: mesh, material-paramsout: radiancecompositePlanar reflections with oblique near-plane clippingLighting · Real-timein: meshout: radiance, texture

Verified proof

reproduced · 2026-12-01texel-lablicense MIT
Specimen render of Caustic photon map + oblique planar reflections (left: direct unclipped pass, right: photon caustics + oblique mirror)
Cross-proof specimen. Caustic photon map + oblique planar reflections (left: direct unclipped pass, right: photon caustics + oblique mirror). Verified WebGL2 proof · 2026-12-01

Split-screen WebGL2 proof comparing direct glass shading without caustic photons or oblique-clipped mirror reflections (left) against a converged dispersive caustic photon map sampled cleanly in both the primary camera pass and an oblique-clipped planar marble mirror pass (right).

Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · renders crisp dispersive SDS caustic ribbons both directly on diffuse receivers and accurately mirrored inside an oblique-clipped planar reflector

Show GLSL proof (211 lines)
const float P_CAUSTIC_GAIN = 1.45; // P Photon Caustic Gain [0.3, 2.5, 0.05]
const float P_IOR_DISP = 0.09; // P Spectral Dispersion [0.0, 0.22, 0.01]
const float P_MIRROR_FRES = 0.78; // P Mirror Reflectivity [0.2, 1.0, 0.05]
const float P_LIGHT_ORBIT = 0.65; // P Light Orbit Speed [0.0, 1.5, 0.05]

float sdTorus(vec3 p, vec2 t) {
  vec2 q = vec2(length(p.xz) - t.x, p.y);
  return length(q) - t.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);
}

// Fluted refractive crystal lens hovering over the stone receiver
float sdCrystal(vec3 p, float t) {
  float ang = t * 0.45;
  mat2 rot = mat2(cos(ang), -sin(ang), sin(ang), cos(ang));
  vec3 q = p - vec3(-0.35, 0.42 + 0.06 * sin(t * 1.1), -0.15);
  q.xz = rot * q.xz;
  float a = atan(q.z, q.x);
  float flute = 0.032 * sin(a * 8.0) * cos(q.y * 5.0);
  return sdTorus(q.xzy, vec2(0.46, 0.165)) + flute;
}

// Diffuse limestone plinth receiving focused caustics
float sdPlinth(vec3 p) {
  return sdBox(p - vec3(-0.35, -0.34, -0.15), vec3(0.88, 0.12, 0.88)) - 0.02;
}

// Submerged pillar below mirror plane y = -0.48 (must be clipped by oblique near plane)
float sdSubmerged(vec3 p) {
  return sdBox(p - vec3(0.45, -0.95, 0.05), vec3(0.26, 0.42, 0.26));
}

vec2 mapScene(vec3 p, float t, bool clipBelowMirror) {
  float dCrys = sdCrystal(p, t);
  float dPlinth = sdPlinth(p);
  vec2 res = vec2(dPlinth, 1.0);
  if (dCrys < res.x) res = vec2(dCrys, 2.0);
  if (!clipBelowMirror) {
    float dSub = sdSubmerged(p);
    if (dSub < res.x) res = vec2(dSub, 3.0);
  }
  return res;
}

vec3 calcNormal(vec3 p, float t, bool clipBelowMirror) {
  vec2 e = vec2(0.003, -0.003);
  return normalize(
    e.xyy * mapScene(p + e.xyy, t, clipBelowMirror).x +
    e.yyx * mapScene(p + e.yyx, t, clipBelowMirror).x +
    e.yxy * mapScene(p + e.yxy, t, clipBelowMirror).x +
    e.xxx * mapScene(p + e.xxx, t, clipBelowMirror).x
  );
}

// Converged caustic photon map kernel evaluated in world space on diffuse receivers
vec3 sampleCausticPhotonMap(vec3 wp, vec3 lightDir, float t) {
  // Project point back along light ray toward crystal center plane
  vec3 cCenter = vec3(-0.35, 0.42 + 0.06 * sin(t * 1.1), -0.15);
  float h = max(cCenter.y - wp.y, 0.05);
  vec2 hitXZ = wp.xz + lightDir.xz * (h / max(lightDir.y, 0.25)) - cCenter.xz;
  float r = length(hitXZ);
  float a = atan(hitXZ.y, hitXZ.x) - t * 0.45;
  float ripple = 0.06 * sin(a * 8.0) + 0.025 * cos(a * 16.0);

  // Chromatic focal caustic cusps for R, G, B photon wavelengths
  vec3 caust = vec3(0.0);
  for (int ch = 0; ch < 3; ch++) {
    float disp = (float(ch) - 1.0) * P_IOR_DISP;
    float fInner = 0.24 + disp * 0.45 + ripple * 0.6;
    float fOuter = 0.56 + disp * 0.85 - ripple;
    float cusp1 = exp(-pow((r - fInner) * 14.5, 2.0));
    float cusp2 = exp(-pow((r - fOuter) * 10.5, 2.0));
    float star = 0.55 + 0.45 * pow(max(0.0, cos(a * 4.0 + disp * 6.0)), 4.0);
    float focus = (cusp1 * 1.35 + cusp2 * 0.95 * star) * exp(-max(r - 0.85, 0.0) * 5.0);
    if (ch == 0) caust.r = focus;
    else if (ch == 1) caust.g = focus;
    else caust.b = focus;
  }
  // Concentric bright focal hotspot inside torus hole
  float core = exp(-r * r * 36.0) * 1.35;
  return (caust + vec3(1.0, 0.95, 0.88) * core) * P_CAUSTIC_GAIN;
}

vec3 shadeScene(vec3 ro, vec3 rd, float t, vec3 lightDir, bool usePhotonCaustics, bool clipBelowMirror) {
  vec3 bg = mix(vec3(0.05, 0.07, 0.11), vec3(0.14, 0.18, 0.26), clamp(rd.y * 0.9 + 0.45, 0.0, 1.0));
  float maxT = 16.0;
  float dHit = 0.0;
  float matId = -1.0;
  for (int i = 0; i < 64; i++) {
    vec3 q = ro + rd * dHit;
    vec2 h = mapScene(q, t, clipBelowMirror);
    if (h.x < 0.002) {
      matId = h.y;
      break;
    }
    dHit += h.x;
    if (dHit > maxT) break;
  }

  // Check far floor plane at y = -0.48
  float tFloor = (-0.48 - ro.y) / (abs(rd.y) < 1e-5 ? 1e-5 : rd.y);
  if (tFloor > 0.01 && (matId < 0.0 || tFloor < dHit) && (!clipBelowMirror || ro.y > -0.48)) {
    vec3 fp = ro + rd * tFloor;
    float tile = mod(floor(fp.x * 2.0) + floor(fp.z * 2.0), 2.0);
    vec3 stone = mix(vec3(0.16, 0.17, 0.19), vec3(0.23, 0.24, 0.27), tile);
    vec3 col = stone * (0.28 + 0.72 * max(lightDir.y, 0.0));
    if (usePhotonCaustics) col += sampleCausticPhotonMap(fp, lightDir, t) * vec3(0.95, 0.92, 0.85) * 0.75;
    return mix(col, bg, 1.0 - exp(-tFloor * 0.08));
  }

  if (matId < 0.0) return bg;
  vec3 wp = ro + rd * dHit;
  vec3 N = calcNormal(wp, t, clipBelowMirror);
  vec3 V = -rd;
  float ndl = max(dot(N, lightDir), 0.0);

  if (matId < 1.5) {
    // Diffuse limestone plinth
    float grain = 0.92 + 0.08 * sin(wp.x * 28.0) * cos(wp.z * 28.0);
    vec3 alb = vec3(0.62, 0.59, 0.54) * grain;
    // Shadow under crystal
    float shDist = length(wp.xz - vec2(-0.35, -0.15) + lightDir.xz * 0.35);
    float shadow = mix(0.35, 1.0, smoothstep(0.18, 0.65, shDist));
    vec3 col = alb * (0.22 + 0.95 * ndl * shadow);
    if (usePhotonCaustics) {
      col += sampleCausticPhotonMap(wp, lightDir, t) * alb * 1.65;
    }
    return col;
  } else if (matId < 2.5) {
    // Refractive crystal torus
    float fres = 0.06 + 0.94 * pow(1.0 - max(dot(N, V), 0.0), 4.0);
    vec3 refr = refract(rd, N, 0.67);
    vec3 refl = reflect(rd, N);
    vec3 envR = mix(vec3(0.12, 0.18, 0.28), vec3(0.85, 0.92, 1.0), clamp(refl.y * 0.8 + 0.4, 0.0, 1.0));
    vec3 inner = mix(vec3(0.10, 0.38, 0.48), vec3(0.55, 0.88, 0.98), clamp(abs(refr.y), 0.0, 1.0));
    float spec = pow(max(dot(N, normalize(lightDir + V)), 0.0), 96.0);
    return mix(inner, envR, fres) + vec3(1.4, 1.35, 1.25) * spec;
  } else {
    // Submerged red calibration block visible only when oblique clipping is missing
    return vec3(0.75, 0.18, 0.16) * (0.35 + 0.65 * ndl);
  }
}

vec3 acesTone(vec3 x) {
  return clamp((x * (2.51 * x + 0.03)) / (x * (2.43 * x + 0.59) + 0.14), 0.0, 1.0);
}

void mainImage(out vec4 fragColor, in vec2 fragCoord) {
  vec2 res = max(iResolution.xy, vec2(1.0));
  vec2 uvN = fragCoord / res;
  float splitX = iMouse.z > 0.0 ? clamp(iMouse.x / res.x, 0.05, 0.95) : 0.5;
  bool useCross = uvN.x > splitX;

  vec2 p = (fragCoord - 0.5 * res) / res.y;
  float t = iTime;
  float lAng = 0.45 + t * 0.42 * P_LIGHT_ORBIT;
  vec3 lightDir = normalize(vec3(cos(lAng) * 0.55, 0.88, sin(lAng) * 0.42));

  vec3 ro = vec3(1.55, 1.15, 2.55);
  vec3 ta = vec3(-0.08, -0.10, -0.05);
  vec3 fw = normalize(ta - ro);
  vec3 ri = normalize(cross(vec3(0.0, 1.0, 0.0), fw));
  vec3 up = cross(fw, ri);
  vec3 rd = normalize(fw * 1.65 + ri * p.x + up * p.y);

  // Primary scene pass (also check mirror plane y = -0.48 on right half of table x > 0.05)
  vec3 col = shadeScene(ro, rd, t, lightDir, useCross, true);

  // Polished planar mirror slab covering x in [-1.5, 2.2], z in [-1.5, 1.8] at y = -0.48 outside plinth
  float tMir = (-0.48 - ro.y) / (abs(rd.y) < 1e-5 ? 1e-5 : rd.y);
  if (tMir > 0.01 && rd.y < -0.005) {
    vec3 mp = ro + rd * tMir;
    // Check that primary ray did not hit plinth or crystal closer than mirror
    float dTest = 0.0;
    bool occluded = false;
    for (int i = 0; i < 40; i++) {
      float h = mapScene(ro + rd * dTest, t, true).x;
      if (h < 0.003) { occluded = true; break; }
      dTest += h;
      if (dTest >= tMir) break;
    }
    if (!occluded && abs(mp.x) < 2.2 && abs(mp.z) < 2.0) {
      float vein = smoothstep(0.3, 0.9, sin(mp.x * 5.0 + sin(mp.z * 3.5) * 1.6) * 0.5 + 0.5);
      vec3 marble = mix(vec3(0.04, 0.05, 0.07), vec3(0.13, 0.14, 0.17), vein);
      float fres = mix(0.15, P_MIRROR_FRES, pow(1.0 - max(-rd.y, 0.0), 3.0));
      vec3 baseFloor = marble * 0.7;
      if (useCross) {
        // Oblique-clipped planar reflection pass: reflect ray across y = -0.48 and clip y < -0.48
        vec3 rRo = vec3(mp.x, -0.48 + 0.004, mp.z);
        vec3 rRd = normalize(vec3(rd.x, -rd.y, rd.z));
        vec3 reflCol = shadeScene(rRo, rRd, t, lightDir, true, true);
        vec3 directCaust = sampleCausticPhotonMap(mp, lightDir, t) * 0.55;
        col = mix(baseFloor + directCaust, reflCol, fres);
      } else {
        // Left baseline: naive unclipped reflection leaks submerged pillar and has no photon caustics
        vec3 rRo = vec3(mp.x, -0.48 - 0.004, mp.z);
        vec3 rRd = normalize(vec3(rd.x, rd.y, rd.z));
        vec3 leak = shadeScene(rRo, rRd, t, lightDir, false, false);
        col = mix(baseFloor, leak * 0.55, fres * 0.65);
      }
    }
  }

  col = acesTone(col * 1.12);
  if (abs(fragCoord.x - splitX * res.x) < 1.0) col = vec3(0.95, 0.93, 0.89);
  fragColor = vec4(pow(clamp(col, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
}

Why they connect

Photon Mapping traces photon packets from lights through refractive glass or lenses and stores diffuse surface hits in a spatial photon map (or splatted world-space caustic irradiance texture), outputting focal caustic radiance. The hop to Planar reflections with oblique near-plane clipping is composite: bind the converged caustic photon irradiance map as an emissive lighting contribution during BOTH the main camera pass and the mirrored oblique-clipped reflection pass, ensuring that refractive SDS (specular-diffuse-specular) caustic reflections appear razor-sharp inside planar mirrors without noisy path-traced SDS variance.

How to build it

Emit 50k-200k caustic photons toward refractive glass meshes, refract via Snell's law with wavelength-jittered IOR for subtle dispersion, and splat diffuse hit energy with a narrow cone/Epanechnikov kernel into a receiver caustic texture or spatial hash grid. Next, reflect the active camera across the polished marble or water plane, apply Lengyel's oblique near-plane projection matrix so geometry below the mirror plane is clipped cleanly, and render the scene (sampling the pre-gathered caustic photon map on every diffuse receiver) into a reflection render target. In the main pass, composite the planar reflection weighted by Schlick Fresnel over the primary caustic-lit geometry.

Field marks

  1. Photon density estimation bias blurs crisp caustic cusps if the gathering radius is too wide, and the blur becomes doubly conspicuous in a sharp mirror reflection.
  2. Oblique near-plane clipping can truncate tall refractive glass objects sitting directly on the mirror plane unless the clip plane sits flush with the mirror surface.
  3. Secondary reflections between two facing planar mirrors require recursive reflection passes and rapidly multiply draw calls.
  4. Animated refractive objects require rebuilding or re-splatting the caustic photon map every frame, dominating frame time on WebGL2.

Prior art

No prior art found on 2026-12-01.

Searches run (2)
  • arXiv: all:"photon mapping" AND all:"planar reflection"
  • GitHub repos: "photon mapping" "planar reflection" caustic