<<

Ecient View Frustum Culling

Daniel Skora Josef Jelnek

sykoradfelcvutcz jelinejfelcvutcz

Department of Computer Science

Faculty of Electrical Engineering

Czech Technical University

Prague Czech Republic

Abstract

We have implemented ecient algorithms for view frustum culling introduced in the article Optimized

View Frustum Cul ling Algorithms for Bounding Boxes by Ulf Assarson and Thomas Moller

We measure and evaluate the eciency of selected sp eedup techniques used in static and dynamic scenes

Keywords view frustum culling b ounding volumes scene hierarchy

Introduction

The main idea how to make VFC ecient was invented by Clark who used scene hierarchy

Slater and Chrysanthou developed VFC probabilistic caching scheme which is signicantly faster but

in some cases pro duces unacceptable errors Lots of improvements based on traversal coherency of the

scene hierarchy were also presented by Bittner and Havran in

We have examined the article Optimized View Frustum Cul ling Algorithms for Bounding Boxes

and also the following technical rep ort by the same authors Optimized View Frustum Cul ling Algorithms

which presents generalized and detailed parts of the basic article

In this section we will describ e briey the main novel ideas of optimization metho ds that Assarson

and Moller introduced in The following explanation is also used as the basic information ab out our

implementation of the presented metho ds We will also include a detailed description critical comments

and remarks ab out changes in our implementation The presentation of the abilities of our application

will take place in Section including the discussion ab out the results in Section and

Motivation and results in

The main goal was to sp eedup the elimination of the invisible ob jects in complex scenes from the

rendering pip eline This part of co de may not b e crucial in most cases but its sp eeding up will help

esp ecially in huge scenes

Moreover the general metho ds the authors of present also sp eedup techniques which use low

degree of freedom of the camera motion in the userdriven walkthrough the scene This is signicant

for well known D computer games driven by a player from his own p oint of view

All metho ds are indep endent each other It is p ossible to determine standalone success in compar

ison with another VFC algorithms Moller et al used the VFC algorithms of DirectModel DirectModel

Specication Hewlett Packard and CosmoD CosmoD programmers guide Silicon Graphics Inc

as a measure ethalon for establishing presented sp eedups

All measurements were p erformed for several types of b ounding volumes and their hierarchy in

scenes consisting of ab out thousands of p olygons They provide a solution which is times faster

than DirectModel a system that uses the axes aligned b ounding b oxes hierarchy and times faster

than CosmoD with the hierarchy of b ounding spheres

Camera b ounding volumes and hierarchy

We could reduce the whole problem of elimination of invisible ob jects to the test of the collision of

two volume ob jects the visible volume of a camera also known as the viewing frustum and the b ounding

volume of the current ob ject

The visible volume of the camera is represented by six planes Two of them near and far are

parallel The other four are connected in one p oint of space that represents the viewp oint They inclined

a spatial angle that represents the FOV eld of view of camera The far plane b ounds visibility of far

ob jects in space The near plane determines the distance of the viewp ort from the viewp oint

Moller et al sp ecify the VF viewing frustum as an axes symmetrical quadrilateral frustum Often

the reduced versions of the viewing frustum without the far plane and sometimes without the near plane

are used in practice The near plane of VF could b e changed to the spherical surface in cases when we

need to render ob jects in a panoramatic pro jection

The most commonly used b ounding volumes for the VFC are already mentioned AABBs and spheres

but also the OBB oriented bounding box or the kDOP discrete oriented polytope The volume

of the ob ject in prop ortion to the volume of its b ounding solid determines the conservativity of the

elimination algorithm The closer are the volumes the harder is the implementation of such a VFC

algorithm The VFC algorithm based on b ounding spheres is simple and fast That is the reason for no

really signicant sp eedup improvements as is shown on the results in

The most commonly used structure that is go o d compromise b etween the tighttting kDOPs

and conservative spheres is the AABB The imp ortant prop erty of the AABB is aligning to the world

co ordinates In contrast to the OBB that is transformed by the same matrix as the vertices of the

b ounded volume many transformations can b e removed in the case of AABB Still there is need to

transform the AABB if the ob ject rotates Go o d compromise for this case can b e a combined hierarchy

of the b ounding b oxes There are the OBBs in leafs of the oriented acyclic graph of the scene from

