QuadTree terrain rendering
I implemented a CLOD algorithm based on the whitepaper of Stefan Röttger ("Real Time Generation of Continuous Levels of Details for Height Fields").
I think all i have implemented actually is correct, at least the method which refines the quad tree and the method which perform the initial roughness calculation.
The next step after doing this is naturally to render the quad tree and see the result... but here is my problem.
My way of thinking about rendering the quad tree is that if, for a current node, any of the children are active then i recurse down the children to draw them otherwise it is a leaf node so i draw a triangle fan by omitting the required vertices at the middle of each edge.
What happens when i see the result is that i got "holes" in the display ("Cracks?").
Here is my RenderNode() method :
void QuadTreeTerrain::RenderNode(int x, int z, int width)
{
int offset = 0; // offset to the corner of the current node
int noffset = 0; // offset to the neighbour nodes
int coffset = 0; // offset to the children's nodes
// do not render the node if it's disabled !
if (quadTree[(z*tData.size)+x]==0)
{
return;
}
/* if (width<2)
{
return;
}*/
// calculate the offsets
offset = width/2;
noffset = width;
coffset = width/4;
// if any of our chilren are active then recurse and draw them!
if (quadTree[((z-coffset)*tData.size)+(x-coffset)]!=0 ||
quadTree[((z-coffset)*tData.size)+(x+coffset)]!=0 ||
quadTree[((z+coffset)*tData.size)+(x-coffset)]!=0 ||
quadTree[((z+coffset)*tData.size)+(x+coffset)]!=0)
{
RenderNode(x-coffset,z-coffset,width/2); // top left child
RenderNode(x+coffset,z-coffset,width/2); // top right child
RenderNode(x-coffset,z+coffset,width/2); // bottom left child
RenderNode(x+coffset,z+coffset,width/2); // bottom right child
}
// else it's a leaf node and we draw a triangle fan !
else
{
// render a triangle fan and omit vertices if needed
glBegin(GL_TRIANGLE_FAN);
// center vertex
RenderVertex(x,z);
// top left vertex
RenderVertex(x-offset,z-offset);
// brief explanation (this apply to all the other cases)
// if z-noffset<0 we are at a limit of our quadtree, then the vertice MUST be rendered !
// if quadTree[((z-noffset)*tData.size)+x]!=0, the neighbour have a lower level of detail
// than the current one, so skip the vertex on that side !
// top mid vertex (if needed)
if ((z-noffset)<0 || quadTree[((z-noffset)*tData.size)+x]!=0)
{
RenderVertex(x,z-offset);
}
// top right vertex
RenderVertex(x+offset,z-offset);
// right mid vertex (if needed)
if ((x+noffset)>=tData.size || quadTree[(z*tData.size)+(x+noffset)]!=0)
{
RenderVertex(x+offset,z);
}
// bottom right vertex
RenderVertex(x+offset,z+offset);
// bottom mid vertex (if needed)
if ((z+noffset)>=tData.size || quadTree[((z+noffset)*tData.size)+x]!=0)
{
RenderVertex(x,z+offset);
}
// bottom left vertex
RenderVertex(x-offset,z+offset);
// left mid vertex (if needed)
if ((x-noffset)<0 || quadTree[(z*tData.size)+(x-noffset)]!=0)
{
RenderVertex(x-offset,z);
}
// top left vertex once again
RenderVertex(x-offset,z-offset);
glEnd();
}
}
Somone see something wrong ? :-)
Is there a better way to render (ie : taking care of the partial triangle fan) ? What would your choice be ?
Best Regards, RaPhiuS / PaRaSiTe
Hmm, I don't know much about quad-trees, but I do remember seeing something about it on GameTutorials.com, and the screenshot looked oddly like a terrain. Perhaps you should look into it, under tutorials, OpenGL. Hope it helps.
- fyhuang [ site ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement