Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Trouble with frustum culling (Video included)  (Read 2523 times)
0 Members and 1 Guest are viewing this topic.
Offline 64kps

Junior Newbie

« Posted 2012-02-13 10:36:57 »

Hello Smiley

(I did already post this at, but since I know there are some OpenGL genii here, I thought I would ask you guys. I hope it's not too offensive Smiley)

I'm working on an OpenGL application and I'm having trouble with my objects being clipped undesirably by frustum culling

The scene consists of a number of objects on an invisible plane. You can pan around by left clicking and dragging on the invisible plane (This does not translate the plane, it translates the camera). You can rotate the invisible plane by right clicking and dragging (This rotates the plane).

The problem comes when you rotate the plane and then pan so that the objects pass through the far plane of the frustum.

I would like my objects to never get clipped, no matter how far back you push them.

I'm currently using a constant frustum defined by

frustum.left = -1.0;
frustum.right = 1.0; = 1.0;
frustum.bottom = -1.0;
frustum.near = 5.0;
frustum.far = 500.0;

but I was thinking perhaps I could update the projection matrix and frustum every frame, ensuring that the near plane touches the front of the bounding box of my objects and the far plane touches the back of the bounding box of my objects.

Does anyone have any advice which could help me get rid of this unwanted clipping?

Please see accompanying video which visually describes the problem here:

Offline Danny02
« Reply #1 - Posted 2012-02-13 10:52:53 »

calculating the near and far plane each frame would be the easiest way to do it for you.
When one need an extreme view distance then there is also the possibility to do logarithmic depth, but you won't need this for such a small example
Offline theagentd

« JGO Bitwise Duke »

Medals: 594
Projects: 4
Exp: 8 years

« Reply #2 - Posted 2012-02-13 12:54:36 »

You can't have your far plane infinitely far away, since that would require infinite precision in your Z-buffer. The higher the ratio is between the near and far plane, the lower the precision you get. With recalculated near and far planes, in a worst case scenario you'd have some objects nearby and some objects far away, in which case the precision would be incredibly bad for both nearby and far away objects, and you could possible experience a terrible artifact known as z-fighting, in which case objects that are overlapping start to bleed through each other.

Another option is to use a multi-pass technique. For example, you can have 2 passes, one which draws stuff between 1.0 and 500.0, and another that draws stuff from 500.0 to 250 000. You can then draw each pass starting with the furthest one, so we draw all stuff between 500.0 and 250 000 first. Then we clear the depth buffer again, change the projection matrix and draw the stuff inside the next frustum. By doing frustum culling on the CPU only objects which intersect both frustums have to be drawn twice.
PS: I'm not exactly sure if the example values I provided are appropriate, it was just to explain what I meant.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 64kps

Junior Newbie

« Reply #3 - Posted 2012-02-13 15:54:09 »

Cool. Fitting the frustum to the bounding box of the objects seems to have worked well Smiley


   matrix =;
   boundingBox = this.createBoundingBox(this.things, matrix);
   originalSettings = {left: -1.0, right: 1.0, top: 1.0, bottom: -1.0, near: 5.0};
   newSettings = {};

   angle = Math.atan(originalSettings.right / originalSettings.near);
   buffer = 1.0;
   newSettings.near   = Math.max(-boundingBox.maxCoords.z, 2.0) - buffer;
   newSettings.far    = Math.max(-boundingBox.minCoords.z, 2.0) + buffer;
   newSettings.left   = -newSettings.near * Math.tan(angle);
   newSettings.right  = newSettings.near * Math.tan(angle);
   newSettings.bottom = -newSettings.near * Math.tan(angle);    = newSettings.near * Math.tan(angle);
   aspectRatio = this.glViewportWidth / this.glViewportHeight;
   if (aspectRatio > 1.0) {
      newSettings.left *= aspectRatio;
      newSettings.right *= aspectRatio;
   } else {
      newSettings.bottom /= aspectRatio; /= aspectRatio;
   this.frustum.near   = newSettings.near;
   this.frustum.far    = newSettings.far;
   this.frustum.left   = newSettings.left;
   this.frustum.right  = newSettings.right;
   this.frustum.bottom = newSettings.bottom;    =;
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (71 views)
2015-11-07 13:29:08

Rems19 (81 views)
2015-10-31 01:36:56

Rems19 (74 views)
2015-10-31 01:32:37

williamwoles (106 views)
2015-10-23 10:42:59

williamwoles (92 views)
2015-10-23 10:42:45

Jervac_ (106 views)
2015-10-18 23:29:12

DarkCart (134 views)
2015-10-16 00:58:11

KaiHH (116 views)
2015-10-11 14:10:14

KaiHH (156 views)
2015-10-11 13:26:18

BurntPizza (171 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!