which the AABBs on the higher levels of the hierarchy can b e easily computed only by a transformation

and by nding the b ounds of the eight vertices set

Clark shown that the scene hierarchy is really imp ortant data structure that helps sp eeding up

the VFC signicantly Moller et al obtain the b est results for sp eeding up the eliminating phase with

the hierarchy of the AABB The more complex hierarchy with the kDOP elements was not used by the

authors but most of the optimization ideas can b e used even for these complex structures

There should b e noted that the authors did not describ e the way how the AABB hierarchy was

created its implementation how and how often they refreshed the dimensions of the b ounding volumes

whether the scenes consisted of some animated solids etc

Basic VFC algorithm

Although Moller et al mentioned the system with VFC algorithm that they used as the base for

the comparison but they did not give any further details They only stated that DirectModel uses the

general test of the collision of two AABBs There was not mentioned its conservativity only the way

how to convert the test of the axes aligned b ox to the quadrilateral frustum

VF VF’ VF’

AABB AABB’ AABB’’

Figure Transformation of the AABB and VF to AABBs

The entire pro cedure is in Figure The AABB and the VF is transformed by the p ersp ective

transformation that reduces the VF to a b ox This transformation needs multiplications The new

AABB is constructed around the original VF The collision detector is applied on this couple and can

b e realized by the six comparisons

An imp ortant feature of the basic algorithm is its conservativity in the sense of the detection of the

state where the b ounding volume intersects the visibility volume of the camera Low precision of this

test can cause unnecessary culling of a big amount of triangles of an ob ject inside the b ounding volume

For an ob jective comparison of metho ds with dierent conservativity the global time measurement is

needed b ecause the results of the VFC in this case aects the load of the output device that can b e

hardware accelerator or software renderer

Considering that we did not have all details of the implementation of the same basic VFC algorithm

for comparison as the authors of the article we have used another much less exp ensive in the term of

time that has the same conservativity as the so called AssarsonMollers basic test basic intersection

that will b e describ ed later The acceleration can b e correctly measured even on less complex scenes

by comparison of the CPU needed to compute only the VFC test routines But we have compared the

algorithms with same which pro ducing the same results The fact that the Moller et al do not take care

ab out conservativity of the compared algorithms aects reliability of the presented results

The idea of the basic VFC algorithm for com

parison is taken from the article Improved frustum

object cul l where Villi Miettinen gives many ex

p eriences with the practical applications for solving

the VFC problem His algorithm is optimized for

AABB and uses one of the AssarsonMollers opti

We used only the core of Miettinens test

mization d

without this additional optimization

Miettinens basic VFC algorithm uses the

The r

collision detection b etween the VF and a sphere In

this case the b ounding sphere is determined by the

center of the AABB and a half of the diagonal con

necting the minimal and the maximal vertex of the

AABB So it is sucient to compute only the dis

tance of the center of the AABB from the tested

Figure Basic VFC algorithm idea

plane and consists of one dot pro duct and the com

parison to the radius of the b ounding sphere

Figure demonstrates the fact that the conversion of the AABB to the b ounding sphere is not exact

If we measure the entire radius of the sphere and the distance from the center of the AABB we can see

that we only need to compare its pro jection to the direction of the normal vector of the tested plane

There is one more dot pro duct compared with the simple sphereplane test The following pseudoco de

describ es more implementation details of this metho d

int AABBvsFrustumAABB b FRUSTUM f

oat m n int i result INSIDE

for i i i PLANE p fplane i

m bmx pa bmy pb bmz pc pd

n bdx fabspa bdy fabspb bdz fabspc

if m n return OUTSIDE

if m n result INTERSECT

return result

Vector mx my mz represents the center of the AABB Absolute values of the normal vector of

the plane a b c transform all p ossible values to the rst o ctant so its dot pro duct with the vector

representing a half of the AABB diagonal dx dy dz will b e always p ositive

Three dierent values are p ossible as the output of the test that determines the continuation of the

rendering pip eline

 OUTSIDE Bounding b ox is totally outside of the VF so the b ounded volume is also outside The

ob ject or the dot hierarchy is eliminated from the further pro cessing

 INSIDE Bounding b ox is totally inside of the VF There is no need for further culling of the geometry

