Atmosphere Rendering, part 2

Still doing work on my Atmosphere Shader, however it's proven to be quite the resource hog!

The current implementation is a fairly typical screen-space shader.  It ray-traces the light from the sun through the atmosphere until it hits the current pixel fragment, calculating the sun transmittance along this ray.  Then it marches that ray towards the camera, blending it over the background performing in and out-scattering again until it reaches the final fragment colour.

Incorporating Mie and Rayleigh scattering in the ray-tracing gives the following results :

Adding the clouds into the mix (as a prototype) gives results with I think outstanding potential.  However the added number of calculations in the shader pretty much takes it to breaking point, so much that I can't even prototype what it will finally look like, because I have to reduce the number of ray-marching steps in the shader.   Put simply, the shader is brute-force ray-tracing with no real optimisations and has reached its limit.

So my next step will be to split apart the atmposphere rendering into two steps.  Firstly, I plan to precompute a 3D Volume Texture containing the results of the light transmittance from the sun to each visible point.   This 3D Volume Texture only needs to cover the sunward-facing side of the planet, and I plan to parameterise the volume as a set of concentric hemispherical shells.

Once the precomputed volume texture is available, the screen-space atmosphere shader only has to do the ray-trace from the fragment surface to the eye, and for each point along this ray, it can simply look up the sun-fragment transmittance, rather than calculate it on the fly.

This will vastly speed up the shader by removing its costly inner-loop.  And in doing so, it will vastly increase the quality of results, because I will now be able to step at a higher frequency, and incorporate better algorithms for the scattering phase functions.

I'm still planning more optimisations, and think that a 3D Air Density volume texture can be precomputed also.  This will aid both calculating the sunlight transmittance volume, and the realtime raymarching algorithm.

I can't wait to see what the atmospheres look like after the optimisations :)   It's worth mentioning that this method of shading the atmosphere allows for fully dynamic clouds, which I intend to run as either a particle system, or cellular automata on the GPU, or a combination of both.  With fully dynamic lighting and seamless volume rendering, it's going to be a real asset to the game.


  1. Cant't say, that i see a lot of difference from previous screenshots. But under the hood changes are important thing. Thanks for an update.


Post a Comment

Popular posts from this blog

2022 Screenshot Update

Screenshot Progress Update!

Rendering Nebulae