Papervision 3D programming tutorials - Clipping & Culling

Posted Mar 01, 2009 by mcasperson / comments 2 comments / Print / Font Size Decrease font size Increase font size

See how to use Papervisions clipping and culling options to improve performance and visual integrity. Demo and source code included.

VIEW THE DEMO
DOWNLOAD THE CODE

In this post I will be looking at two concepts in Papervision: culling and clipping. They are easy to confuse, but both have very important roles.

Culling is the process whereby objects that are not seen by the camera are removed from the rendering pipeline, meaning less polygons for the Papervision engine to have to process.

Clipping is where polygons that extend past the camera are culled, leading to polygons that are still visible (because only part of it is past the cameras view) disappear.

Triangle count without culling is 1000

The scene we have created as a test is simply a number of cubes that surround the camera. Without culling enabled Papervision has to deal with 1000+ triangles (you can see this in the CTr value in the stats counter). When we enable the camera frustum culling by checking the appropriate option box this value drops to around 100.

On my system this drop in triangle count didn't lead to any noticeable increase in performance. So what's the point? Now enable clipping as well as culling. The effects of clipping won't be immediately obvious at this point, but if your PC responds anything like mine you will not see any performance degradation with both options enabled. However with clipping enabled and culling disabled the frame drops significantly.

Clipping frame rate without culling is significanlty lower

The reason for this is that Papervision won't clip an object that has been culled, and because clipping is such an expensive operation culling a significant percentage of the objects before the clipping calculations have to be done allows for a very noticeable performance increase.

So now that we have see the benefits of culling, let's take a look at what clipping actually does. Disable clipping and culling, and tick the options that says "Surrounding blue box visible". This will show a large cube that surrounds the scene. However you will notice that the "walls" of the this cube disappear as the camera rotates. Because the walls of the cube are so large the system determines that they leave the view of the camera when in fact part of them is still visible. This is a fairly extreme example of this sort of problem (and indeed all you would need to do to fix the problem without using clipping is to create a cube with a few more segments making up the sides), but it does demonstrate the effect well.

Without clipping the walls of the blue cube disappear

Now enable clipping. See now how the walls are rendered as you would expect. Clipping slices up the polygons that leave the cameras view so they don't disappear. You'll also see that extra triangles have been created in the process (the walls have a wireframe texture, so the solid lines show the edges of the triangles) - this is one of the performance downsides to clipping.

Clipping fixes up the disappearing walls, but at the cost of creating new triangles

Now tick all three options. We are back to having the walls of the blue cube disappearing. While culling and clipping can be used together, in some situations they don't work - like this one.

Go back to Papervision Tutorials

Rate this Article:

Be the first to rate me.

  • Nothing Found!

    Why not submit your own content? Signup here.


* You must be logged in order to leave comments, please login or join us.

Comments

adrenalin
adrenalin said... on May 27th, 2009 at 2:10 PM

Hellow!
Please look at http://www.vse62.ru/1.swf
it contains one complex object. i see disapearing triangles there.
i’m use Frustum Clipping, but it’s not help me.
there’s few lines of code

          private function init3D():void
          {
                viewport = new Viewport3D(0, 0, true, false);
                addChild(viewport);
                renderer = new BasicRenderEngine();
                scene = new Scene3D();
                camera = new Camera3D();
                camera.x = camera.y = camera.z = 0;
                camera.useCulling = true;
                renderer.clipping = new FrustumClipping(FrustumClipping.ALL);

                camera.focus = 50;
                camera.zoom = 30;               
                camera.z = -200;
                m1.smooth = true;
                torus1 = new MyObject(m1);
                torus1.useClipping = true;
                //torus1.material.doubleSided = true;
                //torus = new BlenderTorus(new BitmapFileMaterial(“torustexture.png”));           
         
                torus1.scale = 1;
               
                scene.addChild(torus1);           
               
                camera.lookAt(torus1);
          }

JohnMayers
JohnMayers said... on April 3rd, 2009 at 10:39 AM

hi,

thanks for the tutorial, very helpful.

I’m afraid the source files are not the right ones, I would love to
see the source though,

thanks,

John



Bookmark and Share
Sign up for our email newsletter
Name:
Email: