Jump to content
  • Advertisement
Sign in to follow this  
Raziel1984

OpenGL How to avoid drawing triangles that are outsid the viewport?

This topic is 2978 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everybody,
I have a technical question for the experts in here:

I am developing an OpenGL application for iPhone using openGL 1.x .
When i render a big item on the device it become obviously slower and that's seem quite normal to me.
But i would have expected an increase of framerate when the object is highly zoomed in as the majority of the vertexes are outside the viewport's bounds.

I also try with glEnable(GL_SCISSOR_TEST)/glScissor(0,0,320,480) but the result is always the same?
This is really driving me crazy!

Why the not shown triangles are always computed(or why the speed remain the same while drawing a smaller portion of the object)?
There is a way to avoid this and subsequently increase the framerate?

Thank you in advance.
Greetings.

Peppe.

Share this post


Link to post
Share on other sites
Advertisement
OpenGL still needs to at the very least run the vertexes through the modelview and projection matrixes before it can determine whether or not they're outside the view frustum. I don't know the internal details fully, but I would expect that there are then 3 cases: fast accept (triangle is fully inside the view frustum), fast reject (triangle is fully outside the view frustum) or a third case where the triangle intersects the view frustum and it needs to go down to per-fragment testing. Older drivers might not even be able to fast accept or fast reject entire triangles. There is also vertex submission overhead on top of this; if your scene has 30,000 triangles in it, every one of them must be submitted, processed and tested by OpenGL before it can decide to accept or reject.

Running your own frustum culling in software in advance of this has traditionally been the solution. The idea is that you check on groups of triangles rather than individual ones. So if you have 300 triangles in a model, you run your own test on the entire model and just don't add it to your draw list if it fails.

There are plenty of articles on frustum culling on the web, and "bounding box" or "bounding sphere" are also good search keywords. Here's a reasonable place to start: http://www.lighthouse3d.com/opengl/viewfrustum/

Share this post


Link to post
Share on other sites
Frustum culling an entire object is a good idea. I compute each object's bounding sphere offline. You might also need to optimize your glDrawElements call by optimizing for the pre and post transform cache. There is a discussion about this in the OpenGL.org forum, in the advanced section.

Warning : it is 4 pages long!
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=257252#Post257252

Share this post


Link to post
Share on other sites
Thank you all for your replies,.
So, if I catch it, using scissor test on the entire screen drives to even worse performance because I will do the check twice.
Am I right?

I will try to implement the frustum culling using bounding box.
Thank you again for your support.

Share this post


Link to post
Share on other sites
Hi,

Consider that in most cases when people talk about frustrum culling they're talking about culling on a per-object basis. What you want is to cull triangles
from being sent to the rendering pipeline that are part of the same object.

Now, there are methods to do that but I guess not every engine needs those. The
easiest is to subdivide the triangles to groups, partitioning them.

In many cases its done with a bounding volume hierarchy but that's not the only option available to you. Even a small grid or AABBs or spheres may do the job
nicely if you can get away with something simple.

Share this post


Link to post
Share on other sites
My object are divided into bodies, and each body is divided into faces.
Each body and face have their own BoundingBox that i previously use for Ray-intersecting purpose.
I will now use these boxes to implement a simpe frustum culling.
What do you think?

Share this post


Link to post
Share on other sites
Are you certain you are vertex bound and not fill rate bound?

If you are the latter then all the offscreen triangle culling in the world won't help you out...
(which could well be the case given you experiance no speed up when zooming into the object)

Share this post


Link to post
Share on other sites
The first attemp to implement a frustum culling gave me quite good result(still working on it).
Now i was wondering how to reduce the number of triangles when the objcect is really zoomed out( the inverse problem).
I was thinking to hide faces that have thier bounding box diagonal smaller than a pixel.

This way when the object is fully visibile(not zoomed) all face pass the frustum test but a lot are discarded by the "Diagonal test",when the object is very zoommed all face pass the "Diagonal test" but very few the frustum one.

What do you thing?

Share this post


Link to post
Share on other sites
Just using a lower detailed mesh and using it beyond a certain range is probably the simplest way to start. Memory is cheap and plentiful, and is a resource to be used, so go ahead and use it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!