Gamasutra is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Gamasutra: The Art & Business of Making Gamesspacer
Sponsored Feature: Onloaded Shadows: Moving Shadow Map Generation from the GPU to the CPU
View All     RSS
November 24, 2020
arrowPress Releases
November 24, 2020
Games Press
View All     RSS







If you enjoy reading this site, you might also want to check out these UBM Tech sites:


 

Sponsored Feature: Onloaded Shadows: Moving Shadow Map Generation from the GPU to the CPU


January 26, 2011 Article Start Previous Page 2 of 3 Next
 

Shadow Map Algorithm

The original Cascaded Shadow Maps algorithm isn't suitable for this Onloaded Shadows because it's not view-invariant. A significant advantage of Cascaded Shadow Maps is that it renders a shadow map only for the areas directly intersected by the view frustum.

Because the view frustum may rotate and move quickly, the frustum can intersect areas not covered by the cascades before a new shadow map is generated by the onloaded pass.

The solution used in Onloaded Shadows is to center the cascades on the view camera, yielding lower quality shadow maps while keeping many of the advantages of the cascaded shadow map technique.

Camera movement must be slow enough to avoid the viewpoint entering the next level of the cascade prior to the generation of a new shadow map.


Figure 2: Screenshot of the sample implementation from the light's view with cascades visualized.

Shadow maps for the nearest cascade are generated every frame on the GPU in order to allow dynamic shadows for nearby objects. The division of cascades across GPU/CPU boundary can be adjusted depending on a performance heuristic.

Technique Overview

The main thread renders the scene using shadow map data stored on the GPU, while the WARP thread generates the shadow map asynchronously. The WARP thread copies the shadow map to a staging buffer and maps it to a subresource. The GPU then updates its shadow buffer with the mapped subresource. The new camera data is utilized once a copy is complete, and then the WARP thread is signaled to once again begin shadow map generation.

Alternatively, asynchronous shadows can be naively implemented by generating shadows synchronously on the GPU every set number of frames.

In this way, a GPU technique which generates the same results can be used to compare with the Onloaded Shadows technique, and performance can be compared by looking at how much of a spike in frame time occurs during either the subresource copy (for Onloaded Shadows) or during the synchronous shadow processing (for the GPU technique).

A significant frame time spike occurring every few seconds would cause a noticeable stall and would be disadvantageous to any game or product that uses this technique. The work done during the synchronous frame is broken down into small enough pieces to cause as little impact as possible. This is called the Distributed Stall optimization.

For the Onloaded Shadows technique, the synchronous copy can be easily subdivided as far as a single byte. For the GPU technique, because the work is not homogenous, breaking apart the shadow processing work becomes significantly more complicated.

For our sample implementation, the work was divided per cascade, and further divided between the original shadow draw and the various post processing passes on the shadow buffer.

Two shadow buffers are used on the GPU because the updates are performed across many frames, with one shadow buffer being copied to while the other's data is used. (If only a single shadow buffer was used, noticeable artifacts would appear while the copy was occurring.) The roles of the two shadow buffers are then swapped.

 


Article Start Previous Page 2 of 3 Next

Related Jobs

Sucker Punch Productions
Sucker Punch Productions — Bellevue, Washington, United States
[11.23.20]

Senior Camera Programmer
Sucker Punch Productions
Sucker Punch Productions — Bellevue, Washington, United States
[11.23.20]

Programmer
Sucker Punch Productions
Sucker Punch Productions — Bellevue, Washington, United States
[11.23.20]

Producer
Sucker Punch Productions
Sucker Punch Productions — Bellevue, Washington, United States
[11.23.20]

Narrative Writer





Loading Comments

loader image