Archived

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

tj963

Triangle Rasterization

Recommended Posts

tj963    234
Hi, How does efficient triangle rasterization work? I understand the concept(I think) and I have it implemented using and incremental system, it adds a certain value every pixel and scanline it moves. But it breaks down on triangles with flat tops and bottoms. It''s also really slow. I can only draw about tem triangles. If anybody has some source code, a link to some or even a description of how it''s supposed to work that would be very helpful. Thanks, tj963

Share this post


Link to post
Share on other sites
WayfarerX    130
I wrote a rasterizer in Java awhile back, this was my primary resource, good stuff.

Check out the rest of his site too. It''s well-known and very informative.

"So crucify the ego, before it''s far too late. To leave behind this place so negative and blind and cynical, and you will come to find that we are all one mind. Capable of all that''s imagined and all conceivable."
- Tool
------------------------------

Share this post


Link to post
Share on other sites
DekuTree64    1168
I wrote a tri-filler a while back, and it ran pretty fast (did a textured version too, but it''s slower). The general idea is to render the triangle as 2 tris, one flat bottomed and the other flat topped. Of course you just bypass one half if your tri has a flat top or bottom (sort the vertices by y value, and compare y1 to y2, y2 to y3).
To render the top half, you can either compute the slope for the whole v1-v3 edge (might be slightly faster, since you can reuse it on the second half, but it loses a little accuracy), or find the x value on that edge at y2 (here''s how I do it: v1.x + (v3.x - v1.x) / (v3.y - v1.y) * height (where height is v2.y - v1.y)) and use that to find your slope. Also check wether that x value is greater than v2.x, and if so, swap them (store them in xLeft and xRight or whatever you want), then compute your slopes like (xLeft - v1.x) / height and the same for xRight. Then simply set xStart and xEnd to v1.x, and do a for y = v1.y to v2.y, adding the slopes to xStart and xEnd each time through, fill between xStart and xEnd and you have a half-triangle. The rest is just the same, except going from xLeft and xRight to v3.x, instead of v1.x to xLeft and xRight.

If you want, I can explain how I do clipping too (probably not the best method, but it seems to work good), but I don''t really have time right now, so I hope this helps as it is^_^



-Deku-chan

DK Art (my site, which has little programming-related stuff on it, but you should go anyway^_^)

Share this post


Link to post
Share on other sites