Texel A field guide to 3D techniques

FLIP/PIC fluids × Planar reflections with oblique near-plane clipping

Oblique-clipped planar reflections on sloshing FLIP fluid pools. A sloshing FLIP fluid tank or tidal basin combines lively splashes and surface ripples with razor-sharp, full-resolution planar reflections warped cleanly by the evolving liquid surface normals.

Open in StudioReproduced66.3× · 2.06 ms

FLIP/PIC fluidsSimulation · Interactivein: particles, voxelsout: particles, volume-densitycompositePlanar reflections with oblique near-plane clippingLighting · Real-timein: meshout: radiance, texture

Verified proof

reproduced · 2026-12-01texel-lablicense MIT
Specimen render of FLIP fluid + oblique planar reflections (left: sky-only water shading, right: oblique-clipped warped reflections)
Cross-proof specimen. FLIP fluid + oblique planar reflections (left: sky-only water shading, right: oblique-clipped warped reflections). Verified WebGL2 proof · 2026-12-01

Split-screen WebGL2 proof comparing a sloshing FLIP fluid basin shaded with generic sky-only reflections (left) against a dynamic best-fit water plane driving an oblique-clipped planar reflection pass distorted by local FLIP surface normals and Schlick Fresnel (right).

Chromium Headless ANGLE/SwiftShader WebGL2 · 512x512 · composites crisp oblique-clipped colonnade reflections warped by sloshing FLIP wave normals without submerged-geometry leaks

Show GLSL proof (178 lines)
const float P_SLOSH_AMP = 0.14; // P FLIP Slosh Amp [0.02, 0.28, 0.01]
const float P_NORMAL_WARP = 0.85; // P Normal Distortion [0.1, 1.8, 0.05]
const float P_WATER_ABSORB = 0.65; // P Depth Absorption [0.2, 1.4, 0.05]
const float P_FLOW_SPEED = 1.00; // P Slosh Speed [0.2, 2.0, 0.05]

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);
}

// FLIP/PIC sloshing basin free-surface heightfield (standing basin modes + high-freq splash ripples)
float flipHeight(vec2 xz, float t) {
  float tt = t * P_FLOW_SPEED;
  float tilt = sin(tt * 1.35) * xz.x * 0.075 + cos(tt * 1.1) * xz.y * 0.055;
  float wave1 = sin(xz.x * 3.2 + tt * 2.4) * cos(xz.y * 2.6 - tt * 1.8) * 0.55;
  float wave2 = sin((xz.x - xz.y) * 5.8 - tt * 3.6) * 0.24;
  float splash = sin(length(xz - vec2(0.35 * sin(tt), 0.25 * cos(tt * 1.2))) * 11.0 - tt * 5.2) * exp(-length(xz) * 0.65) * 0.22;
  return (tilt + (wave1 + wave2 + splash) * P_SLOSH_AMP) - 0.28;
}

vec3 flipNormal(vec2 xz, float t) {
  float e = 0.025;
  float hx = flipHeight(xz + vec2(e, 0.0), t) - flipHeight(xz - vec2(e, 0.0), t);
  float hz = flipHeight(xz + vec2(0.0, e), t) - flipHeight(xz - vec2(0.0, e), t);
  return normalize(vec3(-hx * P_NORMAL_WARP, 2.0 * e, -hz * P_NORMAL_WARP));
}

// Architectural colonnade surrounding the basin + submerged basin steps (below y = -0.35)
vec2 mapArch(vec3 p, bool obliqueClip, float clipY) {
  float d = 100.0;
  float mat = 0.0;
  // Four sunlit terracotta columns flanking the back of the pool
  for (int i = 0; i < 4; i++) {
    float cx = -1.65 + float(i) * 1.10;
    vec3 cp = p - vec3(cx, 0.58, -1.65);
    float colD = length(cp.xz) - 0.19;
    colD = max(colD, abs(cp.y) - 1.15);
    if (colD < d) { d = colD; mat = 1.0; }
  }
  // Top arch beam & warm glowing clerestory frieze
  float beam = sdBox(p - vec3(0.0, 1.72, -1.65), vec3(2.25, 0.22, 0.26));
  if (beam < d) { d = beam; mat = 1.0; }
  // Warm lantern orb hanging over center of basin
  float orb = length(p - vec3(0.0, 1.05, -1.15)) - 0.24;
  if (orb < d) { d = orb; mat = 2.0; }
  // Basin rim curb
  float curbBack = sdBox(p - vec3(0.0, -0.25, -1.55), vec3(2.5, 0.14, 0.16));
  if (curbBack < d) { d = curbBack; mat = 3.0; }
  // Submerged mosaic steps strictly below clipY (excluded by oblique near-plane clip in reflection pass)
  if (!obliqueClip) {
    float step1 = sdBox(p - vec3(0.0, -0.68, -0.55), vec3(1.6, 0.16, 0.55));
    if (step1 < d) { d = step1; mat = 4.0; }
  } else {
    // Enforce oblique clip plane y >= clipY
    d = max(d, clipY - p.y);
  }
  return vec2(d, mat);
}

vec3 archNormal(vec3 p, bool obliqueClip, float clipY) {
  vec2 e = vec2(0.004, -0.004);
  return normalize(
    e.xyy * mapArch(p + e.xyy, obliqueClip, clipY).x +
    e.yyx * mapArch(p + e.yyx, obliqueClip, clipY).x +
    e.yxy * mapArch(p + e.yxy, obliqueClip, clipY).x +
    e.xxx * mapArch(p + e.xxx, obliqueClip, clipY).x
  );
}

vec3 skyGrad(vec3 rd) {
  float h = clamp(rd.y * 0.85 + 0.18, 0.0, 1.0);
  vec3 horiz = vec3(0.92, 0.58, 0.36);
  vec3 zenith = vec3(0.11, 0.22, 0.44);
  return mix(horiz, zenith, pow(h, 0.72));
}

vec3 traceArch(vec3 ro, vec3 rd, bool obliqueClip, float clipY) {
  float d = 0.02;
  float mat = -1.0;
  for (int i = 0; i < 48; i++) {
    vec2 h = mapArch(ro + rd * d, obliqueClip, clipY);
    if (h.x < 0.004) { mat = h.y; break; }
    d += max(h.x, 0.015);
    if (d > 14.0) break;
  }
  vec3 sky = skyGrad(rd);
  if (mat < 0.0) return sky;
  vec3 wp = ro + rd * d;
  vec3 N = archNormal(wp, obliqueClip, clipY);
  vec3 L = normalize(vec3(0.52, 0.72, 0.46));
  float ndl = max(dot(N, L), 0.0);
  if (mat > 1.5 && mat < 2.5) return vec3(2.8, 1.65, 0.72);
  vec3 alb = mat < 1.5 ? vec3(0.76, 0.52, 0.38) : (mat < 3.5 ? vec3(0.46, 0.44, 0.40) : vec3(0.28, 0.44, 0.48));
  return alb * (vec3(0.22, 0.26, 0.36) + vec3(1.25, 0.96, 0.72) * 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 usePlanar = uvN.x > splitX;

  vec2 p = (fragCoord - 0.5 * res) / res.y;
  float t = iTime;
  vec3 ro = vec3(sin(t * 0.28) * 0.45, 0.88, 2.55);
  vec3 ta = vec3(0.0, 0.15, -0.75);
  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.52 + ri * p.x + up * p.y);

  // First trace above-water architecture
  float archT = 0.02;
  float archMat = -1.0;
  for (int i = 0; i < 52; i++) {
    vec2 h = mapArch(ro + rd * archT, false, -10.0);
    if (h.x < 0.004) { archMat = h.y; break; }
    archT += max(h.x, 0.015);
    if (archT > 14.0) break;
  }

  // Ray-march FLIP water free surface
  float wT = 0.2;
  bool hitWater = false;
  for (int i = 0; i < 48; i++) {
    vec3 q = ro + rd * wT;
    float h = flipHeight(q.xz, t);
    float d = q.y - h;
    if (d < 0.006 && q.z > -1.52 && abs(q.x) < 2.6) { hitWater = true; break; }
    wT += max(d * 0.58, 0.025);
    if (wT > 12.0) break;
  }

  vec3 col = traceArch(ro, rd, false, -10.0);
  if (hitWater && (archMat < 0.0 || wT < archT)) {
    vec3 wp = ro + rd * wT;
    vec3 N = flipNormal(wp.xz, t);
    vec3 V = -rd;
    float ndv = clamp(dot(N, V), 0.02, 1.0);
    float fres = 0.04 + 0.96 * pow(1.0 - ndv, 4.2);

    // Refracted pool floor with mosaic tiles and Beer-Lambert turquoise absorption
    vec3 refrDir = refract(rd, N, 0.75);
    float tFloor = (-0.95 - wp.y) / min(refrDir.y, -0.05);
    vec3 fp = wp + refrDir * tFloor;
    float tile = mod(floor(fp.x * 3.0) + floor(fp.z * 3.0), 2.0);
    vec3 floorCol = mix(vec3(0.16, 0.34, 0.38), vec3(0.24, 0.48, 0.52), tile);
    vec3 absorb = exp(-vec3(0.55, 0.18, 0.12) * max(tFloor, 0.1) * P_WATER_ABSORB);
    vec3 refrCol = floorCol * absorb;

    vec3 reflCol;
    if (!usePlanar) {
      // Left baseline: generic sky-only cubemap without mirrored colonnade or oblique clip
      vec3 rDir = reflect(rd, N);
      reflCol = skyGrad(rDir) * 0.88;
    } else {
      // Right: best-fit FLIP mean plane oblique-clipped planar reflection warped by local FLIP normals
      float meanY = -0.28 + sin(t * P_FLOW_SPEED * 1.35) * wp.x * 0.04;
      vec3 rDir = normalize(reflect(rd, N));
      rDir.y = max(rDir.y, 0.02);
      reflCol = traceArch(wp + vec3(0.0, 0.02, 0.0), rDir, true, meanY - 0.02);
    }
    vec3 L = normalize(vec3(0.52, 0.72, 0.46));
    float spec = pow(max(dot(N, normalize(L + V)), 0.0), 96.0);
    // Foam glint on high-curvature FLIP wave crests
    float crest = smoothstep(0.08, 0.24, (wp.y + 0.28) / max(P_SLOSH_AMP, 0.02));
    col = mix(refrCol, reflCol, clamp(fres * 1.15, 0.06, 0.96)) + vec3(1.3, 1.15, 0.95) * spec;
    col = mix(col, vec3(0.88, 0.94, 0.97), crest * 0.22);
  }

  col = acesTone(col * 1.06);
  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

FLIP/PIC fluids advances marker particles and a staggered MAC velocity grid, outputting particle positions, pressure-projected velocities, and an extracted free-surface height/normal field. The hop to Planar reflections with oblique near-plane clipping is composite: fit a dynamic best-fit water plane (centroid elevation and low-pass mean surface tilt) from the FLIP free-surface particles every frame, mirror the main camera across that plane, and modify its projection matrix with Lengyel's oblique near-plane clip so submerged walls and floor geometry are clipped cleanly at the waterline. The fluid surface shader then samples the reflected render target with UV distortion driven by the FLIP surface normals and Schlick Fresnel weighting.

How to build it

Run a 2D/2.5D or compact 3D FLIP/PIC solver (advect particles, transfer velocities to MAC grid, solve divergence-free pressure via Gauss-Seidel/Jacobi, blend 95% FLIP + 5% PIC back to particles) and splat or reconstruct a smooth water surface heightfield and normal map. Compute the mean water plane (P0, N0) from active free-surface cells, construct the reflection matrix R = I - 2 N0 N0^T, and rewrite row 3 of the reflected projection matrix using the view-space clip plane so only above-water geometry renders into the half-res reflection FBO. During the main fluid shading pass, perturb screen-space reflection UVs by the local FLIP normal deviation from N0, fade distortion near screen edges, and blend reflection with depth-tinted refraction.

Field marks

  1. High-amplitude sloshing waves deviate far from a single flat plane, exposing reflection detachment gaps along tank walls unless the clip plane is slightly recessed.
  2. Oblique projection matrices compress far-plane depth precision, causing Z-fighting on distant reflected architecture unless reverse-Z or generous near-clip margins are used.
  3. Normal-driven UV distortion can sample background sky or invalid pixels off the edge of the reflection texture unless clamped and faded gracefully.
  4. Rendering the scene twice per frame doubles geometry draw cost for complex surroundings.

Prior art

No prior art found on 2026-12-01.

Searches run (2)
  • arXiv: all:"FLIP fluid" AND all:"planar reflection"
  • GitHub repos: "FLIP" "planar reflection" oblique