OpenGL Distance Optimizations

Member
Posts: 40
Joined: 2008.10
Post: #1
Hello everyone,

Is there any way in OpenGL to make things that are farther away less clear, perhaps to optimize the scene more?

Thanks
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #2
If you use fog, you can filter out your objects which are completely behind the fog plane, and draw them with a very simple shader which outputs fragments in the current fog color -- no texturing, no lighting, etc etc. This has been a win for me.

Another option might be to draw all your distant stuff using simpler shaders into a quarter-resolution FBO, and then run a gaussian blur pass on it (to mitigate pixelation) while blitting it to the screen. This might be a win... either way you'll get a cool cheapo DOF effect.

Or just use really simple shaders and simplified geometry for distant objects.
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
You're talking about levels of detail, presumably? The simple answer is to submit simplified geometry with fewer vertices for objects further from the camera, but there are a gajillion different approaches to actually doing that...
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
Also, if you do switch levels of detail, be it geometric or in terms of shader complexity, you will eithe rhave to accept "popping" as the levels change, or come up with a way to interpolate between levels.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #5
I think fogging works pretty good myself.

Also, I've seen it where distant objects are faded out with distance, instead of disappearing into the fog. That seems to work pretty good too.

Another option might be fading out the geometry and fading in a billboard in place of the object. I've even seen what I believe are animated billboards for very distant animated humans in (I think it was) Delta Force. The effect worked really well.

For geometry LOD, I've seen popping in Halo. It doesn't look as bad as I thought it would. Geometry LOD interpolation between levels seems like a major PITA though, if one were to take it a step further to get rid of the popping.
Quote this message in a reply
Member
Posts: 40
Joined: 2008.10
Post: #6
TomorrowPlusX Wrote:If you use fog, you can filter out your objects which are completely behind the fog plane, and draw them with a very simple shader which outputs fragments in the current fog color -- no texturing, no lighting, etc etc. This has been a win for me.

Another option might be to draw all your distant stuff using simpler shaders into a quarter-resolution FBO, and then run a gaussian blur pass on it (to mitigate pixelation) while blitting it to the screen. This might be a win... either way you'll get a cool cheapo DOF effect.

Or just use really simple shaders and simplified geometry for distant objects.

How would you blit the FBO onto the screen over the nearer objects with depth and all that? Would you just blit the farther objects and then render the nearer objects?


Simplifying the geometry right now does not seem to be an option because I am just using cubes. Unless I used planes in place of the cubes. The fogging sounds good, but just to make sure, if I render them with textures and materials in the fog it will render at the same speed or possibly slower right? Mostly the reason I am asking this is because I am using textured dominoes in a simulation, and the textures seem to be flashing once they get farther away, so I was thinking that if a lower level of detail were used on the farther away objects, they might not be flashing. Of course, that might not be why they were flashing in the first place. Based on this, would fog still be a good choice?
Quote this message in a reply
Member
Posts: 40
Joined: 2008.10
Post: #7
Sorry everyone I found out the solution had nothing to do with distance clarity. For anyone with a similar problem I had to enable back face culling and it worked perfectly.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #8
You should've had culling on anyway.

BTW, what's your depth buffer precision?
Quote this message in a reply
Member
Posts: 40
Joined: 2008.10
Post: #9
I don't know the exact depth buffer precision but my zNear plane is at 0.1, my zFar plane is at 10000, and I have 16 bit color depth.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #10
Color depth doesn't mean anything in the case of the z-buffer, which is why I asked about your depth precision.

The mystery texture flashing you're seeing at distance is likely what we call z-fighting. It's a result of floating point precision not being high enough to be able to correctly decide if a fragment is in front of another or not. This happens as a result of a combination of two things: 1) the precision of your depth buffer and 2) the differential between your near and far planes.

In the case of 1) 24 bits precision is better than 16, so it's important that you know what your depth buffer precision is and how to change it when you see issues like you're seeing.

In the case of 2) 0.1 near to 10k far might be a little steep. You can try lowering that to like 0.1 near and 1k far or maybe even 1.0 near to 1k far. I regularly use 0.1 near and 1k far myself with no issues @24 bit depth.

Finally, turning on backface culling will remove a lot of the visual z-fighting, since logically, if the backface isn't being drawn then its fragments aren't there to fight with the front faces' fragments. This may or may not remove all visible z-fighting, depending on what you're drawing.
Quote this message in a reply
Member
Posts: 40
Joined: 2008.10
Post: #11
How do you change the depth buffer precision?
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #12
merrill541 Wrote:How do you change the depth buffer precision?

What API are you using to set up your OpenGL context? Cocoa, SDL, GLUT, iPhone?
Quote this message in a reply
Member
Posts: 40
Joined: 2008.10
Post: #13
I'm using SDL.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #14
merrill541 Wrote:I'm using SDL.

Pfft.. Figures... that's the one API I can't help you with, sorry Sad You'll either have to consult the docs or wait for someone else to hop along here.
Quote this message in a reply
Member
Posts: 40
Joined: 2008.10
Post: #15
Thanks anyways.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Signed Distance Fields for Alpha Tested Magnification of Vector Textures maximile 2 6,026 Mar 29, 2010 10:59 AM
Last Post: Skorche
  Point distance attenuation with OGL-extension - how? mcMike 6 5,804 May 21, 2008 10:58 PM
Last Post: mcMike