Graphics Reference
In-Depth Information
How to do it…
We'll begin by creating the HLSL shaders that will read the G-Buffer and output the
contribution of light based on a simple Blinn-Phong lighting model.
1. Create a new HLSL file named Lights.hlsl and add the G-Buffer texture references
and functions that we created in the previous recipe to read the G-Buffer attributes.
2.
Add the following additional HLSL structures:
struct LightStruct
{
float3 Direction;
uint Type; // 0=Ambient, 1=Direction, 2=Point
float3 Position;
float Range;
float3 Color;
};
cbuffer PerLight : register(b4)
{
LightStruct LightParams;
};
struct PixelIn // Same as SA Quad
{
float4 Position : SV_Position;
float2 UV : TEXCOORD0;
};
3.
We need a new simple vertex shader that accepts the default vertex structure for
rendering meshes, and outputs only the position and a UV coordinate based upon
the final normalized device coordinate. This shader will be used to render any light
volume meshes:
PixelIn VSLight(VertexShaderInput vertex)
{
PixelIn result = (PixelIn)0;
vertex.Position.w = 1.0f;
result.Position = mul(vertex.Position,
WorldViewProjection);
// Determine UV from device coords
result.UV.xy = result.Position.xy / result.Position.w;
// The UV coords: top-left [0,0] bottom-right [1,1]
result.UV.x = result.UV.x * 0.5 + 0.5;
result.UV.y = result.UV.y * -0.5 + 0.5;
return result;
}
 
Search WWH ::




Custom Search