Jump to content
  • Advertisement
Sign in to follow this  
jamesw

Calculating coverage for software rasterization

This topic is 3408 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'm trying to find implementation details on how to calculate pixel coverage (the area of the pixel covered by the triangle) when rasterizing triangles in software. I did some googling but wasn't able to find anything helpful. Does anyone know of any resources on this topic?

Share this post


Link to post
Share on other sites
Advertisement
Assuming you have an already transformed and projected triangle (aka 2D)

I believe that this is correct...
TriangleArea = 0.5f * ((x1 - x2) * (y3 - y1) - (y1 - y2) * (x3 - x1));

Edit:
This site should be able to explain it:
http://softsurfer.com/Archive/algorithm_0101/algorithm_0101.htm

Share this post


Link to post
Share on other sites
Quote:
Original post by meisawesome
Assuming you have an already transformed and projected triangle (aka 2D)

I believe that this is correct...
TriangleArea = 0.5f * ((x1 - x2) * (y3 - y1) - (y1 - y2) * (x3 - x1));

Edit:
This site should be able to explain it:
http://softsurfer.com/Archive/algorithm_0101/algorithm_0101.htm


This isn't remotely related to what the OP's question was!
He didn't want to know the area of a triangle!?

Back on track:
I guess there might be some performance tricks, but the naive way of doing it is to clip the triangle against the four pixel borders, then calculate the area of the resulting polygon.

I assume you use this for some sort of AA?
If you accept some quality loss you might get away by subdividing the pixel (2x2, 4x4 etc) and then calculate how many of the sub pixels centers are within the triangle.



Share this post


Link to post
Share on other sites
>I assume you use this for some sort of AA?

It's for a lightmapper, when using low resolution lightmaps I end up with multiple triangles per texel. I want to know how to weight each triangle's attributes toward the final result for that texel. I'm currently doing what you said with sub pixel centers, but even with a large number of samples (16) small texels on UV seams won't get any triangles rasterized to them, so I was looking for an analytical approach. I'll try clipping the triangle.

Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!