0

In OpenGL, is it possible to use multisample anti-aliasing only on edge pixels and sample each other pixel only once in order to improve performance?

In other words, I want to treat edge pixels and non-edge pixels differently, and sample multiple points for each edge pixel, while only sampling the center point for each non-edge pixel.

I have tried to Google this but I have not found any sources that discuss this; however, this video about the graphics in Manifold Garden suggests that they use a form of MSAA only on pixels that are close to an edge.

HelloGoodbye
  • 3,624
  • 8
  • 42
  • 57

1 Answers1

0

That's what multisampling is. The fragment evaluation happens at a lower rate than the number of samples in the framebuffer. The results of the evaluation are written to a number of samples that fit the pixel coverage area of the primitive rasterization. While implementations differ on what the ratio should be (some always sample the fragment shader once, others do it at a rate of 1/4th that of the sample count, etc), that is the basic idea.

Multisampling already does what you want. If it did a 1:1 ratio of fragment evaluation to samples, that would just be "supersampling".

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • I don't know if you understood my question correctly. I want to treat edge pixels and non-edge pixels differently, so that I sample more than 1 points in each edge pixel, while only sampling the center point in every non-edge pixel. – HelloGoodbye Apr 04 '23 at 21:50
  • @HelloGoodbye: What do you mean by "sample more than 1 points"? Why would you need to sample more "points", rather than just write the one "point" to fewer samples? It also wouldn't improve the performance of MSAA; it would *reduce* the performance of MSAA. – Nicol Bolas Apr 04 '23 at 23:13
  • What I mean by sampling more than one points is to use the principle of MSAA, to calculate the color in more than one point in the pixel. What do you mean by writing "the one 'point' to fewer samples"? I don't know what it is you mean should be written to a sample, usually you _read_ things from samples when you take the samples (i.e. you make a measurement using the sample). Also, I'm considering each sample to be taken in a unique point, so you would always have as many points as you have samples. Which "one point" do you refer to? – HelloGoodbye Apr 05 '23 at 12:30
  • Why do you think it would reduce the performance of MSAA? If you only need to take one sample for each non-edge pixel, that means that you have to perform less computation for each non-edge pixel compared to if you had to take as many samples in each of those pixels as in an edge pixel. In my mind, the less computation you need to do, the higher performance you would get. So by only using MSAA in edge pixels, you would increase the performance. Or am I missing something? – HelloGoodbye Apr 05 '23 at 12:33
  • In a multisample framebuffer, every pixel contains X samples, with each sample being a distinct value taken from a location within that pixel. If you were doing supersampling, you would execute the FS for each sample covered by a primitive during rasterization, so at most X times, with the outputs of each FS execution being written to a different sample. – Nicol Bolas Apr 05 '23 at 13:41
  • If you're doing MSAA however, you execute the FS Y times, where Y < X. Y may be X/4 or even a fixed value of 1. You then write the same FS outputs to *multiple* samples in the area being covered by that primitive. So if X is 16, and Y is 1, then for each pixel that touches a fragment, you run the FS 1 time, but write its values to up to 16 samples in that pixel. That's what MSAA is for. – Nicol Bolas Apr 05 '23 at 13:44
  • @HelloGoodbye: What you're asking for is for Y to change based on where you are in the primitive. You want Y = X if you're at a pixel that is on the edge of the primitive, but Y < X elsewhere. This means you're running the FS *more* in your hypothetical algorithm than you would in proper MSAA. Therefore, it would be slower. – Nicol Bolas Apr 05 '23 at 13:45