Heuristic depth is a rough guess. For real results, make a depth map with an ML model (e.g. Depth Anything or MiDaS), white = near, and load it as the depth map.
Theory: Image → Heightfield
grid vertex (i,j) → u = i/(W-1), v = j/(H-1)
P = ( 2(u-0.5), 2(0.5-v)·H/W, depth(u,v)·scale )
The photo is the texture; depth only moves vertices in z.
Theory: Heuristic Depth
lum = 0.299R + 0.587G + 0.114B
sat = (max - min) / max
d = mix(lum, sat, w) (bright/colorful = near)
d = blur(d), normalize to 0..1, then d^gamma
Theory: Tearing
drop triangle if max(d) - min(d) > threshold
A big depth jump is an object edge. Stretching a
triangle across it smears the subject into the background,
so tearing cuts it into separate layers.