of the b ounded ob ject or down traversal the hierarchy This state is also useful information for the

software renderer that could avoid the lowlevel p olygon clipping

 INTERSECT Ob ject could intersect the VF The down

traversal the hierarchy is needed and in the case of

leafs the sending of the entire ob ject for culling on the

level of the ob ject geometry

VF

Accuracy of rep orting INTERSECT value dep ends on

the conservativity of the used metho d Beside the inac

curacy caused by the size of the AABB and the size of

the b ounded ob ject there are another inaccuracies in the

corners of the VF The algorithm detects the INTERSECT

state even when the b ounding volume is in fact outside the

VF This case is displayed on Figure where the regions

Figure VFC algorithm inaccuracy

of failure of the algorithm are in edges of sweep frustum

Basic intersection test

The rst optimization in the article is the basic test

n−vertex

basic intersection of the collision of the AABB with the

VF Instead of nding out lo cations of all vertices in rela

tion to the tested plane it is p ossible to determine one of

the AABB states OUTSIDE INSIDE INTERSECT only by

p−vertex n−vertex

the test of two vertices the nvertex and the pvertex

Figure explained the geometric meaning of npvertices

are dened in the following way the farthest vertex

They p−vertex

of the AABB in the p ositive resp negative sense in the

direction of the normal vector of the plane is the pvertex

resp nvertex Because of the geometry of the AABB it is

p ossible to reduce the determining of the n and pvertices

Figure Examples of npvertices

using lo okup Table This table is indexed by the signs

of the normal vector parts of the given VF plane

n n n pvertex nvertex

x y z

x y z x y z

max max max min min min

x y z x y z

max max min min min max

x y z x y z

max min max min max min

x y z x y z

max min min min max max

x y z x y z

min max max max min min

x y z x y z

min max min max min max

x y z x y z

min min max max max min

x y z x y z

min min min max max max

Table Lo okup table for determining the n and pvertices

The basic test uses only two dot pro ducts The rst one detects if the nvertex is outside the half

space dened by actual VF plane In this case the AABB is also outside VF If the test fails the next

test of the pvertex is pro cessed If it is outside then the AABB intersects the plane In the opp osite

case the AABB is inside the halfspace The whole algorithm of this basic test is describ ed in the next

pseudoco de listing

Indexvectors nx ny nz and px py pz gain min and max vertices The implementation of the

Table is reduced to values that are used for indexing of the table of two items with the minimal and

maximal parts of the AABB co ordinates The test for the OUTSIDE state can b e done only by one dot pro duct

int AABBvsFrustumAABB b FRUSTUM f

oat m n int i result INSIDE

for i i i PLANE p fplane i

m pa bvpnxx pb bvpnyy pc bvpnzz

if m pd return OUTSIDE

n pa bvppxx pb bvppyy pc bvppzz

if n pd result INTERSECT

return result

Plane masking and coherency

The next two optimization have the b est eect on the sp eed plane masking and using the plane

coherency of the VFC b etween frames temporal coherency

To take advantages of the hierarchy the authors

invented an incremental reduction of planes that are

needed to test for collision with the AABB in the

given level of hierarchy If the parent b ounding b ox

is inside the halfspace then this test is not needed

in lower levels of the hierarchy Each child is then

also inside this halfspace See Figure

In the recursive traversal the bitmask of the

planes is sent from a parent to its children In

the p osition of the second dot pro duct that is used

for determining the INTERSECT state the plane is

masked out in the case of the negative test for the

Figure Plane masking

elimination of further tests on the next levels of the

hierarchy

int AABBvsFrustumAABB b FRUSTUM f int inmask int outmask

oat m n int i k result INSIDE outmask

for i k k inmask i k k if k inmask

PLANE p fplane i

m pa bvpnxx pb bvpnyy pc bvpnzz

if m pd return OUTSIDE

n pa bvppxx pb bvppyy pc bvppzz

if n pd outmask k result INTERSECT

return result

The plane coherency optimization provides b oth theoretically and practically the highest acceleration

of the current VFC algorithm This metho d used the temp oral coherency that cause little changes of

the conguration of the VF and AABBs It is very likely that if a test with a plane fails then it fails also

in the next frame with the same plane So it is sucient to remember the index of the last tested plane

