PDA

View Full Version : question about 4 x MSAA



Desperado
02-21-2018, 07:34 AM
Hello, I have a question about 4 x MSAA with Opengl:

Assume, I draw a white ( 1, 1, 1, 1 ) quad on a black background (0, 0, 0, 1) using 4 x MSAA.
A pixel is covered by the quad by 100% in y direction and by 70% in x direction.
Should the resulting pixel have a color of ( 0.7, 0.7, 0.7, 1 ) ?

Regards

GClements
02-21-2018, 09:35 AM
4x MSAA only has four samples per fragment, so the blending ratios will be in increments of 25%. So 0.7 isn't possible. Also, the alignment matters, so 70% coverage might have 2 or 3 samples inside depending upon the sample positions.

So you'd expect to get either (0.5,0.5,0.5,1) or (0.75,0.75,0.75,1). It's theoretically possible to get other values, as the sample positions are up to the implementation. Having all 4 samples inside 70% coverage seems quite unlikely but not entirely beyond the bounds of possibility; but only having one is inconceivable.

Desperado
02-21-2018, 10:49 AM
I see. Would it be possible to calculate the blending ratio by other means, like, in the shader, in cases where I can calculate it exactly ( like screen space quad drawing )?

Also if you could point me to a document that defines exactly how the samples are spatially distributed over the pixel and which sample yields which blending ration I'd be grateful.

GClements
02-21-2018, 09:57 PM
I see. Would it be possible to calculate the blending ratio by other means, like, in the shader, in cases where I can calculate it exactly ( like screen space quad drawing )?
Rather than using MSAA, you can use glEnable(GL_POLYGON_SMOOTH) to generate alpha values for edge fragments, which can then be used with blending. However, this requires rendering polygons in front-to-back order, and it only considers polygon edges, not e.g. depth testing.


Also if you could point me to a document that defines exactly how the samples are spatially distributed over the pixel and which sample yields which blending ration I'd be grateful.
The sample points are implementation-dependent. You need to refer to the vendor's documentation for your particular hardware, or you can use glGetMultisample() to query the sample locations at run time (if they're fixed; it's possible for the sample locations to vary between fragments).