Author Topic: Bounding Spheres: Efficient Frustum Culling  (Read 7410 times)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 523
Bounding Spheres: Efficient Frustum Culling
« on: March 14, 2016, 12:02:38 pm »
OpenGL has a glFrustum() function to restrict (clip) forcibly its graphical output to within a given volume in the virtual 3D space. Auxiliary functions gluPerspective() and gluLookAt() used in both ObjReader and Objector utilize this function intrinsically so that there's no need to call it directly in the source code of both renderers. Any graphical output outside the six planes of current frustum isn't drawn in the OpenGL canvas.

However the clipping functionality of a modern OpenGL implementation belongs to the rasterization stage of its pipeline (bright blue box below), i.e. is implemented well past the programmatically accessible vertex and fragment processing stages. It effectively means that vertex/pixel group (mesh) data is processed regardless of the group's actual final visibility, which stresses OpenGL computationally, and especially so, at extreme closeups within large OpenGL canvases and in the full screen mode.

Note that the immediate mode/FFP functionality in a modern OpenGL driver is entirely emulated by its predefined, built-in programmable pipeline procedures so that everything that's been said above pertains not only to GLSL shading but also to those more obscure historical modes of operation.

That said, it would seem reasonable to introduce some sort of a simple early rejection test to avoid passing invisible mesh data to the render procedure altogether. This is where mesh bounding spheres can step in to the rescue again. The simplest test is to check if the mesh bounding sphere lies entirely outside at least one of the six planes that form up the current view frustum, in which case the mesh may be safely excluded from the batch of meshes to be rendered in the current frame thus totally avoiding the overhead of extra computation of visual data that will never be seen on the screen.

This is exactly what the attached ObjReader64 source code does. In such models like the Sponza Attrium where each piece of cloth, or vase, or plant, or sculpture is a separate mesh regardless of its actual material, the test helps skip the rendering of up to 40% and more of the meshes that can't be seen at the camera's current orientation because they are behind the viewer's back or too far beyond the sides of the current viewport (frustum).


(Please merge my mods with your current sources and also let me know if you have made any significant changes to the sources since our latest merger a few months ago.)
« Last Edit: March 15, 2016, 02:55:00 pm by Michael Lobko-Lobanovsky »
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 523
Re: Bounding Spheres: Efficient Frustum Culling
« Reply #1 on: March 18, 2016, 04:10:40 pm »
OK Patrice,

Now I understand your motivation regarding the PB code. Then just let's have it your way in OR32 (it works for me too) but let's leave the C++ version the way it originally was. C++ creates the grm_frustum[][] array at app load time before any code starts to actually execute, and this is exactly what we need to have it fully defined in the program at all times.

As for the .MAX files, please don't hesitate to ask me for the conversion whenever you need it. I have access to 3DS Max 2016 and I can convert such files directly to .OBJ and .FBX (in any fbx syntax starting with FBX 2010 and up), and I can also convert huge modern .LWS and .LWO files to .FBX and Collada that are also likely to be reliably readable with your C4D software.

(I can't however convert any C4D files to anything else as there seems to be no 3rd-party software that's able to read modern C4D files without a Cinema4D package installed on one's computer ;) )
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 523
Re: Bounding Spheres: Efficient Frustum Culling
« Reply #2 on: March 19, 2016, 06:12:56 am »
Thanks for the header, Patrice! Now everything seems to compile just fine. :)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)

Michael Lobko-Lobanovsky

  • Administrator
  • *****
  • Posts: 523
Re: Bounding Spheres: Efficient Frustum Culling
« Reply #3 on: March 19, 2016, 04:20:08 pm »
Where did you got this star base?

Here :)

(sborka is the Russian for assembly. the nice thing is it introduces the concept of skydome -- something you haven't been using in your models yet.)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, Windows 7 Ultimate Sp1)