Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I render five boxes in WebGL with one texture for all of them, the app runs at 60 FPS, nice. But when I render 70 boxes the performance decreases to ~40fps... but only 5 of the boxes are visible.

I have debugged the app and all 70 boxes are using per fragment shaders when there is no need because 65 of them are out of frustum. I thought that setting the GL viewport clipped out-of-view polygons, but apparently not.

I would like to know if I can use frustum culling techniques to avoid this? How can I activate frustum culling? Is there any WebGL command or I have to do it manually?

Thanks in advance,

share|improve this question
Fully-clipped-away primitives shouldn't get processed by fragment shaders. How are you determining that the shaders for the out-of-view objects still run? Are you sure they are out of view? – Josh Petrie Jul 7 '11 at 15:56
Also, welcome to the site. – Josh Petrie Jul 7 '11 at 15:56
Thanks for the welcome. Iam wrong the 70 boxes are clipped before per fragment shader, because they are out of the viewport. But, 20 fps of overhead! Isn't it too much just for 70 boxes? – JoniPichoni Jul 7 '11 at 16:06
up vote 1 down vote accepted

Remember that FPS is not a great metric for performance: it's not a linear measure. 60 FPS is ~0.016 seconds per frame, whereas 40 FPS is 0.025 seconds per frame. That's a different of only 0.009 seconds for fourteen times as much render throughput. Timing rendering (which executes on the GPU) is not as straightforward as timing CPU operations. See this guide, which covers D3D specifically, but explores some concept that will apply to GL as well.

60 FPS for almost no objects sounds like you have v-sync enabled. In that scenario, you don't need too much more stuff to be rendered before you can hit a threshold where you have to block for a while waiting for the (modern equivalent of the) vertical blank interrupt before you can continue. This can make your FPS appear to drop dramatically. If you disable v-sync you may notice a much less severe drop.

All that being said, all the GPU will do for you is clip triangles outside of the viewport. It will not do frustum culling for you, which means every bit of geometry you submit will make it all the way through the vertex transformation pipeline into clip space at the least. The fragment shader should not run on primitives that have been clipped out.

If you implement frustum culling yourself (the API will not do it for you), you can boost your performance in general by not having to even submit out-of-view geometry to the card.

share|improve this answer
Good point about FPS. At a certain point complex CPU calculations for culling can be more expensive than just sending the polys anyway. If you are just sending cubes, you could also try instancing, though I guess you're performing more of a stress-test. – Jonathan Connell Jul 7 '11 at 16:06
First of all, thakns for the response, very usefull. But as I said on the other comment, 20fps of penalty, isn't it too much just for clipping those boxes? – JoniPichoni Jul 7 '11 at 16:10
No. First of all, as I noted, 20 FPS here is 0.009 seconds. Second, because you appear to have v-sync on, you're probably actually trying to render much faster than that, but are ending up just slightly out of phase with the vertical blank, which results in your tending to be blocked more frequently than you strictly need to be to complete your rendering. – Josh Petrie Jul 7 '11 at 16:13
Thanks very much. Last question, how can I have vsync off in webgl? isnt it window manager dependent? or should I call glFlush to render all the FBO to the device? – JoniPichoni Jul 7 '11 at 16:34
You should post a new actual question to get that answered. You'll get more visibility on it that way. – Josh Petrie Jul 7 '11 at 16:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.