Raymarched volumetric clouds


This project renders volumetric clouds inside a box volume, with a sun/moon using only ray marching.

The project is written in C and GLSL, using the Sokol libraries for graphics and windowing abstractions;

The project can be run as either a single application, or as a client/host model where the host dynamically loads the client, making iterating the shader much easier.

Thanks to Sokol GFX, the program can be built both for Windows and Wasm (potentially Linux and Mac too, but I don't have the means to test it). The background on this page is the shader running in real time.

The clouds density is obtained using fractal brownian motion on a noise texture. When calculating the fbm, the shader takes the distance from the camera in consideration, and avoids calculating the smaller details, which require a texture sample The raymarcher returns early if it finds that the density has already reached its maximum value.

The sunflare is created by sampling the noise texture using the angle between the pixel's coordinate and the sun screen position. The glare is also slightly offset using the time since the program start to give it an animated glowing effect.

The noise textures are uncompressed as noise compresses very badly, instead they are saved as .raw file which have 4 bytes headers (2 for width and 2 for height) then raw image data. This also means that there is no need for additional allocation after loading the file.

The whole program uses only a single allocation of 5MB at the beginning for image loading.