Sign in to follow this  

Primitive type with Octtrees?

This topic is 4713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've got a quick question that puzzled me off and on for the last month: What's the best primitive type to use with Octtrees? Please correct me if I am wrong, but I would assume that storing each individual triangle that is inside or crosses an AABB would result in a very, very large data structure and a waste of video memory (or system memory, if I choose to use the deformable terrain route). I would also think that using triangle strips would be somewhat akward, as by the time the subdivision gets down to just a few triangles per AABB, the benefit of having the polygons stripped would be outweighed by the many, many API calls. That leaves me with indexed triangles. Indexed tris would solve the storage requirement, as instead of having to store three floats for position, two floats for texcoords and maybe more data, all you would have to do is store three unsigned integers for the indicies. Also, the function calls in DirectX allow you to specify which indicies to draw, so there would be no problems in regards to API overhead. Unfortunately indexed tris bring up a new problem with polygons that are in both bounding boxes: they would be drawn twice, leading to possible z-fighting problems. Are indexed tris the way to go?

Share this post


Link to post
Share on other sites
Here is how I'd do it ( still have to implement it )
The octree class stores all the triangles.
In each octree node you store indices (or pointers) to the triangles that intersect it.
Each frame you increment a "frame time" variable and check the visible triangles against it. If it's the same, don't draw, outerwise set the triangle frame time to the current frame time and draw.
So it's something like:


struct Triangle
{
DWORD VertexIndices[3];
DWORD FrameTime;
};

struct OctreeNode
{
Triangle** ppTriangles; // triangle pointer array
};

class Octree
{
void Draw()
{
++m_FrameTime;

for each visible triangle
{
if( pTriangle->FrameTime != m_FrameTime )
{
AddTriangleToRenderQueue( pTriangle );
pTriangle->FrameTime = m_FrameTime;
}
}
}

private:

DWORD m_FrameTime;

Triangle* m_pTriangles; // The actual triangles of the level
OctreeNode* m_pRoot;
};






This way every visible polygon is only rendered once.
And of course the best primitive to use is indexed triangle list, because you can set a big vertex buffer once and work just with indices.

Share this post


Link to post
Share on other sites

This topic is 4713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this