Tuesday, 2 April 2013

Assignment 10: Depth Pass

Requirements
  • Add Depth Techniques to each of your Effects that renders in the Opaque bucket
    • Remember that a Technique consists of:
      • Vertex Shader
      • Fragment Shader
      • Render State
    • The output of the fragment shader in your Depth technique must be the normalized Z value of the fragment's position in view space
      • You already know how to calculate the view position. In order to store it in a texture we want it to be [0,1], which means it should be divided by the far plane distance. This is the distance you use to create the view-to-projection transformation, and you should pass it as a uniform into the shader
      • You only need to output a value in the red channel, because we will use a single channel texture format. The final statement in the fragment shader can look something like this:
        • o_color = float4( depth, 0.0, 0.0,1.0 );
    •  The depth shaders for completely opaque Effects can be very simple, but the ones for binary alpha Effects must be a bit more complicated. You will have to look up the diffuse texture, and clip the fragment to make sure that you only write depth for those fragments that should be shaded
    • The Depth Techniques should write to depth, and the depth test should succeed when depth is less than or equal to the previous depth
  • Update the Shade Techniques for each of your Effects that renders in the Opaque bucket
    • The Shade Techniques should not write to depth, and the depth test should only succeed when depth is equal to the previous depth
  • (Your Effects that render in the Translucent bucket shouldn't change. They should still only have one Shade Technique, and their depth tests should succeed when depth is less than or equal to the previous depth. (It is up to you whether they write to depth or not; in our assignments it shouldn't make a difference)
  • Create a view depth texture
    • You will create this the same way you created the Opaque bucket texture for Assignment 09, except that you should use D3DFMT_R16F for the texture's format. This means that it is a 16-bit floating point texture that only uses the red channel.
  • Add a Depth pass to your renderer. The general outline of your renderer will be something like this:
    • Render Depth techniques of Opaque bucket
      • Set the view depth texture as the render target
      • Clear the color and depth
        • (Remember that "color" in this case is our "view depth" texture, and depth is still the hardware depth buffer)
      • Draw all of your objects in the Opaque bucket using their Depth Techniques
        • (Optional) Some of you sort your draw calls based on shaders rather than Effects. If you do this you may consider adding an additional sorting front-to-back to increase efficiency
    • Render Shade techniques of Opaque bucket
      • Set the Opaque bucket texture as the render target
      • Clear the color but not the depth
        • (We need to keep the depth that was rendered so we can compoare against it)
      • Draw all of your objects in the Opaque bucket using their Shade Techniques
    • Render Shade techniques of Translucent bucket
      • Set the real back buffer as the render target
      • Copy the Opaque bucket texture into the back buffer
      • Draw all of your objects in the Translucent bucket using their Shade Techniques
  • Create a translucent Effect that has soft intersections
    • You will need to make the view depth texture available to the fragment shader
    • You will need to make the far plane distance available to the fragment shader
    • Compare the current fragment's view depth with the previous view depth
      • The current fragment's view depth can be found the same way that the depth pass texture was created: Pass the view position to the fragment shader and use the Z component
      • The previous fragment's view depth can be found by:
        • Looking up the view depth texture using the screen texture coordinates (calculated the same way that we did in Assignment 09)
        • Multiplying the normalized depth by the far plane distance
      • Subtracting the current depth from the previous depth will now give you the difference, in world units, of the current depth from the previous depth (positive numbers mean that the current depth is closer to the camera and negative numbers mean it is further away)
    • Fade out the translucent object when it gets close to what was already rendered
      • We talked about the general math for doing this in class. Experiment to find something that looks good.
  • Your scene must include:
    • An opaque ground plane
    • At least one object with binary alpha that is in front of the ground plane to prove that your depth pass works correctly
    • At least one object with soft intersections that is intersecting the ground plane
      • (It is not a requirement, but you should consider having keyboard controls that can move the intersecting object up and down to make it easier to verify that the soft intersections are working. If you do this please document the keyboard controls in your writeup)
  • Your writeup must include a screenshot of the view depth texture
    • (Optional) It is interesting to compare this to the actual hardware depth buffer visualization that PIX shows. Consider showing a screenshot of this side-by-side with the view depth texture that you created

No comments:

Post a Comment