
Title
Deferred lighting, C++/D3D, 2012.
Description
I am just done my deferred lighting debugging works recently, there are some notes based on my own experience:- In the geometry pass, I prepare 3 render targets a. normal map (view space normal) + clip space depth (z/w).
- Draw lights
- Firstly, draw a ambient light, we fetch the diffuse texture and compute with the ambient light, then writing the color into the frame buffer. In terms of the depth value, we fetch it from the alpha channel of the 1st render target and write the value into z buffer. If you have z-prepass, you needn't rewrite depth to the z buffer.
- Secondly, having a sun light means drawing a full screen rectangle using clip space coordinate based on the directional lighting formula: multiply among diffuse, specular map, and lighting BRDF. Enable alpha blending one plus one, and disable depth write
- Thirdly, regarding to omni lights, using a light volume (sphere) to draw, and uses point lighting BRDF formula: enable alpha blending one plus one, use front-face culling, disable depth write, and depth test uses greater than.
We can use clip space depth value to transform pixels into the view space and doing lighting. Importantly, the texture coordinate of the MRT maps in pixel shaders must be transformed from the screen space to the image space !!!
Otherwise, you will see the light volume is clipped by your screen.
123float2 vTexcoord = IN.texCoord.xy / IN.texCoord.z;
vTexcoord.x = 0.5 * (1 + vTexcoord.x);
vTexcoord.y = 0.5 * (1 - vTexcoord.y);
- Lastly, supporting a spot light just need to draw a cone mesh, however, this kind of lights I haven't tried yet.
b. diffuse map (diffuse color).
c. specular map (specular color and shininess).