Sign in to follow this  
openglaussie

OpenGL occlusion culling

Recommended Posts

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
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
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
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
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
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
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
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
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
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
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
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
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
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
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  

  • Partner Spotlight

  • Forum Statistics

    • Total Topics
      627646
    • Total Posts
      2978381
  • Similar Content

    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
    • By cebugdev
      hi guys, 
      are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
      Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic 
      let me know if you guys have recommendations.
      Thank you in advance!
    • By dud3
      How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below? 
      Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
      Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.
       
      References:
      Code: https://pastebin.com/Hcshj3FQ
      The video shows the difference between blender and my rotation:
       
    • By Defend
      I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
      My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
      * make lots of VAO/VBO pairs and flip through them to render different objects, or
      * make one big VBO and jump around its memory to render different objects. 
      I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
      If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?
       
    • By test opty
      Hello all,
       
      On my Windows 7 x64 machine I wrote the code below on VS 2017 and ran it.
      #include <glad/glad.h>  #include <GLFW/glfw3.h> #include <std_lib_facilities_4.h> using namespace std; void framebuffer_size_callback(GLFWwindow* window , int width, int height) {     glViewport(0, 0, width, height); } //****************************** void processInput(GLFWwindow* window) {     if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)         glfwSetWindowShouldClose(window, true); } //********************************* int main() {     glfwInit();     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);     //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);     GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", nullptr, nullptr);     if (window == nullptr)     {         cout << "Failed to create GLFW window" << endl;         glfwTerminate();         return -1;     }     glfwMakeContextCurrent(window);     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))     {         cout << "Failed to initialize GLAD" << endl;         return -1;     }     glViewport(0, 0, 600, 480);     glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);     glClearColor(0.2f, 0.3f, 0.3f, 1.0f);     glClear(GL_COLOR_BUFFER_BIT);     while (!glfwWindowShouldClose(window))     {         processInput(window);         glfwSwapBuffers(window);         glfwPollEvents();     }     glfwTerminate();     return 0; }  
      The result should be a fixed dark green-blueish color as the end of here. But the color of my window turns from black to green-blueish repeatedly in high speed! I thought it might be a problem with my Graphics card driver but I've updated it and it's: NVIDIA GeForce GTX 750 Ti.
      What is the problem and how to solve it please?
  • Popular Now