Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am thinking about the best ways to render two dimensional objects in the highest detail possible using modern graphics technology and it occurred to me that when I simplify a situation enough, I ought to be able to calculate the exact percentage of coverage of a triangle over a pixel, at least for the cases where an edge spans a pixel. This is, after all, the primary issue that multisampling and supersampling are dealing with, the issue of coverage.

I now realize that the question of how to exactly produce the coverage of the pixel that the vertices lie on is a much more difficult one.

Is it fair for me to say that it is theoretically possible to perform such a calculation on programmable shaders? After all, it's quite possible to compute the area covered by an arbitrary triangle which lies over a grid, on all the grid cells.

I guess I seem to have already come up with an explanation of why not do antialiasing this way: the corners.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

If you are dealing with more than one triangle in your world, the corners aren't even the only problem. If you're rendering an antialiased triangle over a known background, you can calculate the coverage at a pixel and blend using that alpha. But if you then render a second triangle over the first one, you have to ask a question: Did this second triangle block the first one? Did the first one block the second? Did they not overlap at all? Did they partially overlap? For an unbounded number of triangles, it's a very hard problem to solve "perfectly"—you have to remember every triangle that intersects that pixel (unless there are clever algorithms that I am unfamiliar with).

It's possible to perform such a calculation, it's simply impractical.

share|improve this answer
    
I think there still would be a way to have it work consistently without remembering the triangles. But I think you're right, the issue is that the resultant color depends on the actual orientation of the coverage itself. A contrived example I just came up with is the case of two shapes which cover half of a pixel. Suppose one is red and one is green. If the red shape covers the left side of the pixel and the green shape covers the right side, the resultant pixel color is yellow. However if both shapes cover the same exact portion of the pixel, the green would overwrite the red. No yellow. –  Steven Lu Feb 11 '12 at 16:15
add comment

A pixel is a single sample of the various geometrical shapes at that point. Supersampling is essentially a way of better approximating those shapes. An analogy is the rectangle method as a way of estimating the area under a curve, and which produces better estimates for more, smaller rectangles.

It is possible to beat such approximative methods if you have access to the original geometry, just as you can calculate the area under a curve precisely if you know the formula for the curve. The problem with computer graphics is that by the time you want to render a single pixel, you've discarded all those triangles many operations ago. A computer with enough resources could remember every triangle that affects a given pixel and then, once all the triangles were drawn, could construct the final pixel value based on that. Obviously that would be immensely impractical so instead we take a representative sample from each triangle and throw away the precise information. Supersampling means we take more information from each one and reduce the aliasing, but it can't be avoided entirely once you cross over from the analogue domain into the digital.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.