Early zpass rendering?

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Early zpass rendering?

Post by Zeal » Wed Nov 01, 2006 7:41 pm

I wasnt sure exactly what this technique was called, so I had trouble searching for it. Ive heard you can render your entire scene first reading only zdepth, and store that information (in a texture?), THEN you render your final scene. This way you can save a LOT of fillrate due to all the supper fast z culling, and you dont have to worry about rendering batches in any particular order (back to front doesnt matter anymore).

So my question is,

A.) What is this technique officially called? Early zpass?

B.) Does Ogre support it, and would anyone be so kind as to point me to some info that might help me implement it?

Thanks in advance!
0 x

User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
Contact:

Post by haffax » Wed Nov 01, 2006 8:19 pm

You probably mean "early z out", though I don't see this name used often and it sounds somewhat silly. The other name I heard "zbuffer pre-fill" is better IMHO, as it is more to the point.

What the technique does is to utilize the extremely fast depth rejection of fragments. According to ATI optimization guide, a radeon9800 card can reject 160 pixels per clock (IIRC). You first deactivate colour write and only activate depth write and draw the scene, then you draw with materials on, just like you wrote.

But you still have to care about batching, since it doesn't help the CPU at all, render states are still set to my knowledge still set, etc, etc..
And it still comes with the overhead of an extra pass, which is usually not neglectable. This technique is useful for complex materials with big textures and/or shaders.

You can use this with ogre easily. Just add an extra pass as the *first* pass to your more complex materials. And set lighting off, colour_write off for the pass.

Ogre renders for each renderqueue first all first passes of the materials, then all second passes and so on.. This means, that after the first pass of each material the zbuffer is filled already and the second pass of the materials might not even be rendered, if objects are hidden behind others, and thus expensive shaders might not get called.
0 x
team-pantheon programmer
creators of Rastullahs Lockenpracht

User avatar
Falagard
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2060
Joined: Thu Feb 26, 2004 12:11 am
Location: Toronto, Canada
Contact:

Post by Falagard » Wed Nov 01, 2006 8:36 pm

What haffax said.

Also, if you're performing a pass per light then you can just render your ambient pass before your lighting passes and it'll take care of writing down the depth buffer for you so that if your lighting passes have complex pixel shaders then those pixels will be ignored if they fail the zbuffer test.

A tip with Ogre materials is that the Ogre renderer splits up passes into those that are ambient passes, and then everything else. It renders all ambient passes in the scene first, and then all other passes afterwards. This is specifically to take advantage of "early z-out" or "zbuffer pre-fill".

To let the renderer know that a particular pass should be considered an ambient pass you specify an ambient value of 1 1 1 and a diffuse and specular of 0 0 0 in the pass. Even if you're disabling colour write you'll want to do this so that Ogre classifies it as an ambient pass.

At least that's what I understand from the documentation.
0 x

User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Post by Zeal » Wed Nov 01, 2006 8:41 pm

Ogre renders for each renderqueue first all first passes of the materials, then all second passes and so on..
Ok, so right now I have two objects each with a complex material, each with only one pass. If I simply insert a 'pre pass' to those materials (one that only reads zdepth with color/light off), ogre will be smart enough to use that z info to cull the scene in 'pass 2'?

Sounds pretty easy, no fancy scene manager stuff eh? I think I can handle that.

Im curious about batching though, you said I still had to worry about it... renderstate shouldnt be a factor for the first (zdepth only) pass right? Regardless of the order in which things are rendered, why would ogre care about states for a zdepth only pass?
0 x

User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
Contact:

Post by haffax » Wed Nov 01, 2006 8:51 pm

Zeal wrote:Ogre will be smart enough to use that z info to cull the scene in 'pass 2'?
Ogre doesn't have to be smart here at all, it is all done by the GPU using the zbuffer. That's what the zbuffer is for. ;) (among others)
Zeal wrote:renderstate shouldnt be a factor for the first (zdepth only) pass right?
Right.
Zeal wrote: Regardless of the order in which things are rendered, why would ogre care about states for a zdepth only pass?
It doesn't and that is not what I meant. But Ogre still sets the render states for the second pass, even if not a single pixel of it is actually drawn. Because there is no culling in this sense, but rather a pixel rejection based on the z value.
0 x
team-pantheon programmer
creators of Rastullahs Lockenpracht

User avatar
Zeal
Ogre Magi
Posts: 1260
Joined: Mon Aug 07, 2006 6:16 am
Location: Colorado Springs, CO USA

Post by Zeal » Wed Nov 01, 2006 9:10 pm

Ok cool so now that I know how its done (sounds super simple), do you guys think its worth it? Im sure the answer is - it depends.

I was thinking of doing a early zpass for AT LEAST my terrain and some large structures (buildings, towers), because I figure such things are somewhat simple (geometry wise), and due to their size its very likely they will be obscuring a large part of the scene. And since I use complex shaders on just about everything, I THINK this will really help a lot. Well see...

Ive been toying with the idea of rendering a lot of my trees as large static batches, and I think a early z pass would help a lot here too...
0 x

Post Reply