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: Early Z Pass

  • 1
    \$\begingroup\$ This kind of sounds like a draw order issue. \$\endgroup\$
    – House
    Commented Apr 2, 2012 at 14:38
  • \$\begingroup\$ It is, but I can't manually control it. (Perhaps hints on how to make the Ogre Engine render only static geometry objects later?) \$\endgroup\$
    – teodron
    Commented Apr 3, 2012 at 9:59

1 Answer 1


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.

  • \$\begingroup\$ While using an alpha rejection flag and blending the objects without writing color information in the first pass, the objects do get drawn correctly. But what I fail to understand is why using a custom vertex shader that slightly offsets the Z a little, totally hinders the early Z culling. Unfortunately, I went with drawing everything in the pre-pass. Your observation does not hold, i.e. the same behavior is exhibited: from one side, the alpha textured polygons are rendered correctly, from the other they capture the background (not the closest contributing object!). Thanks for the hints! \$\endgroup\$
    – teodron
    Commented Apr 3, 2012 at 9:58
  • 2
    \$\begingroup\$ So I'm confused as to what you're actually doing now (drawing transparent/not drawing transparent on the pre-pass) and whether you're still having the problem, but how exactly are you altering the Z position of vertices when everything goes to crap? \$\endgroup\$ Commented Apr 3, 2012 at 16:18
  • \$\begingroup\$ I am drawing the transparent objects in the first pass, but that's not sufficient. I tried using a depth bias for this pass to avoid flickering objects. Alpha blending gets rid of shadows. Without alpha blending inthe first pass, things work ok, except for the shadows of some trees that do not let light pass through their leaves. Is it possible to have Early Z functional and still not damage the other passes? \$\endgroup\$
    – teodron
    Commented Apr 5, 2012 at 13:22
  • 1
    \$\begingroup\$ +1, nothing will work as long as you render translucent objects in your Z-prepass. It doesn't make sense. \$\endgroup\$ Commented Apr 5, 2012 at 14:06
  • \$\begingroup\$ Yeah, you want to render absolutely nothing alpha blended the first pass, but alpha tested objects are fine (as long as the shader for that pass actually performs the alpha test). \$\endgroup\$ Commented Apr 5, 2012 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .