Graphics Reference
In-Depth Information
// Pixel Shader output structure
struct GBufferOutput
{
float4 Target0 : SV_Target0;
uint Target1 : SV_Target1;
float4 Target2 : SV_Target2;
// | -----------32 bits-----------|
// | Diffuse (RGB) | SpecInt (A) | RT0
// | Packed Normal--------------->| RT1
// | Emissive (RGB) | SpecPwr (A) | RT2
};
11. We will be using view-space for our G-Buffer operations; therefore, we need to provide
a new vertex shader that passes the normal and tangent vectors in view-space:
GBufferPixelIn VSFillGBuffer(VertexShaderInput vertex)
{
GBufferPixelIn result = (GBufferPixelIn)0;
result.Position = mul(vertex.Position,
WorldViewProjection);
...
// Transform normal/tangent into world view-space
result.ViewNormal = mul(vertex.Normal,
(float3x3)WorldInverseTranspose);
result.ViewNormal = mul(result.ViewNormal, (float3x3)View);
result.ViewTangent = float4(mul(vertex.Tangent.xyz,
(float3x3)WorldInverseTranspose), vertex.Tangent.w);
result.ViewTangent.xyz = mul(result.ViewTangent.xyz,
(float3x3)View);
return result;
}
12. We will use the following functions within our pixel shader to encode and pack our
normal vectors into the second render target:
float2 EncodeAzimuthal(in float3 N)
{
// Lambert azimuthal equal-area projection
// with normalized N is equivalent to
// Spheremap Transform but slightly faster
//http://aras-p.info/texts/CompactNormalStorage.html
float f = sqrt(8*N.z+8);
return N.xy / f + 0.5;
}
 
Search WWH ::




Custom Search