Archived

This topic is now archived and is closed to further replies.

bakery2k1

Polygon tesselation

Recommended Posts

bakery2k1    712
I wrote my .map file parser, and can now render levels created in Worldcraft. The problem is that each wall is one large polygon, so lighting looks terrible. Does anyone have any code/links so that I can split a polygon into an arbitrary number of smaller ones, so that the lighting will look good? I really want to give a tesselation level and a polygon, and the code to draw it out of smaller triangles. eg:
    /\  
   /  \
  /    \
 /      \
/--------\

goes to

    /\
   /  \
  /----\
 / \  / \
/---\/---\
 
with tesselation level 1, etc Any other ideas (except lightmaps?)

Share this post


Link to post
Share on other sites
bakery2k1    712
The polygons can be of arbitrary size and shape, with an arbitrary number of vertices, but are always convex. I can probably do the triangle case, simply by interpolating vertex positions, and then put these together to get other polygons, in a fan shape. I was wondering if there are any well-known methods, since I thought this would be a common problem.

Thanks

Share this post


Link to post
Share on other sites
bstepa    122
Triangle fans would work. You can subdivide the inner triangles by adding a new vertex at the midpoints between two vertices that make up one of the triangles in the triangle fan. Pretty simple to do. As long as the polygon is coplaner, I don''t think there should be any problems (remember to put a limit on the tessellation depth).

Share this post


Link to post
Share on other sites
nitzan    108
This should be incredibly easy with recursion.

Just write a function that takes a triangle and splits it into four other triangles, then calls itself with those triangles.

For example:

this pseudo-code:

void tessalate(GLfloat x[3], GLfloat y[3], int depth) {

// x[3] holds all the x coordinates of the triangle.
// y[3] holds all the y cooddinates of the triangle.

if(depth == 0) {
drawTriangle(x, y);
return;
}

// find first sub-triangle and pass it along //

GLfloat temp_x[3];
GLfloat temp_y[3];

temp_x[0] = x[0]+x[1]/2;
temp_y[0] = y[0]+y[1]/2;
temp_x[1] = x[0];
temp_y[1] = y[0];
temp_x[2] = x[0]+x[2]/2;
temp_y[2] = y[0]+y[2]/2;

tessalate(temp_x, temp_y, depth--);

// repeat code above for the other 4 sub-triangles

return;
}

obviously you dont want to do all the calculations every frame. So you would probably create some tree-structure to store the sub triangles so you can simply parse the tree whenever you want to draw them.

I hope this is what you asked for, and I also hope this helps. I guess this is kind of a complicated subject.

Nitzan

-------------------------
www.geocities.com/nitzanw
www.scorchedearth3d.net
-------------------------

Share this post


Link to post
Share on other sites
bakery2k1    712
i guess you could use some cool per pixel lighting... on a geforce3...

I''d like to do that(dont have a geforce 3 yet, but looking in to it). However, all the articles i''ve seen involve still calculating the vector to the light at each vertex, not per fragment.
Do you have any more in-depth infornmation?

BTW, I''m now looking into spotlights using projective texturing.

Share this post


Link to post
Share on other sites
miles vignol    122
If you go with a recursize triangle subdivision kind of approach, you should add a "minimum size" check that would end up keeping triangles relatively similar sizes (and not was time subdividing slivers). If a triangle is smaller than this size, the recursion ends. What the "size" of each triangle means is up to you (bounding box, area, perimeter, longest side, etc.)

Just a suggestion.


Edited by - miles vignol on December 19, 2001 2:38:23 PM

Share this post


Link to post
Share on other sites