Graphics Reference
In-Depth Information
uint PackNormal(in float3 N)
{
float2 encN = EncodeAzimuthal(N);
// Pack float2 into uint
uint result = 0;
result = f32tof16(encN.x);
result |= f32tof16(encN.y) << 16;
return result;
}
13. And finally, create the pixel shader to collect and output the attributes to the
G-Buffer render targets:
GBufferOutput PSFillGBuffer(GBufferPixelIn pixel)
{
// Normalize our vectors as they are not
// guaranteed to be unit vectors after interpolation
float3 normal = normalize(pixel.WorldNormal);
...
float3 diffuse;
float specIntensity;
... sample normal, texture and specular intensity
GBufferOutput result = (GBufferOutput)0;
result.Target0.xyz = diffuse;
result.Target0.w = specIntensity;
result.Target1 = PackNormal(normal);
result.Target2.xyz = MaterialEmissive.rgb;
// Specular Power normalized to 0-50 range
result.Target2.w = MaterialSpecularPower / 50;
// Return result
return result;
}
14. Within ConstantBuffers.cs , we need to update the PerObject structure to
include the additional matrices we defined in HLSL:
public struct PerObject {
...
public Matrix ViewProjection;
public Matrix View;
public Matrix InverseView;
 
Search WWH ::




Custom Search