Teaching new tricks to an old dog

Posted: 29 Nov 2012 22:21
Tags: atmosphere gallery shader

This post is a sort of follow-up to the previous one. Although "Production Volume Rendering" only deals with voxel buffers, its reading has been inspirational enough for me to improve on XRT volume rendering. For now, XRT capabilities are based on RenderMan 3.2 atmosphere shaders1.

How atmosphere shaders work

This part is lifted from Pixar Application Note #20 available here

Atmosphere shaders are bound to surfaces, just like surface or displacement shaders. So you must have an object in the background for the atmosphere shader to run. In other words, pixels with no geometry at all "behind" them will not run any atmosphere shaders.

The general idea behind the smoke effects is to ray march along the incident ray I, sampling illumination and accounting for atmospheric extinction. Typically, this is done with the following algorithm:

Choose an appropriate step size for marching along the ray.
    total_len = length(I)
    current_pos = P;
    while total_len > 0 do:
        sample the smoke density and light at current_pos
        adjust Ci/Oi to add new light and extinguish due to smoke opacity.
        current_pos += stepsize * normalize(-I);
        total_len -= stepsize;

Volume shaders of this type can be very expensive. The computational expense is proportional to the number of iterations of the while loop, which is determined by the step size and the length of I. Therefore, it is important to choose your stepsize carefully — too large a stepsize will result in banding and quantization artifacts, while too small a stepsize results in very long render times.

A smarter shader

Fog light
Image Unavailable

This example, borrowed from the Gelato example set, features spinning gears in fog lighted with a spot light. Because there are holes and dents in the gears, parts of the fog are either obscured or lighted. This is the famous "god rays" effect.

On this kind of scene, the smoke shader example that comes with the Application Note #20 performs badly. The scene is quite large and there are many small details that requires a small step size to be properly caught. However, you will get a huge speed boost if you realize that the space outside the spot shape is not lit and does not need to be raymarched. If the shader is passed information regarding the spot shape (a cone here) and orientation, it can compute much tighter bounds for the raymarching algorithm and avoid useless steps in the dark void. First, the volume ray origin and position are transformed into the spot canonical space, then the new volume ray is intersected against the canonical cone shape (a mere second degree equation to solve).

You will get a better grasp of the "god rays" effect in the following animation:

You will find also this example and the companion video in the Gelato gallery.

Rate this post:

rating: 0+x

Comments: 0