and b egin with this test in the next frame One more item in the AABB structure is then needed where

this plane index is stored Also the mo dication of the algorithm is needed to use b oth tests together

correctly This situation is shown in Figure where the reordering of the plane tests dep ending on the

tests in the previous frame

4 1

1 3 2 4

2 3

Figure The plane index renumbering in the plane coherency metho d

int AABBvsFrustumAABB b FRUSTUM f int inmask int outmask

oat m n int i k bstartid result INSIDE

PLANE sp fplane bstartid outmask

if k inmask

m spa bvspnxx spb bvspnyy spc bvspnzz

if m spd return OUTSIDE

n spa bvsppxx spb bvsppyy spc bvsppzz

if n spd outmask k result INTERSECT

for i k k inmask i k k

if i bstartid k inmask PLANE p fplane i

m pa bvpnxx pb bvpnyy pc bvpnzz

if m pd bstartid i return OUTSIDE

n pa bvppxx pb bvppyy pc bvppzz

if n pd outmask k result INTERSECT

return result

Octant test

In this optimization metho d Moller et al used the symmetry of the VF If the radius of the

sphere b ounding the AABB is smaller than the smallest distance of the VF plane from the center of the

symmetric pyramid then the test with only three planes of the o ctant where the AABB center lies is

needed The situation is in Figure

Moller et al do not give more detailed description of

the implementation so we could not implement the o ctant

to b e as go o d as the authors present The problem is

test r

that the o ctant that the AABB center b elongs to could b e

only by three dot pro ducts This means p er

determined d

manent loss of nine multiplications b efore the test with the

rst plane The next problem is the test of the functional

ity of the o ctant test The comparison of two distances are

needed that are computed after any change in the geometry

of the AABB and the VF These computations are called

heavily in dynamic scenes so after the activating of this

test the VFC is slowed down Because of this we do not

Figure Octant test

nd this test useful and we will not introduce its relatively

complicated implementation

Translation and rotation coherency

This optimization signicantly aects the degree of freedom of the camera and can b e used only in

the case where none of the AABBs did not move or rotate and when the VF movement is controlled

by the user using only simple translations and rotations It cannot b e applied on general walkthrough

dynamic scenes where the translation and rotation of the camera is is uently changed Villi Miettinen

veried that TRcoherency achieves not so go o d results as Assarson and Moller presented We have

not implemented this metho d but the description is presented here See Figure

a

d

Figure Examples of TRcoherency

 rotation coherency If in the last frame the b ounding volume is outside the left plane and the whole

rotation of the camera was only to the right we can rep ort that in the current frame this ob ject is



also outside the VF The rotation need to b e less than where is the angle b etween the

left and right plane of the VF

 translation coherency Assume that VF only translated after the last frame and the distances of the

VF and the b ounding volumes changed by a little d We compute the pro jection of this increment

to the directions of the normal vectors of all VF planes Before the test for a collision of the given

b ounding volume with the VF plane we compare the distance to the given plane from the last frame

with the current increment If the increment is greater than this distance the collision detection

with the given plane has to b e pro cessed

Analogy of VFC with the collision detection

The collision test with the VF and the AABB can by easily transformed to the test of two AABBs

In practice only the plane masking and the plane coherency can help Sp eedup is based only on

eliminating several comparisons The collision test of two AABBs can b e done in the six comparisons

so a big sp eedup could not b e exp ected Much b etter optimization could b e exp ected in the test for

collision of the two OBBs where the general collision detection is very complex

Our implementation

For verifying the eciency of the optimization we developed an application that can load hierarchical

scenes with a camera and pro cess ob jects and camera motion correctly traverse a scene

hierarchy constructs b ounding volumes and visualizes the results of tests from the viewp oint including

real time measuring

As an input the internal format of the D Studio was chosen It has all necessary prop erties

mainly for scene motion The application supp orts animation based on the interpolation of the quater

nions using Ko chanekBartels piecewise continuous spline functions The hierarchy of the AABBs is

automatically actualized The AABB hierarchy is generated from the current OBB leafs by a transfor

mation

Figure Example output from our application

The user can watch the scene from the p oint ab ove the scene or directly by the view of the tested

camera All eight degrees of freedom and the geometry can b e controlled by a mouse or by hot keys The

