Multi-Res Performance Optimisation for Atmosphere + Clouds
Volumetric Raymarching can be Very Costly
Volumetric Raymarching can be very costly as many 100s of ray-marching operations are performed on the GPU each pixel for each frame. A standard HD screen of 1920x1080 contains over 2 million pixels. In the case of my atmosphere + cloud shader, this high fill-rate cost brings the game's frame-rate to its knees.
In order to play Pegwars with cool new clouds in smooth realtime and iterate on the shader, I had to shade the planet and everything within the planet's atmosphere to a half-width, half-height render target. This approach costs 1/4 of the fill-rate and renders around 4x faster, but the results as you can see are blocky and blurry. Especially the building edges and the horizon lines are badly aliased :
As the atmosphere / cloud shader is very much fill-rate limited, either optimise the number of shader instructions per-pixel, or reduce the number of pixels shaded. The goal for this technique is to reduce the number of pixels rendered while still rendering the effect at high resolution so as not to lose any visible detail.
There are large areas of the viewport where the final shaded result will not change dramatically and so these can be shaded at 1/4 size without it being particularly noticeable. On the other hand there are areas (object edges and terrain horizon especially) where it is essential to render the effect at full-resolution.
The basic heuristic follows:
Details of the Multi-Res Optimisation
Step 1 - Write the Atmosphere Mask
|Detecting object sillhouettes by using ddx/ddy from the normals map.|
Note the artifacts in the sun using this technique, the threshold is poorly chosen.
|Different Regions of the Edge Detection drawn in different colours.|
|A Surreal looking cityscape|
|Starting to look more like the final mask output|