Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deferred shading anti-aliasing

Many people note that MSAA does not work with deferred shading. Why is that? It sounds okay in my head.

According to wikipedia:

... due to separating the lighting stage from the geometric stage, hardware anti-aliasing does not produce correct results anymore since interpolated subsamples would result in nonsensical position, normal, and tangent attributes.

Can you explain that?

What are the other AA alternatives I have?

like image 794
Pilpel Avatar asked Dec 02 '22 15:12

Pilpel


2 Answers

Multisampling does work with deferred rendering. Deferred rendering simply changes the price you pay for it.

Multisampling is based on the general idea that you only need to execute the fragment shader once for all of the samples covered by a particular triangle's rasterization within that pixel. So while you do write to multiple samples (like with super sampling), you only execute the fragment shader once, thus saving lots of texture accesses. The same value is written across the samples in the multisample image.

That is still doable with deferred rendering. The geometry pass still makes sense under multisampling rules. Or at least, as much sense as it ever has.

The problem is what you have to do during your lighting pass.

Because your geometry pass was multisampled, your lighting pass must read multisampled data. You cannot do a multisample resolve of the geometry buffers (that would be the "nonsensical" part Wikipedia was talking about); your lighting pass must read each sample and process it. Per light. So if you did an 8x multisample operation, your fragment shader will have to run eight times for each pixel. Per light.

That's generally not a cost that a lot of people are willing to pay.

The alternatives are any of the "I can't believe it's not anti-aliasing" techniques, like FXAA or whatever.

like image 99
Nicol Bolas Avatar answered Dec 28 '22 07:12

Nicol Bolas


Multi-sample antialiasing samples the visibility of a primitive at several subpixel positions, however the shading is only evaluated once inside a pixel per primitive. Deferred shading samples the geometric attributes, and the shading is deferred into a second phase where the correspondence between primitives and visibility samples is lost, which makes it hard to avoid redundant shading. Furthermore, the geometry buffer can become prohibitively large in case of high screen resolutions and high visibility sampling because each sample needs to store all attributes. ---From Deferred Attribute Interpolation Shading's introduction.

like image 36
freehyan Avatar answered Dec 28 '22 08:12

freehyan