Deferred lighting

     Today I finish my deferred lighting debug, there are some experience notes:
  1. In the geometry pass, I prepare 4 render target
    • depth map( view position and depth, actually we can try to just store the depth value only) - remove, we can just save clip space depth(z/w) to instead
    • normal map( view space normal ) + clip space depth(z/w)
    • diffuse map( diffuse color)
    • specular map( specular color and shininess )
  2. Draw lights
    • First, draw ambient light, we fetch the diffuse texture compute with ambient light  and fetch depth value from depth map write to the frame buffer and depth buffer. If you have z-prepass needn't rewrite depth to the z buffer.
    • Second, sun light draw a full screen rectangle( is clip space coordinate ) compute the directional lighting, multiply among diffuse, specular map and lighting formula. Enable alpha blending one plus one, disable depth write
    • Third, omni light draw the light volume( a sphere ), use point lighting formula. Enable alpha blending one plus one, use front-face culling, disable depth write, and depth test use greater than. We can use clip space depth to transform pixel to the view space and do lighting. Importantly, the texture coordinate of the MRT maps, must in the pixel shader transform from screen space to image space !!! otherwise you will see the light volume slip on your screen.

           float2 vTexcoord = IN.texCoord.xy / IN.texCoord.z;   
          vTexcoord.x = 0.5 * (1 + vTexcoord.x);
          vTexcoord.y = 0.5 * (1 - vTexcoord.y);

      thank for this article(http://www.gamedev.net/community/forums/topic.asp?topic_id=557716) give me idea.
    • Fourth,  spot light just draw a cone mesh, this kind of light we don't not support now.


      The bottom figure is ambient + sun + three omni light result:

                 World space deferred lighting discussion: http://www.gamedev.net/community/forum/topic.asp?topic_id=544144&whichpage=1&#3508871

Comments

Popular posts from this blog

Drawing textured cube with Vulkan on Android

glTF loader for Android Vulkan

C++ unit testing & CI integration in GitHub (I/2)