UDN
Search public documentation:

ModulatedShadows
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Lighting & Shadows > Modulated Shadows
UE3 Home > Lighting Artist > Modulated Shadows

Modulated Shadows


Document Changelog: Created by Daniel Wright.

Overview


Modulated shadows were introduced to solve some of the performance problems with normal shadows, and to give artists more control over shadow appearances. Throughout this doc, 'normal shadows' simply means non-modulated shadows, and does not imply anything about the filtering technique.

Note that modulated shadows work with both projected shadow buffers as well as shadow volumes.

Versions


ModShadowFadeoutTime functionality was introduced in QA_APPROVED_BUILD_JUNE_2007, but shadows didn't fade in as well until QA_APPROVED_BUILD_AUGUST_2007. The Modulate-Better shadow mode was added in QA_APPROVED_BUILD_JAN_2008.

Relevant Settings


ModShadowOptions.jpg

LightShadowMode

Controls the type of shadowing used for this light source.

  • LightShadow_Normal - the default behavior and requires a mesh to be dynamically lit by the shadow casting light in order to receive shadows from that light. This is a very important implication because it means lightmapped geometry cannot receive normal shadows if the lightmap contains the contribution from the shadow casting light. Normal shadows are very expensive on Xbox 360 as they require extra render target space which requires other render targets to be saved out and restored afterwards.
  • LightShadow_Modulate - enables modulated shadows from this light source, which cast on any opaque or masked object. This is the cheapest mode. Modulated shadows operate by multiplying scene color instead of masking out a certain light.

ModShadowColor

This controls the color of modulated shadows.

ShadowFalloffExponent

Rate at which the shadows falloff based on distance for spot lights and point lights. A higher value means that the falloff will occur more quickly. A value of 1.0 equals linear falloff.

ModShadowFadeoutExponent

This controls the fade-out and fade-in curves when ModShadowFadeoutTime is greater than zero.

ModShadowFadeoutTime

If this is greater than zero, then the modulated shadow will fadeout based on the time that the caster was last visible. It will also fade in based on the time that the caster first became visible. This can be used to fade out shadows on characters in other rooms, whose shadows would otherwise be seen through the wall. Make sure you have realtime update on in the editor or it will not work correctly. The fade is framerate dependent so hitches may cause undesired artifacts.

Why use modulated shadows


An object's dynamic shadows are drawn for each light that uses Normal Shadows. Shadows in this sense are the absence of light coming from the current light source. This is a more physically correct model, however it has some serious implications. A typical scene will have several lights in the same area, but only one of these lights casting dynamic shadows for performance reasons. In this case, shadow color is totally dependent on the lights affecting the shadowed surface. The shadow will be very dim because the shadow-casting light source only contributes a fraction of the total light on the surface, and the shadow is simply the absence of that light. It would be very difficult for an artist to tweak the shadow color and make it darker in this case, because that would require making the shadow-casting light brighter (or closer, less attenuation etc), which may ruin the lighting in the scene.

Normal shadows do not cast onto static geometry once its lightmap has been built. Modulated shadows cast on the entire scene and so solve this problem.

A scene with 3 lights affecting the character, only one of them casting normal shadows. Note that the shadow is very dim.
ThreeNormal.jpg

How modulated shadows work


This is where modulated shadows come into the picture. In short, modulated shadows allow the artist to have only one shadow per dynamic object and control that shadow color without changing the lighting properties of the shadow-casting light source.

Modulated shadows are much less physically correct than normal shadows, however in most cases this is offset by the performance and user control benefits. In each lighting pass the shadows have ModShadowColor applied, and then they are rendered to an attenuation buffer, instead of being used to mask out the current light. When all the lights have been rendered, the attenuation buffer is multiplied with the scene color. The result is that shadows will be darker no matter how many lights are affecting a surface, because shadows from one light source affect the light from all light sources, instead of just the shadow-casting light source.

The same scene with 3 lights affecting the character, only one of them casting modulated shadows. Note that the shadow is still strong.
ThreeMod.jpg

Modulated shadows for point lights have a radial attenuation based on the light's radius. This is also true for spot lights except that the falloff is also affected by the inner and outer cones. For directional lights there is no distance attenuation.

Limitations


Double shadowing

Since modulated shadows simply modulate against scene color, areas where shadows overlap will be double shadowed. The workaround for this is to shadow parent nearby primitives. For example, in Gears of War 1 all weapons are shadow parented to their pawns to avoid double shadowing there. See AttachingActors#b_ShadowParented for how to shadow parent in content. To shadow parent in code use the PrimitiveComponent's SetShadowParent method.

Emissive artifacts

Modulative shadows are multiplied against the scene color, including emissive light, which should not be shadowed. The workaround is to use the Modulate-Better shadow mode, which will prevent modulated shadows from affecting pixels whose emissive component is > 1 for any channel.

Casting through geometry

In the current implementation, mod shadows cast through geometry. The most obvious cases of this will have to be avoided through careful light placement. Avoiding these situations through manual light tweaking can be very difficult, but can be made significantly easier by using LightEnvironments. In some cases this can be alleviated through the use of ModShadowFadeoutTime. Shadows on backfaces can be avoided with the Modulate-Better shadow mode.

The only way to really avoid these projection artifacts is to use normal shadows. However, normal shadows are considerably more expensive than modulated shadows for the most part. There's one exception to this: DominantLights. Dominant lights allow you to have one light casting normal shadows for cheap.

Shadow buffer filtering

One implication of modulated shadows is that backface color from a certain light will no longer be the same as the shadow casted from that light source. This means that shadows must cover the backfaces accurately, or the difference will be obvious. This is a problem for some shadow buffer filtering techniques, such as VSM, which introduce a depth offset. See ShadowBufferFilteringOptions and ShadowBufferFilteringTech for more info.