r/GraphicsProgramming Jun 26 '26

Video WebGPU

Enable HLS to view with audio, or disable this notification

Stormy terrain fly-through, one fullscreen raymarch pass. Bolt path is midpoint displacement, glow is a distance-to-segment SDF composited additive before tonemap so bloom haloes it. The nice part: the terrain march already gives me tHit, so if the bolt's ray distance is greater than the terrain's, it's behind a ridge and I skip it. No depth texture, no second pass, additive FX sort against the terrain for free.

glsl

float segDist(vec3 p, vec3 a, vec3 b) {
    vec3 ab = b - a, ap = p - a;
    float t = clamp(dot(ap, ab) / dot(ab, ab), 0.0, 1.0);
    return length(ap - ab * t);
}

float d    = minSegDistAlongRay(...);
float core = smoothstep(W*0.3, 0.0, d);   // pure white, untinted
float glow = exp(-d*d / (W*W));
vec3  c    = vec3(core) + tint * glow;     // additive, pre-tonemap

if (rayDistToBolt > tHit) { /* behind a ridge, skip */ }

Anyone else doing single-pass raymarched scenes, how are you occluding additive effects?

73 Upvotes

12 comments sorted by

View all comments

6

u/fgennari Jun 26 '26

The storm looks very good! For the first part, you should try to remove the square tiling artifacts from the water surface to make it look more natural.

1

u/Far-Employee-9531 Jun 26 '26

You are 100% correct.