Graphics Reference
In-Depth Information
Figure 1 1.7. Optimized view-space position reconstruction.
clip distance. This scaling value can be calculated in the g-buffer pass and stored in the
g-buffer, so that it can be used in the lighting pass. This technique is illustrated in
Figure 11.7.
// -- G-Buffer vertex shader --
// Calculate view space position of the vertex and pass it to the pixel
shader
output.PositionVS = mul(input.PositionOS, WorldViewMatrix).xyz;
// -- G-Buffer pixel shader --
// Divide view space Z by the far clip distance
output.Depth.x = input.PositionVS.z / FarClipDistance;
// -- Light vertex shader --
#if VOLUMES
II Calculate the view space vertex position
output.PositionVS = mul(input.PositionOS, WorldViewMatrix);
#elif QUADS
// Calculate the view space vertex position (you can also just directly
// map the vertex to a frustum corner to avoid the transform)
output.PositionVS = mul(input.PositionOS, InvProjMatrix);
#endif
// Light Pixel shader
#if VOLUMES
// Extrapolate the view space position to the far clip plane
float3 viewRay = float3(input.PositionVS.xy *
(FarClipDistance / input.PositionVS. z),
FarClipDistance);
#elif QUADS
Search WWH ::




Custom Search