Graphics Reference
In-Depth Information
How to do it…
First let's begin by outlining the HLSL code necessary to extract the attributes from the G-Buffer.
1. We'll start by defining a structure to store the loaded G-Buffer attributes in, as shown
in the following HLSL code snippet:
// Structure for holding loaded G-Buffer attributes
struct GBufferAttributes
{
float3 Position;
float3 Normal;
float3 Diffuse;
float SpecularInt; // specular intensity
float3 Emissive;
float SpecularPower;
};
// Screen-aligned Quad PixelIn
struct PixelIn
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
2.
In order to unpack the normal, we will require the following functions:
float3 DecodeAzimuthal(in float2 enc)
{
// Unproject Lambert azimuthal equal-area projection
// http://aras-p.info/texts/CompactNormalStorage.html
float2 fenc = enc*4-2;
float f = dot(fenc,fenc);
float g = sqrt(1-f/4);
float3 n;
n.xy = fenc*g;
n.z = 1-f/2;
return n;
}
float3 UnpackNormal(in uint packedN)
{
// Unpack uint to float2
float2 unpack;
unpack.x = f16tof32(packedN);
unpack.y = f16tof32(packedN >> 16);
// Decode azimuthal (unproject)
return DecodeAzimuthal(unpack);
}
 
Search WWH ::




Custom Search