Q:

Early Z culling - Ogre

For Ogre experienced people, but also experts in the field:
Early Z culling is sometimes quite desirable, and that's what I tried to do in Ogre by using a two pass material. The first one is writing to the Z Buffer, but not to the frame buffer. This is how it looks like:
 pass EarlyZ
    {
        texture_unit TU0
        {
            //ambient diffuse texture
            texture $TU0_TEXTURE 
            tex_coord_set 0
            filtering trilinear
        }
        //cull_software none
        //cull_hardware none
        lighting off
        colour_write off
        shading flat
        //scene_blend alpha_blend
        alpha_rejection  greater_equal 200
        depth_bias  -5 -5 // ugly hack - without it, objects tend to flicker
    }

The biggest problem I get is with alpha objects and shadows. For example, now I can't get  tree impostors to cast correct shadows instead of blocks. Although they are rendered correctly, the PSSM isn't working correctly, so the shadows tend to look like stencil shadows. Any ideas on how to fix it? As many people said: is it possible to perform early Z culling and still have transparent objects in the scene? If yes, some hints to do it in Ogre? Here are some screenshots:

A:

Your alpha-blended objects should not participate in a depth pre-pass. For a given final pixel, its color will be a number of colors blended together at different depths: the portion of the color furthest away from the camera will either be the sky/background or an opaque object, and all the other contributions will be from semi-transparent objects. And if you draw everything in a depth pre-pass, then the depth in the depth buffer will always be the closest contributing object (a semi-transparent object), not the farthest contributing object (an opaque object or sky/background element).
Note that alpha-tested objects are fine, as long as the pixel shader that performs the testing is actually being run on the depth pre-pas.

