Friday, April 12, 2013

Graphics Assignment 10

The 10th assignment was on differed rendering. You hold the output of the opaque bucket and pass it to the translucent object bucket to create a fading effect at the intersection of the translucent object with Opaque objects bucket.

   Initial depth pass:
     The opaque bucket is asked to draw the depth of the opaque objects relative to the distance from the camera. We create a new surface for drawing this depth. Instead of using D3DFMT_X8R8G8B8 format for the surface, we take D3DFMT_R16F because the result we want to output from the fragment shader is depth and that requires only red channel to output to. To make the fragment shader output the depth of the opaque bucket to the viewDepth surface we set the render target to that surface instead of the back buffer. The texture is available from the viewDepth surface.

Draw Opaque Bucket:
    After we get the depth of all the opaque we can draw the opaque bucket to a different surface say, opaqueBuffer surface. The order of drawing opaque bucket and view depth doesn't matter.

Draw translucent Bucket:
  Set the render target to back buffer and Stretch rect the opaquebuffer surface and copy it to the backbuffer. Now calculate the distance from the camera of the pixel to be shaded  and compare it with the texel of the view depth texture( that is the depth of the opaque object in view space). We saturate the difference of these two pixel so that we get a value between 0 and 1. This then becomes the alpha value of the pixel.

To see the fading effect properly use the keys NUM8, 4, 2, and 6 which are mesh controls.

Final Output:








View Depth Texture:


Hardware Depth Buffer:



Download Code








No comments:

Post a Comment