Sign in to follow this  
openglaussie

OpenGL occlusion culling

Recommended Posts

openglaussie    100
Hi, i am back working on on old idea of mine about occlusion culling , i coded a fast zbuffered-concave/convex-polygon-with-holes function ,and i was proceeding with the next step. My biggest concern is about transforming vertices, i am going to do the job twice, opengl renders its own buffer, while in software the code basically do the same. Now i was thinking about this, since i need the normals for the zbuffer,an algorithm might work in this way. I consider the whole world fixed , and i move the observer in the opposite view direction , its just like in the real world the observer rotates and moves, the rest of the world stays fixed, opposing to what normally happens with opengl or directx. Now i think i am going to need a matrix derived from quaternions. Has anyone done the same thing , or is just a stupid idea ? Is there any way to avoid recompunting twice the vertices(sp??) Thanks and sorry for my english.

Share this post


Link to post
Share on other sites
Zemedelec    229
If your culling is done on CPU, then of course you need to transform the occluders and ocludees on the CPU as well.
But they must be very low-poly, since you don't wanna do only occlusion, right?

Share this post


Link to post
Share on other sites
nts    968
Quote:
Original post by Joshua Klint
There's not much reason to do any culling other than frustum culling.
Not true.

When doing occlusion culling on the CPU don't test with the same geometry you are rendering. Use a very low poly version or better yet use a bounding box or AABB. Using an AABB you can cut the transformations down to two vertices (min and max for AABB).

Share this post


Link to post
Share on other sites
Zemedelec    229
Quote:
Original post by Joshua Klint
There's not much reason to do any culling other than frustum culling.


Very untrue. For every single scene, with high geometric complexity, overdraw and occluded objects there is two things one can do to save GPU computing power for a better picture - transfer it from the distant scene to the front via LOD, or remove it from hidden and not visible part of the scene via occlusion culling.
In the end, it almost always saves GPU cycles that can be spent somewhere else. Even for higher FPS...

Share this post


Link to post
Share on other sites
Joshua Klint    109
It depends on what kind of scene it is. If you are rendering an outdoor scene there is very little you can do that won't be a special trick that only works in small demos that have absolutely no practical use.

I think most of the theory on occlusion is hangons from the Quake BSP days, and it's not really in tune with what modern GPUs can do.

For an indoor scene, a good portal system can make a big difference, but I see beginning programmers who want to draw 10,000 polys on the screen worry about occlusion, and it doesn't make sense unless you are really going to be pushing the GPU. Unless you are saving at least maybe 20,000 polys with occlusion, don't even bother.

For all culling, you should use a sphere test. This is the center of the object, with a radius of the furthest vertex from the center. It is not terribly accurate, but can be made to err on the side of caution. Anything more complicated than that and you will just slow your app down, unless you are running a quad core CPU with a TNT2 GPU.

Share this post


Link to post
Share on other sites
Hodgman    51234
Quote:
Original post by Joshua Klint
It depends on what kind of scene it is. If you are rendering an outdoor scene there is very little you can do that won't be a special trick that only works in small demos that have absolutely no practical use.

Still very untrue. There's been a lot of work done on outdoor occlusion, and there are a lot of practical techniques you can use.

Valve's Source engine uses "occluder frustums" similar to the ones in this article for outdoor scenes.
It might be a special trick, but it definitely has practical use.

Also: Quad-trees/Oct-trees still receive wide-spread use in outdoor visibility culling, and even precomputed-PVS techniques are still being used...

Share this post


Link to post
Share on other sites
Yann L    1802
Quote:
Original post by Joshua Klint
It depends on what kind of scene it is. If you are rendering an outdoor scene there is very little you can do that won't be a special trick that only works in small demos that have absolutely no practical use.

Incorrect. Although not as effective as in indoor scenes, occlusion culling can still have a huge impact on outdoor scenes. Especially if they're densly populated (bumpy terrain, vegetation, buildings, etc).

Quote:
Original post by Joshua Klint
I think most of the theory on occlusion is hangons from the Quake BSP days, and it's not really in tune with what modern GPUs can do.

