Graphics Reference
In-Depth Information
space within the minimum and maximum of a depth cell and modulates with the
previous transparency.
float4
main
(
PS_INPUT input
):
SV_Target
{
// Texture/image coordinates to sample/load/read the depth
// values with .
float2
texcoords
=
input
.
tex
;
float4
fineZ
;
fineZ
.
x
=
linearize
(
hiZBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipPrevious
,
int2
(0, )).
x
);
fineZ
.
y
=
linearize
(
hiZBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipPrevious
,
int2
(0,
−
1) ) .
x
);
fineZ
.
z
=
linearize
(
hiZBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipPrevious
,
int2
(
−
1, 0) ) .
x
);
fineZ
.
w
=
linearize
(
hiZBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipPrevious
,
int2
(
−
1,
−
1) ) .
x
);
// hiZBuffer stores min in R and max in G.
float
minZ
=
linearize
(
hiZBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipCurrent
).
x
);
float
maxZ
=
linearize
(
hiZBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipCurrent
).
y
);
// Pre
−
divide.
float
coarseVolume
=1.0
f
/(
maxZ
−
minZ
);
// Get the previous four fine transparency values .
float4
visibility
;
visibility
.
x
=
visibilityBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipPrevious
,
int2
(0, 0)).
x
;
visibility
.
y
=
visibilityBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipPrevious
,
int2
(0,
1)).
x
;
visibility
.
z
=
visibilityBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipPrevious
,
int2
(
−
1, 0 ) ) .
x
;
visibility
.
w
=
visibilityBuffer
.
SampleLevel
(
pointSampler
,
texcoords
,
mipPrevious
,
int2
(
−
−
1,
−
1)).
x
;
// Calculate the percentage of visibility relative to the
// calculated coarse depth. Modulate with transparency of
// previous mip.
float4
integration
=
fineZ
.
xyzw
abs
(
coarseVolume
)
visibility
.
xyzw
;
// Data
−
parallel add using SIMD with a weight of 0.25 because
// we derive the transparency from four pixels .
float
coarseIntegration
=
dot
(0.25
f
,
integration
.
xyzw
);
return
coarseIntegration
;
}
Listing 4.4.
The demo uses both a minimum Hi-Z buffer and a maximum Hi-Z buffer.
With them, we calculate how much empty space there is in between the hierarchy depth
cells. We linearize the post-projected depth into view-space Z for the computation. We
could also output a linear Z-buffer during the Hi-Z pass, but this would require some
changes in the ray-tracing pass and cone-tracing pass because view-space Z cannot be
interpolated in screen space by default.