Lighting Tutorial

Z-buffered shadows quality

z-buffered shadows works by computing a depth buffer of all objects in the scene as viewed from the light source point of view. The name z-buffer comes from the fact that the distance from light source is computed along the light source local Z axis. In essence, the light source is processed like a camera during the shadow calculation step.

Then, at render time, the software can determine if a pixel is under shadow by comparing its the distance of the surface it is shading, to the light source from the depth data contained in the z-buffer. If the distance of the surface at the pixel position is further away from the light source than the distance in the z-buffer, then, obviously, there is an object occluding the light source and thus, the pixel is in shadow for that given light source.

Z-buffer shadows can be faster to compute because the depth calculation is done once for each light source at the begining of a render while for ray-traced shadows, the depth calculation is done at least once for each pixel and for each light source.

However, even though a z-buffer shadow map is computed only once, this calculation is done for each pixel in the z-buffer. So a 512x512 z-buffer will require 262 thousand depth calculation. And a 2kx2k z-buffer will require 4 million depth calculations. And this is computed for every lights in the scene. So there is a tradeof in speed.

With z-buffer shadows, the shadow quality is mainly determined by the z-buffer map size and by the light cone angle. Increasing the light cone angle almost certainly necessitates that the z-buffer map size be increased also.

Z-buffer shadows are not easy to use. They produce all kind of artifacts and the shadows produced don't take distance from shadow casting objects, to shadow receiving objects into account which makes it difficult to get really convincing soft shadows. Soft z-buffer shadows are produced by first computing the shadow map and then bluring the shadow buffer. This bluring is constant, no matter how far away is the shadow casting object.

See http://www.hash.com/htmlHelp/v11.1/GeneratedHtml/LightP.htm of the on-line technical Reference Manual for more detailed description of z-buffer shadows shortcomings and how to use them.

And here to the right, is an example of the same Thanksgiving scene rendered with z-buffer shadows. The klieg lights cones were reduced to as much as possible for the scene and the z-buffer map was 2k x 2k in size. Notice the missing shadows under the plates and the utensils even though all precautions were taken.

For those reasons I don't recommend their usage. They may look faster but for really nice results, large shadow maps are necessary and they take considerable time to render. In the end, it may take as long as soft ray-traced shadows with very large maps especially when multipass is used.

Also, my experience is that z-buffered shadows take considerably more time to adjust and get right unless one just always selects the highest map sizes. I'd rather have the computer render a scene even though it may take longer than havinh me sitting at a scene tweaking the parameters until they are right and optimal.

Here is a quick analysis of some of the z-buffer shadows artifacts:

In the top image, there are no shadows at all. Notice how the plates and the utensils seem to be part of the table. There is no shadows under them to provide a sense of volume and height.

In the center image, even though the shadow map was 2k x 2k and the light size was reduced to 5cm to get as sharp shadows as possible, it is still not possible to get nice shadows all around. We can distinguish some form of shadows under the plates (1) and under the glasses (2) but the shadows are so soft that they don't provide that feeling of depth. the plates still seem to be part of the table. Also, the utensils are so small compared to the shadow map pixel size that they don't even cast any shadows. Even the turkey dish, which actually cast shadow, seems to float above the table because the shadow is way too soft.

Compare that with the bottom image, where all the shadows provide the proper sense of height and depth.

Now we are ready to tweak the shadows in our scene.