Skip to main content
GameDev.net gamedev.net
🔒 Locked

Layers (Looking for suggestions)

Started by Blue*Omega Apr 20, 2005 at 11:29 AM 6 replies 1k views
Original Post
Blue*Omega
Blue*Omega
I'm currently working on a 3D "engine" (Just a demo, really) that imitates the feel of old 16 bit-era graphics. Though all the graphics are 3D models the camera is locked into pointing straight down the "Z" axis at all times, Collision detection only takes place on a 2d plane, and the graphics themselves are broken up into several "layers" (For Parallax Scrolling and other similar effects) The layers effect is what I'm working on now. My current solution is as such: -Start with the back-most layer -Preform culling/scrolling/etc -Render all visible entities on this layer -Clear the depth buffer (not the color) -Repeat with the next layer up till all layers are drawn. (This is all OpenGL, BTW. Not that it really matters.) This should work very nicely in theory (haven't finished implementing it yet) and elegantly prevents any element from one layer interfering with any others. (If you drew them all into the same depth buffer large objects in the background may intersect with objects in the foreground) There is one big problem, though. OVERDRAW! If you have a scene made up of, say, 10 layers, and each ends up drawing in the same section of the screen, you've just overwritten a pixle 9 times to get what should have been done in 1. This becomes even more of an issue when you introduce fragment shaders. Early z-out can help significantly reduce the number of fragment operations you go through. So I'm curious to see if anyone has any suggestions as to how to elegantly be able to render front to back and still keep each layer to it's own "plane." My idea thus far is to try and implement some sort of stencil buffer that masks the areas that have already been drawn as you go back, but I feel like there may be a better way. Thanks for any ideas!
Agony
Agony
Could you perhaps set the depth range to 0.00f to 0.09f for the first layer, to 0.10f to 0.19f for the second layer, etcetera. Wouldn't this map all your z values from normal space into a very set layer, so that each layer would still be separated from each other? Just a thought, though I get mixed up on some of this 3D camera/depth stuff sometimes...
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
Blue*Omega
Blue*Omega
That's certainly a possibility, but I can think of a couple of problems right off the bat:

1) Lost precision! Z fighting would be horrible if you were only allocating a tiny bit of the Z Buffer for a given section of the scene.

2) Difficult to scale. In theory, I only want the number of layers to be limited by the level designers imagination. Dividing up a finite amount of space like that eventually runs out. (Yes, it would take a while, but each new layer would make problem# 1 worse)

Thanks for the idea, though! Never hurts to throw out suggestions ^_^
DBX
DBX
Each layer uses the same Z value, so there would be no fighting/precision issues, and there are tens of thousands of possible Z values so you are going to run out of processing power before Z values.
Agony
Agony
Quote:
Original post by DBX
Each layer uses the same Z value, so there would be no fighting/precision issues, and there are tens of thousands of possible Z values so you are going to run out of processing power before Z values.
But each layer contains 3-dimensional objects, I'm assuming. If each layer merely contained flat sprites, sure, it'd be no problem.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas nly, and not for things themselves." - John Locke o
d_emmanuel
d_emmanuel
You might want to look into doing a "lay down z pass".
The idea behind this is to render the scene twice.
The first time, you render the scene with color writes and effects disabled
and z-writes enabled to obtain the z-values for the scene.
For the second pass, render the scene with z-writes disabled but color writes
and effects enabled. If you have a large number of expensive pixel shaders this could be the way to go.

Blue*Omega
Blue*Omega
Quote:
Original post by Agony
But each layer contains 3-dimensional objects, I'm assuming. If each layer merely contained flat sprites, sure, it'd be no problem.


Correct. I do have the option to use flat sprites, but we're assuming 90%+ of the resources are going to be 3D.

Quote:
Original post by d_emmanuel
You might want to look into doing a "lay down z pass".


Doesn't Doom 3 do this? Could be a good solution. Of course, 1 pass is always better than 2, but if the first pass is nothing but depth values it would go pretty fast. I like this idea!

Any others, keep 'em coming!

Drilian
Drilian
Could you use the stencil buffer? I know you kinda mentioned it in your post and how you'd like to find a better way, but it really would be, I think, the most efficient way to do what you're talking about.

Clear stencil
Render front layer into depth/stencil/color buffer

then, after the first layer, make sure to only draw where the stencil buffer has not been drawn to.

Each subsequent layer would have to, essentially:

1. Clear Z buffer
2. Draw layer
3. Draw to stencil buffer (no Z buffering or color writes)

lather, rinse, repeat.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.