Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
1  
This kind of sounds like a draw order issue. –  Byte56 Apr 2 '12 at 14:38
    
It is, but I can't manually control it. (Perhaps hints on how to make the Ogre Engine render only static geometry objects later?) –  teodron Apr 3 '12 at 9:59
add comment

1 Answer

up vote 6 down vote accepted
+50

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.

share|improve this answer
    
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! –  teodron Apr 3 '12 at 9:58
2  
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? –  John Calsbeek Apr 3 '12 at 16:18
    
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? –  teodron Apr 5 '12 at 13:22
1  
+1, nothing will work as long as you render translucent objects in your Z-prepass. It doesn't make sense. –  Laurent Couvidou Apr 5 '12 at 14:06
    
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). –  John Calsbeek Apr 5 '12 at 16:28
show 9 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.