I think you don't understand what occlusion culling (according to the modern definition) actually is :) It has strictly nothing to do with BSPs and co, and was never used in Quake. You might be confusing it with PVS, which is indeed a little outdated (a least in the way it was done in Quake). But modern occlusion culling is something completely different than BSP/PVS.

Quote:
Original post by Joshua Klint
For an indoor scene, a good portal system can make a big difference,

Sure it can, but is restricted to a certain type of geometry. In fact, portal rendering is a special type of occlusion culling. More general forms of OC, such as HOM or hardware OC with conditional rendering, can entirely replace a portal system. They're both more effective than portals can ever be (by definition), and can handle all types of scenes without specific requirements such as imposed by portals.

Quote:
Original post by Joshua Klint
but I see beginning programmers who want to draw 10,000 polys on the screen worry about occlusion, and it doesn't make sense unless you are really going to be pushing the GPU. Unless you are saving at least maybe 20,000 polys with occlusion, don't even bother.

That is true, however OC is a vital part of an engine if you increase the poly load over a certain limit, and if you have scenes with high depth complexity. So it is only natural that beginners should learn about it. Especially since hardware support for OC is increasing.

Quote:
Original post by Joshua Klint
For all culling, you should use a sphere test.

No, you should not.

Quote:
Original post by Joshua Klint
This is the center of the object, with a radius of the furthest vertex from the center. It is not terribly accurate, but can be made to err on the side of caution. Anything more complicated than that and you will just slow your app down, unless you are running a quad core CPU with a TNT2 GPU.

Incorrect again. Do not make assumptions if you clearly do not have the expertise to back it up. Spatial culling is an extremely important part of any modern engine. Culling removing depth complexity (means everything from occlusion culling, over LOD, to distance based procedural simplifications like adaptive displacement mapping) is even more important on todays shader heavy scenes. The quickest geometry is the one you don't render.

Share this post


Link to post
Share on other sites
Joshua Klint    109
All you have done is contradict everything I said. Why don't you lay out a proposal of how you think culling should be handled? Because there are far too many academic opinions on this subject from people who have never actually made anything but a small demo showcasing their idea under extremely controlled conditions.

I have implemented "occluders" as well, but they are only useful in very specific circumstances. Overall I could easily do without them, but I just left them in because I thought they were neat. And yes, the sphere test should be used because you can quickly check to see if it is inside the planes of the occlusion volume, with no transformations required at all.

Outdoor culling is not that important because if you can't render all your geometry fast enough when the player goes up on a hill or something, you're screwed anyways. For static geometry, it is almost always faster to chuck the whole geometry at the GPU, or at least big chunks that can still be frustum-culled.

For dynamic objects, instanced rendering gives you the speed you need. There are not a lot of conditions under which outdoor culling of instanced meshes will provide more frames than it eats up.

Share this post


Link to post
Share on other sites
AndyPandyV2    298
I found GPU occlusion culling worked just fine on my outdoor terrain rendering. Yes, even on top of a hill it is still useful, as some sections of terrain will be overlapping each other in the distance(the big mountains/hills blocking the ones behind them). And if you were to leave the ground and fly up into the sky the terrain would be using a lower LOD anyway. Its fast/cheap and reduces vert count considerably, no reason not to use it.

Share this post


Link to post
Share on other sites
openglaussie    100
Thanks for your input , it gave birth to a new obsession of mine.
Basically i have a way to avoid transforming all the vertices in the scene
and avoiding using a lod for the level itself, it is based around triangle navigation trhough adiacency maps

Share this post


Link to post
Share on other sites
Yann L    1802
Quote:
Original post by Joshua Klint
All you have done is contradict everything I said.

Because pretty much everything you said was incorrect :) What do you expect me to say ?

Quote:
Original post by Joshua Klint
Why don't you lay out a proposal of how you think culling should be handled? Because there are far too many academic opinions on this subject from people who have never actually made anything but a small demo showcasing their idea under extremely controlled conditions.

In short, the two most important aspects in culling (both CPU and GPU side) is the removal of geometry not visible due to camera projection (ie. frustum culling), and the removal of depth complexity. The former should imnperatively use a form of hierarchical spatial structure. While spheres are a possibility, in practice they usually give far worse results than other structures by being overly conservative. The latter is comprised of occlusion culling, level of detail, and other slightly more exotic culling systems. For very simple scenes (< 100k faces), as the one in your engine (from here, brute forcing everything to the GPU is a possibility. But once you go into more advanced rendering, especially with heavy vertex shaders and state change limitations, some form occlusion culling becomes a must have.

If you are interested in more details about how I think it should be handled, I leave it to you as an exercise to dig out the hundreds of threads where I talked about all aspects of spatial structures, dynamic trees, occlusion systems, performance analysis, etc, in the past. That's all i can offer right now, since my current opinion on the matter is covered by several NDAs :)

Quote:
Original post by Joshua Klint
I have implemented "occluders" as well, but they are only useful in very specific circumstances. Overall I could easily do without them, but I just left them in because I thought they were neat.

This is because your scenes are too simple right now for them to be effective. And also, because your implementation of them is probably far from optimal. In my engine, which is used as a part of a high end commercial and military visualization system, and which features several extremely optimized culling systems, occlusion culling can easily remove up to 90% of geometry in a frame. That means going down from over 5 million visible faces per frame to maybe 500k, in many situations. As you can imagine, this gives us a considerable speedup. The same is true for most modern game 3D engines.

Quote:
Original post by Joshua Klint
And yes, the sphere test should be used because you can quickly check to see if it is inside the planes of the occlusion volume, with no transformations required at all.

As I mentioned above, sphere tests are usually sub-par in terms of efficiency.

Quote:
Original post by Joshua Klint
Outdoor culling is not that important because if you can't render all your geometry fast enough when the player goes up on a hill or something, you're screwed anyways. For static geometry, it is almost always faster to chuck the whole geometry at the GPU, or at least big chunks that can still be frustum-culled.

For dynamic objects, instanced rendering gives you the speed you need. There are not a lot of conditions under which outdoor culling of instanced meshes will provide more frames than it eats up.

Those are very bold statements. Even a seasoned professional would think twice about making such generic statements about rendering and GPU performance behaviour. Now don't take this as an offense, but from your previous posts I think we can safely classify you as a intermediate beginner. As such, you don't yet have the experience of correctly assessing the performance characteristics of modern 3D engine design (which is a very complex field). Just because OC didn't give you a speedup, doesn't mean it won't in the general case. Chances are, that your particular implementation was sub-optimal, or your algorithms were not appropriate for your scenes (as you said yourself, you didn't even know about GPU occlusion culling). Many people in this thread have told you that you were wrong - maybe you should listen to people that have more experience than you, and learn from them.

Share this post


Link to post
Share on other sites
Joshua Klint    109
Quote:
If you are interested in more details about how I think it should be handled, I leave it to you as an exercise to dig out the hundreds of threads where I talked about all aspects of spatial structures, dynamic trees, occlusion systems, performance analysis, etc, in the past. That's all i can offer right now, since my current opinion on the matter is covered by several NDAs :)

So I see you don't have a definitive answer, just a lot of smarmy remarks and smily faces. :)

Share this post


Link to post
Share on other sites
Yann L    1802
Quote:
Original post by Joshua Klint
So I see you don't have a definitive answer, just a lot of smarmy remarks and smily faces. :)

I think I have been quite precise. What do you want more ? Source code ? A step by step guide ? Giving you such detailed answers would invalidate my security clearance and violate at least two NDAs (for those who remember that 'ABT incident' some time ago, yeah, they now make me sign multiple NDAs just to be sure *ahem* ;)

As I said, search the forums. Here, let me help you. Besides that, there is no definitive answer to such a question. It all depends on the specifics of your engine, your target hardware, and the type of scenes you are using. There is no magical algorithm that will make everything super-fast, while all other algorithms are unusable. Fact is, spatial and occlusion culling are vital parts of an engine, if you go over a certain face and shader complexity threshold.