current state of the VFC algorithm can b e seen in the output window see Figure Each of the six

camera planes has its own color that is used for coloring the ob jects that collide with this plane Ob jects

inside the VF are of white color and ob jects outside are not displayed at all The current used level

of the hierarchy can b e seen on the displayed AABBs The algorithm can b e switched to the collision

detection mo de where the VFC test is applied to the b ounding b ox chosen by a user

The Op enGL application was compiled using GCC under Linux and Windows MinGW

For measurement reasons more functions with dierent optimization are run simultaneously and the

time is measured for each of them The obtained results is then sent using TCPIP to the indep endent

application it can b e on another computer that takes care ab out their pro cessing and displaying

Measurement and results

The eciency of the optimization was veried on two tested scenes Both are fully motion contain

simple geometric solids sphere cylinder b ox and pyramid in the hierarchy The rst scene vfcds is

smaller in the number of triangles and the camera ies over the entire scene The second scene bigds

is more complex The camera ies over the entire scene and in one case even outside it

The measurement was pro cessed in two mo des The rst mo de see Graph and Graph represents

the inuence of a motion of the camera and the ob jects movement on the VFC eciency In the

second mo de see Graph and Graph the animation of the ob jects is disabled in the whole scene

All measurements were p erformed in the frames animation where in each of the frame dierent

optimization of the VFC algorithm were applied The measured time is shown relative to the time of

the basic VFC algorithm without any hierarchy The results are in the graphs where is shown time

dep endency and in the tables where there are the average values for the entire measurement

Results from the vfcds scene

70 %

60 %

VFC algorithm

50 % basic

pvertex test

40 % n

test

30 % o ctant

coherency

20 % plane

masking 10 % plane 0 %

0 25 50 75 100 125 150 175 200

Graph vfcds full ob jects motion

70 %

60 %

VFC algorithm

50 % basic

pvertex test

40 % n

test

30 % o ctant

coherency

20 % plane

masking 10 % plane 0 %

0 25 50 75 100 125 150 175 200

Graph vfcds without animation

Results from the bigds scene

70 %

60 %

basic VFC algorithm

50 %

npvertex test

40 %

test

30 % o ctant

coherency

20 % plane

masking 10 % plane 0 %

0 25 50 75 100 125 150 175 200

Graph bigds full ob jects motion

70 %

60 %

VFC algorithm

50 % basic

pvertex test

40 % n

test

30 % o ctant

coherency

20 % plane

masking 10 % plane 0 %

0 25 50 75 100 125 150 175 200

Graph bigds without animation

Conclusion

The results show that the b est acceleration was reached using the plane coherency of the VF as was

theoretically predicted The presented reasons caused that the results of Assarson and Moller were not

repro duced The results show how imp ortant is the scene hierarchy The graphs of the sp eedup with

relation to time proves ineciency of our implementation of the o ctant test On average we provide

times faster solution compared to the basic algorithm In the case of static scenes the results of

optimization are b etter then in the case of dynamic scenes as exp ected We have veried even the

p ossibility of using of the shown optimization for the collision detection The side eect of our work is

of the VFC algorithm that can b e used for the teaching purp oses

References

Ulf Assarson and Tomas Moller Optimized View Frustum Culling Algorithms for Bounding Boxes

In Journal of Graphics Tools pages

James H Clark Hierarchical Geometric Mo dels for Visible Surface Algorithms In Communications

of the ACM pages

Mel Slater and Yiorgos Chrysanthou View Volume Culling Using a Probabilistic Caching Scheme

In Proceedings of the ACM Symposium on Software and Technology pages

Ji Bittner and Vlastimil Havran Exploiting Temporal and Spatial Coherence in Hierarchical Vis

ibility Algorithms In Proceedings of Spring Conference on Budmerice SK

Ulf Assarson and Tomas Moller Optimized View Frustum Culling Algorithms technical rep ort

Chalmers University of Technology Sweden

Villi Miettinen Improved frustumob ject cull In Sourceforge mailing list gdAlgorithmslist

JT Klosowski M Held JSB Mitchell H Sowizral and K Zikan Ecient Collision Detection Us

ing Bounding Volume Hierarchies of kDOP In IEEE Transactions on Visualization and Computer

Graphics pages