70 4.ScreenSpaceClassificationforEfficientDeferredShading
We do this by prebuilding a lookup table that converts a 7-bit raw classifica-
tion ID into a 5-bit optimized classification ID, as shown in Listing 4.8. Each ID
is passed through this lookup table before being used for index buffer generation.
These two bits give us four possible combined properties, which is enough to
represent all possible combinations in the scene as follows:
00 = solid shadow.
01 = solid shadow + shadow fade + sunlight.
10 = sun light (with no shadows).
11 = soft shadow + shadow fade + sunlight.
The only caveat to collapsing these bits is that we’re now always calculating
shadow fade when soft shadows are enabled. However, this extra cost is negligi-
ble and is far outweighed by the benefits of reducing the shader count to 32.
#define LIGHT_SCATTERING (1 << 0)
#define MSAA_EDGE (1 << 1)
#define SKY (1 << 2)
#define SUN_0 (1 << 3)
#define SUN_1 (1 << 4)
unsigned char output[32];
for (int iCombo = 0; iCombo < 128; iCombo++)
{
// Clear output bits.
unsigned char bits = 0;
// Most combos are directly copied.
if (iCombo & RAW_LIGHT_SCATTERING) bits |= LIGHT_SCATTERING;
if (iCombo & RAW_MSAA_EDGE) bits |= MSAA_EDGE;
if (iCombo & RAW_SKY) bits |= SKY;
// If in solid shadow.
if (iCombo & RAW_SHADOW_SOLID)
{
// Set bit 0 if fading to sun.
if ((iCombo & RAW_SHADOW_FADE) &&
(iCombo & RAW_SUN_LIGHT))
bits |= SUN_0;
4.10Optimizations 71
}
else if (iCombo & RAW_SUN_LIGHT) // else if in sun
{
// Set bit 1.
bits |= SUN_1;
// Set bit 0 if in soft shadow.
if (iCombo & RAW_SHADOW_SOFT)
bits |= SUN_0;
}
// Write output.
output[iCombo] = bits;
}
Listing 4.8. This builds a lookup table to convert from raw to optimized material IDs.
TileCoalescing
We mentioned earlier that we take advantage of the tile block layout to speed up
index buffer generation by coalescing adjacent tiles. This is done by comparing
each entry in a block row, which is very fast because they’re contiguous in
memory. If all entries in a row are the same, we join the tiles together to make a
single quad. Figure 4.7 shows an example for the Xbox 360 platform. By coa-
lescing a row of tiles, we only have to generate one primitive instead of four. On
the PlayStation 3, the savings are even greater because a block size is
1
61
6
tiles.
We extend this optimization even further on the Xbox 360 and coalesce an entire
block into one primitive if all 16 IDs in the block are the same.
Figure 4.7. Coalescing two rows of tiles within a single block on the Xbox 360.
10 10 1018
34 34 3434
34 18 1010
10 10 1010
72
4.
1
1
1Perfo
r
Using t
h
implem
e
fication
m
on the
P
pass, an
d
F
i
Task
Depth
-
sificat
i
Pixel
c
Globa
l
Total
Table 4.
2
cation m
e
r
mance
C
h
e scene sho
w
e
ntation that
c
m
ethod. The
P
layStation 3
d
the extra sh
a
ig
ure 4.8. The
-
related clas-
i
on
c
lassification
l
light pass
. Performanc
e
e
thod. All nu
m
4.Scre
e
C
ompari
s
w
n in Figure
4
c
alculates all
l
results are s
h
is very smal
l
a
der cost is
m
Split/Second
s
PlayStation
Naive
0.00
0.00
13.93
13.93
e
comparisons
m
bers are times
e
nSpaceCla
s
on
4
.8, we com
p
l
ight properti
h
own in Tabl
e
l
because we
m
inimal.
s
cene used for
o
3 Pla
y
Stati
o
Classific
a
1.29
~0.00
4.82
6.11
for a naive i
m
measured in
m
s
sificationfo
r
p
are perform
a
i
es for all pix
e
e 4.2. The pi
x
’re piggybac
k
our performa
n
o
n 3
a
tion
Xbox
3
Naive
0.00
0.00
8.30
8.30
m
plementation
m
illiseconds.
r
EfficientDe
f
a
nce betwee
n
e
ls and our ti
l
x
el classifica
t
k
ing onto an
n
ce compariso
n
3
60 Xbox 3
6
Classifi
c
0.70
0.69
2.69
4.08
versus our til
e
f
erredShadi
n
n
a naive
l
e classi-
t
ion cost
existing
n
s.
6
0
c
ation
e
classifi-
n
g
References 73
References
[Swoboda 2009] Matt Swoboda. “Deferred Lighting and Post Processing on Play-
Station
3.” Game Developers Conference, 2009.
[Moore and Jefferies 2009] Jeremy Moore and David Jefferies. “Rendering Techniques
in Split/Second.” Advanced Real-Time Rendering in 3D Graphics and Games,
ACM SIGGRAPH 2009 course notes.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.122.82