# Calculating coverage for software rasterization

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

## 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 on other sites
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 on other sites
Quote:
 Original post by meisawesomeAssuming 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 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!

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633387
• Total Posts
3011620
• ### Who's Online (See full list)

There are no registered users currently online

×