Skip to main content
gamedev.net
🔒 Locked

Declare Depth Buffer function

Started by Viper173 8 replies 1.8k views
Original Post
Viper173
Viper173
Is there a way to tell opengl how to use its depth buffer? I dont mean glDepthFunc but a function that would specify a way how Opengl stores pixel in the buffer. I dont want OGL to waste that much precision in the front. I think multi pass rendering, using glDepthRange and sorting your objects on your own isn't such a comfortable way to do this. I had this question a couple of weeks ago, but I didn't get far. I'm busy enough to draw things in order so that blending works correctly. I dont wanna sort objects because of depth testing again. 24 or 32 bits should be enough to draw whatever you want, don't you think? Is there a way to satisfy my lazy character?
zedzeek
zedzeek
with shaders i believe u can write whatever value u want to the depthchannel, (beware it might cause a bit of a slowdown though).

normally a 24bit depthbuffer should be enuf, r u seeing zfighting in your scene?
if so what near + far z values are u using
DANNER
DANNER
You generally don't want to mess around with optimizing based on the depth buffer. Most hardware has some sort of optimized Z algorithm (Hierarcical Z, Z compression, Fast Z Clears, etc.) which cannot be used if you're doing somethign tricky like reverze Z with glDepthRange.

As zedzeek said, you can output Z in a pixel shader to do something interesting, but again, the hardware cannot use it's optimized algortim when you do this.

IMO, If you thought of something really really clever that fit your needs, you *might* outsmart the hardware algorthims, but this is much more pain than it's worth.
Viper173
Viper173
You mean there is absolutely no way to draw objects normally in your DRAW procedure, without messing around with draw order or even pixel shaders. hmm, pretty disappoiting!
I wanted to use a single call to gluperspective and then declare a range from 5 to maybe 1 billion or even more. As I use it now planets start flickering just a bit in the distance.

grrr, that I dont understand! I mean why does it have to be such a pain to draw astronomical scenes in OpenGL?

I guess I just leave it the way it is then. I would be happy to give up some of my precision in the front in order to draw things correctly in the distance but it seems that this solution is not worth the efford..thanx though
DANNER
DANNER
Quote:
Original post by Viper173
You mean there is absolutely no way to draw objects normally in your DRAW procedure, without messing around with draw order or even pixel shaders. hmm, pretty disappoiting!
I wanted to use a single call to gluperspective and then declare a range from 5 to maybe 1 billion or even more. As I use it now planets start flickering just a bit in the distance.

I didn't realize you were seeing flickering in your scene. I though you just wanted more flexibility to use the depth buffer.

You shouldn't need to perform your own depth sorting with a 24 bit depth buffer. What is your zNear / zFar value set to? If zNear is too small or zFar is too big, z fighting is pretty common. Usually Z Near value that is too small is the culprit so play with it first by making it bigger.
haphazardlynamed
haphazardlynamed
if youre already sorting stuff for blending
why not draw in back to front order for depth as well?
it should be the same ordering unless youre doing somthing really wierd for blending
Viper173
Viper173
well, I wouldn't call it flickering...
just a little noisy on the edges.

actually... I just enabled AA and it's pretty much gone.
wow, it goes up to
gluPerspective(70, 1024/768{Width/Height}, 2, 10000000)
without flickering, then it starts..
randomname
randomname
Quote:
Original post by Viper173
gluPerspective(70, 1024/768{Width/Height}, 2, 10000000)
1024/768=1! Use 1024.0/768.0 instead (or typecast to float before dividing) to be on the safe side.
Ubik
Ubik
I noticed, that you set the near z plane to 2. You could mak it bigger, because now you have the high precision relatively near camera. When you push the near plane farther, the precision is "spreads" to the range you are using.

I am assuming that you are using really large scale that shows an solar system, but no spaceships or anything "smallish" that you would position near the camera. (On a spaceship-scale the nearest planets, exluding the one the ship might orbit, would appear as brighter stars.)
zedzeek
zedzeek
u can use 2 (or more) depth ranges eg
glDepthRange(0,0.5)
gluPerspective(90,1,2,10000);

draw near stuuf

glDepthRange(0,5,1.0)
gluPerspective(90,1,10000,100000000);

draw far stuff

Topic Locked

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

Sign in to reply to this topic.