The exact threshold cannot be given, because it depends too much on case-specific circumstances. Same is true for the exact algorithms to use - hardware occlusion culling, HOMs, software renderers, and even PVS. All have their place, and the wise selection of an appropriate algorithm is often more important than its implementation details. This can only be achieved by experience. Trial and error. You should also be aware that algorithms not working for you might very well work for others, because the frame conditions are different - more faces, higher geometrical density, more shader and state bound scenarios, etc.

You'll run into that sooner or later, if you carry on with graphics development. But in the meantime, try not to make generalized statements and assumptions without providing facts, because this will only spread incorrect information.

Share this post


Link to post
Share on other sites
glaeken    294
Quote:
Original post by nts

When doing occlusion culling on the CPU don't test with the same geometry you are rendering. Use a very low poly version or better yet use a bounding box or AABB. Using an AABB you can cut the transformations down to two vertices (min and max for AABB).


I've been thinking of coding up a hardware occlusion implementation also. And I had thought to use AABBs instead of the actual geometry. But my question is, wouldn't using AABBs occlude geometry that it shouldn't? If you had a large bounding box - but its model was quite a bit smaller than it's max/min (like a tree trunk for example) - and you had a small object behind this tree but wasn't occluded by the trunk, but was occluded by the tree's AABB, wouldn't this produce artifacts?

Share this post


Link to post
Share on other sites
Yann L    1802
Quote:
Original post by glaeken
I've been thinking of coding up a hardware occlusion implementation also. And I had thought to use AABBs instead of the actual geometry. But my question is, wouldn't using AABBs occlude geometry that it shouldn't? If you had a large bounding box - but its model was quite a bit smaller than it's max/min (like a tree trunk for example) - and you had a small object behind this tree but wasn't occluded by the trunk, but was occluded by the tree's AABB, wouldn't this produce artifacts?

Yes, this will indeed happen. However, you can use approximate geometry for culling, by making sure that it will only be smaller than (or just as large as) the occluder itself. Think of it as an 'interior bounding box'. Often, such a structure will be more complex than a bounding box, though - a conservative interior hull. Special algorithms exist in order to optimally fit such a volume into an object, but they're unfortunately quite complex. An alternative is to manually model them, and attach them to the object. That's what we did in the past, and it worked pretty well.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By povilaslt2
      Hello. I'm Programmer who is in search of 2D game project who preferably uses OpenGL and C++. You can see my projects in GitHub. Project genre doesn't matter (except MMO's :D).
    • By ZeldaFan555
      Hello, My name is Matt. I am a programmer. I mostly use Java, but can use C++ and various other languages. I'm looking for someone to partner up with for random projects, preferably using OpenGL, though I'd be open to just about anything. If you're interested you can contact me on Skype or on here, thank you!
      Skype: Mangodoor408
    • By tyhender
      Hello, my name is Mark. I'm hobby programmer. 
      So recently,I thought that it's good idea to find people to create a full 3D engine. I'm looking for people experienced in scripting 3D shaders and implementing physics into engine(game)(we are going to use the React physics engine). 
      And,ye,no money =D I'm just looking for hobbyists that will be proud of their work. If engine(or game) will have financial succes,well,then maybe =D
      Sorry for late replies.
      I mostly give more information when people PM me,but this post is REALLY short,even for me =D
      So here's few more points:
      Engine will use openGL and SDL for graphics. It will use React3D physics library for physics simulation. Engine(most probably,atleast for the first part) won't have graphical fron-end,it will be a framework . I think final engine should be enough to set up an FPS in a couple of minutes. A bit about my self:
      I've been programming for 7 years total. I learned very slowly it as "secondary interesting thing" for like 3 years, but then began to script more seriously.  My primary language is C++,which we are going to use for the engine. Yes,I did 3D graphics with physics simulation before. No, my portfolio isn't very impressive. I'm working on that No,I wasn't employed officially. If anybody need to know more PM me. 
       
    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
  • Popular Now