Graphics Reference
In-Depth Information
5. We can then define the pixel shaders for each of the light types. The following snippet
of code supports a point light:
float4 PSPointLight (in PixelIn pixel) : SV_Target
{
float4 result = (float4)0;
result.a = 1.0f;
GBufferAttributes attrs;
ExtractGBufferAttributes(pixel,
Texture0, Texture1,
Texture2, TextureDepth,
attrs);
float3 V, L, H;
float D, attenuation;
PrepareLightInputs((float3)0, attrs.Position,
attrs.Normal, LightParams,
V, L, H, D, attenuation);
result.xyz = LightContribution(attrs, V, L, H, D,
attenuation);
return result;
}
6.
The directional light simply overrides the L (to light) vector and sets the attenuation
back to 1.0f (no fall off).
float4 PSDirectionalLight (in PixelIn pixel) : SV_Target
{
...
PrepareLightInputs((float3)0, attrs.Position,
attrs.Normal, LightParams,
V, L, H, D, attenuation);
L = normalize(-LightParams.Direction);
H = normalize(L + V);
attenuation = 1.0f;
result.xyz = LightContribution(attrs, V, L, H, D,
attenuation);
return result;
}
7.
And lastly, we have our simple ambient light pixel shader.
float4 PSAmbientLight(in PixelIn pixel) : SV_Target
{
...
result.xyz = attrs.Diffuse * LightParams.Color;
return result;
}
We are now ready to move onto creating the LightRenderer class in our C# project,
define some lights, and hook up the G-Buffer
 
Search WWH ::




Custom Search