// // Leave a Comment

Depth Map Bias and Self-Shadowing Artifacts, Transparency Support, Raytraced Shadows, and How Raytraced Shadows Work?

In this post it contains a very quick reference of the book Digital Lighting & Rendering and Author Jeremy Birn shares about Depth Map Bias and Self-Shadowing Artifacts, Transparency Support, Raytraced Shadows, and How Raytraced Shadows Work? from his new book Digital Lighting & Rendering, Third Edition on creating more convincing lighting and rendering.
To help you make better 3D renderings, here are some tips for creating more engaging and believable lighting. Some of these steps are frequently forgotten or skipped by beginners, but all of them are necessary and useful techniques in crafting professionally lit scenes.

Depth Map Bias and Self-Shadowing Artifacts

Artifacts like bands or grid patterns (as shown in Figure 3.14), are often caused by having a parameter called depth map bias set too low. For scenes built on a very large scale, you may need to raise the bias of some shadows to eliminate such artifacts.

Figure 3.14 A depth map bias that's too low causes artifacts that appear to be stripes, grids, or moiré patterns, shown at a bias of 0.005 (left), 0.02 (middle), and 0.25 (right).

Bias is a number that gets added to each distance measurement in the shadow map, pushing the shadow-start-distance further out from the light. Increasing the bias slides the shadowing effect out a little further away from the surface casting the shadow, so that it doesn't accidentally start too soon and cause artifacts. Artifacts such as banding or grid patterns appear because points on the surface essentially begin shadowing themselves, in areas where the limited number of depth samples have under-estimated the actual distance from the light to the surface.

The bias is set in the distance units of your software, so a scene built on a larger scale might need a higher bias, or a scene built on a very small scale might need a lower bias.

Fixing Light Leaks

Too high a bias can cause visible gaps between the object casting a shadow and the point where the shadow itself starts. A high bias can even let light "leak" through walls and corners that should be blocking the light, as shown in Figure 3.15.

Figure 3.15 A depth map bias that's too high, combined with thinly built geometry, can cause light leaks (left). Lowering the bias (right) is one way to fix this problem.

If you have light leaking through corners, there are some things you should do to isolate and fix the problem:

Hide all the other lights in your scene, so that you are test-rendering only one light.
If you are using a spotlight, make sure the cone is as narrow as possible to aim it just where it needs to shine.
Reduce the depth map bias.
Reduce the filtering or softness applied to the shadow, which extends light into shadow areas in much the same way as an increased bias.
A light leak is not always the fault of the lighting; often, it is a problem with your modeling. Here are some tips to fix your models to avoid light leaks:

Build thicker geometry in your architecture, instead of using infinitely thin surfaces. Walls of real houses have a thickness, and yours should too.
Add a polygon outside a building to block light where it is not needed.
Make sure that all corners are properly beveled, not perfect 90-degree angles.
If a part of your geometry isn't casting shadows, try adding another surface, such as a primitive shape, inside the part.
For some beginners, raising the shadow map resolution seems to be their first response to any shadow problem, even though this takes more memory and rendering time. If a problem with your shadows can be fixed by adjusting the bias, which does not add to your rendering time, then get the bias right first. If your shadows are not working well with a particular model, sometimes you need to fix the model.

Transparency Support

You expect a transparent object to cast a lighter shadow, and an opaque object to cast a darker shadow. However, conventional depth map shadows do not respond correctly to transparency, and are not any lighter when blocked by a transparent object For example, in Figure 3.16, the shadow becomes as dark under a transparent material as it is under an opaque material. Remember that each point in the depth map stores only one distance at which the light will be cut off, so it either stops at the glass or it doesn't, with no shades possible in between.

Figure 3.16 A limitation of conventional depth map shadows is that different levels of transparency in objects do not cause lighter shadows.

You may be able to work around the lack of transparency support in scenes that have a small amount of glass by setting glass objects not to cast shadows, or by using light-linking to remove them from some of the shadow-casting lights. However, in scenes with a large amount of glass (in which you will probably be raytracing already to achieve refraction), you may want to bite the bullet and switch to raytraced shadows.

Raytraced Shadows

Raytraced shadows are shadows computed by tracing rays of light between light sources and illuminated objects. Raytraced shadows are computed one pixel at a time as you render rather than being pre-computed and stored in shadow maps. Raytraced shadows have a number of advantages over shadow maps:
  • Raytraced shadows become lighter when shining through transparent surfaces, and they can even pick up color from colored transparent surfaces, as shown in Figure 3.17.

Figure 3.17 Raytraced shadows can pick up different levels of color and opacity when shining through transparent surfaces.

  • With raytraced shadows, you don't run into many of the problems associated with shadow maps, such as needing to adjust bias to prevent artifacts or fix light leaks.
  • Raytraced shadows do not use a fixed-resolution map, so they can always be crisp and accurate in any resolution rendering.
  • Raytraced shadows support higher quality, more realistic soft shadows, when used with area lights as described below.
  • Raytraced shadows work equally well from most types of lights, with no efficiency advantage pushing you toward spotlights.

So, if raytraced shadows are so wonderful and easy to use, why didn't I write about them first? And why do most feature films still rely primarily on shadow maps? There are two simple answers:

Raytraced shadows generally take longer to render than shadow maps. For complex scenes, the difference can be huge.
Employing raytracing in your scene increases memory use, and effectively limits the complexity of the scenes you can render on your computer.
Thus, raytraced shadows may be the first choice of a beginner or someone working on simpler scenes, but currently they're less desirable for professionals working on larger, film-resolution projects or doing animation work on tight deadlines.

How Raytraced Shadows Work?

Conventional raytracing works backwards in the sense that each ray is computed starting at the camera, instead of starting at the light source as in real life. For each pixel in your image, a ray is traced out from the camera at the appropriate angle until it hits part of a surface that needs to be rendered, as shown by the white lines in Figure 3.18.

Figure 3.18 Raytracing starts with primary rays fired from the camera (white). But for ray-traced shadows, rays need to be fired from each rendered point towards the light, to see if the path is clear (yellow) or blocked and requiring a shadow (red).

For each point on a surface, the renderer needs to determine which lights will be illuminating that point. If a light uses raytraced shadows, then the renderer needs to trace a path from the surface point to the light. If any polygons are found to be blocking that path, then the light will be blocked from the points on the surface. The area where the light is blocked from points on the surface forms the raytraced shadow. The yellow rays in Figure 3.18 show rays followed to the light; red rays show rays that were blocked by geometry, indicating that the point being rendered is in shadow.

If there is more than one light casting raytraced shadows, then the process of checking through space to see whether there are any polygons blocking a ray needs to be repeated for each light with raytraced shadows. All of this needs to be repeated at least once for each pixel, and usually more than once per pixel when rendering with anti-aliasing (anti-aliasing techniques will be discussed in Chapter 9, "Shaders and Rendering Algorithms.")

The result is that raytraced shadows slow down even the fastest computers. Furthermore, the time required to raytrace the shadow is only a part of the performance hit taken by raytracing. All of the polygons in your scene that might be casting a shadow need to be stored in memory in a way that can be searched through. Instead of allowing the rendering software to focus on a small part of your scene at one time, the raytracing process requires continual access to large amounts of data, usually stored in memory in many sorted lists of polygons. The result is that raytracing a large, complex scene uses up far more memory than rendering without raytracing.