Frustum Culling

Blitz3D Forums/Blitz3D Programming/Frustum Culling

EmerGki(Posted 2005) [#1]
Somebody have any example of Frustum Culling?

Thanks'

Emerson Gresoski
Dynamic Games Entertainment
www.dynamicgames.com.br/novo or www.dynamicgames.com.br (for english)


big10p(Posted 2005) [#2]
Blitz3D automatically perform frustum culling on a per-entity basis, but if the camera can see a single pixel on an entity then the whole thing gets rendered.

Performing culling on a per-triangle basis isn't easy and I don't *think* anyone has done it successfully in B3D. The processing time needed to perform the cull is normally longer that it would take to render all entities anyway, so it's not worth it. Someone correct me if I'm wrong, here. :)


Andy(Posted 2005) [#3]
>Blitz3D automatically perform frustum culling on a per-
>entity basis, but if the camera can see a single pixel on
>an entity then the whole thing gets rendered.

I know that's the prevalent wisdom on the subject, but I've experienced some weird things which lead me to believe that it is not entirely accurate.

For example, I made a very long landing strip(two triangles) for a makeshift flight sim. Regardless of camerange it would sometimes simply disappear if I wasn't looking directly at it, even if it was still in the field of vision.

I didn't look into it, but at the time, I assumed that B3D culled not based on entity pixels, but based on entity center.


Andy


big10p(Posted 2005) [#4]
Hmmm. It can't cull simply on mesh coords (centre), otherwise you'd see entities suddenly pop into view as you looked around a scene. Can't think what the problem was you were having, though. :)


jhocking(Posted 2005) [#5]
@andy: I don't know if this is relevant to your prob (probably not) but note that Blitz culls based on an entity's first frame of animation. Thus, if the mesh is located far from that first frame, it can appear to pop in and out as the coordinates from that first frame move into and out from the camera view.

I don't know of any way around this, such as forcing Blitz to always render a given entity regardless, but I may just be forgetting how to do that.


sswift(Posted 2005) [#6]
This is my frustrum culling library which I use in my shadow system:



Free = Don't email me for support. I'm very busy!

Buy a copy of my shadow system if you want help with using it. :-)


sswift(Posted 2005) [#7]
A couple more things.

1. What you want to do is use the function in the above code for determining if a sphere that encloses your object is in the frustum. It's up to to you calculate this sphere. I just figure out the smallest box that will enclose the entity, an then make a sphere with a radius from the center of the box to the corner of the box so the sphere encloses the box.

2. I make no guarantees that trying to cull objects like this will be any faster than just letting Blitz do the job.

But I have known Blitz to fail to cull objects that are outside the camera view and cause slowdown as a result, such as when bulding a starfield for a 2D style shooter with a bunch of entities in a grid.


Beaker(Posted 2005) [#8]
I think Blitzs frustrum culling is based on entity centre and bounding sphere or box. Can't remember exactly.

This can be a problem with animated meshes (boned/skinned B3Ds) because the mesh can animate out of the bounding shape. But, it should be fine otherwise.


Andy(Posted 2005) [#9]
>@andy: I don't know if this is relevant to your prob
>(probably not) but note that Blitz culls based on an
>entity's first frame of animation.

I appreciate your input, but there were no animation, indeed it was simply a white quad consisting of 2 tri's.

It was really weird, but could possibly be because the center of the mesh was actually behind the aircraft but the landing strip continued forwards.


Andy


sswift(Posted 2005) [#10]
Best way to do frustrum culling would probably be bounding sphere and then an oriented bounding box which is scaled and rotated to fit the object as tightly as possible. I'm not sure how you would calculate that, but I'd try to figure out how I'd do it myself, and then try to construct an algorithm to do the same thing. I'll bet there are papers out there though that explain how to best fit an OBB to a cloud of points.

Anyway, the above code can do that sort of culling. If you make eight quads polygons for the sides of the box and eight for the frustum, and then clip the box with the frustum, if any of the box polygons are not clipped away completely, being completely outside the frustum, then the box is in the frustum. This is plenty fast enough to do if you don't have 100,000 objects in your scene and you do the sphere check first.


bytecode77(Posted 2006) [#11]
hi!

i don't wanted to grab this thread out of his grave, but:

the huge polyclip above^^
i do not understand how it works... is there any sample for this?
i have seen this and i got interrested :)
thanx :)


Andy(Posted 2006) [#12]
Your sig is a bit excessive.


Andy


bytecode77(Posted 2006) [#13]
grrrrrrr
where did i hear the word SIG before?
ah yes, the stencil shadow thread :/


ShadowTurtle(Posted 2006) [#14]
... sig=signature ... @ devilschil


bytecode77(Posted 2006) [#15]
ok st, now lets don't make too much offtopic :) !

have you got any sample to this?


jhocking(Posted 2006) [#16]
You mean other than his shadow system?


bytecode77(Posted 2006) [#17]
no, i mean how this polygon clipping algorithm works...
because i would be interessted in that^^