Analytic Fog Rendering with Volumetric Primitives (2025)
77 points
1 day ago
| 4 comments
| matejlou.blog
| HN
Ono-Sendai
1 hour ago
[-]
Coincidentally I just posted a blog post on fog rendering, in particular with exponential height fog, yesterday: https://forwardscattering.org/post/72
reply
reactordev
3 hours ago
[-]
Yesssssss…

However, I’d push this a little further with light reflectance and scattering. Fog does some weird things to light when it’s dense. You mention this towards the end but even just a Rayleigh calc should be enough.

A goal of mine, maybe this year, is to get back into volumetric clouds and fog using SDF with wgpu but, the economy.

But something like…

    // Assume: 
    // vec3 fogColor;      // Base fog color
    // float density;      // Fog density at point
    // vec3 lightDir;      // Direction from point to light
    // vec3 viewDir;       // Direction from camera to point
    // vec3 sunColor;      // RGB color of light

    // Compute angle between light and view
    float cosTheta = dot(normalize(lightDir), normalize(viewDir));

    // Simple Rayleigh-ish phase function (forward/backward scattering)
    float phase = 0.75 * (1.0 + cosTheta * cosTheta);

    // Wavelength-dependent scattering (approx Rayleigh)
    vec3 sigma = vec3(0.5, 0.8, 1.0); // R,G,B scattering coeffs

    // Fog contribution
    vec3 fogContribution = density * phase * sigma * sunColor;

    // Blend with scene color (sceneColor comes from existing render)
    vec3 finalColor = mix(sceneColor, sceneColor + fogContribution, density);

Take that with a grain of salt but the idea is to blend the final color with a scattering coefficient for when light is trying to shine through.
reply
kqr
7 hours ago
[-]
If, by chance, there are any fans of Morrowind here, there are shaders for the OpenMW source port that add volumetric fog and the game becomes absolutely stunning with them. I'm sure that was what the original developers intended but couldn't achieve with the computers of the age.

Volumetric fog has a special place in my heart.

reply
maximus_prime
7 hours ago
[-]
Shout-out to his incredible mod adds volumetric fog to GTA 4: https://fusionfix.io/iv
reply
bee_rider
7 hours ago
[-]
This is pretty cool, and also seems pretty accessible for a “graphics thing.” Just a little calculus.

It would be kind of neat to have an example of a physical situation that produces each of the example functions (although I’m sure that isn’t always possible).

Can the effect of multiple fog emitters reasonably be modeled as the sum of their outputs? I guess for high densities, probably not (eventually the air will get saturated), but for low densities, probably yes…

reply
Ono-Sendai
57 minutes ago
[-]
For simple models (constant incoming radiance), you can indeed just add the optical depths from the different fog 'layers'. (90% sure but the maths is easy to check anyway, see https://forwardscattering.org/post/72)
reply