Graphics Reference
In-Depth Information
//
Convert
position and
normals
to
world
space
output.PositionWS
=
mul(
input.Position, WorldMatrix ).xyz;
output.NormalWS
=
normalize( mul(
input.Normal, (float3x3)WorldMatrix
) );
//
Calculate the clip-space
position
output.PositionCS
=
mul(
input.Position, WorldViewProjMatrix
);
// Pass along the texture coordinate
output.TexCoord
=
input.TexCoord;
return output;
}
// 6-Buffer pixel shader
PSOutput
PSMain(
in PSInput input )
{
PSOutput output;
// Sample the diffuse map
float3 diffuseAlbedo = DiffuseMap.Sample( AnisoSampler, input.TexCoord ).rgb;
// Normalize
the
normal after interpolation
float3 normalWS =
normalize(
input.NormalWS );
// Output our G-Buffer
values
output.Normal = float4( normalWS, 1.0f );
output.DiffuseAlbedo = f1oat4( diffuseAlbedo, 1.0f );
output.SpecularAlbedo = float4( SpecularAlbedo, SpecularPower );
output.Position = float4( input.PositionWS, 1.0f );
return output;
Listing 11.1.
G-buffer generation shader code.
It should also be mentioned that the tessellation pipeline can also be used when ren-
dering the g-buffer. G-buffer generation is the only pass where the scene geometry is being
used, so if tessellation is desired, it should be used in this phase so that the g-buffer infor-
mation reflects the finely tessellated meshes.
G-Buffer Rendering with Normal Mapping
Since the final surface normal vector is required for the lighting pass, any normal mapping
5
must be applied during the g-buffer pass. A common approach for forward rendering is to
transform light positions and vectors to tangent space (Lengyel, 2001) in the vertex shader,
and then apply lighting in that space to facilitate the use of normal maps. However, this
5
Normal mapping
is a technique that simulates more complex geometry by storing perturbed surface normal
vectors in a texture, and then looks up these normal vectors in the pixel shader for use in lighting calculations.
Search WWH ::
Custom Search