multisampling and fragment shader

自闭症网瘾萝莉.ら 提交于 2019-12-08 19:08:29

This is the basic idea of MSAA (multisample anti-aliasing). The fragment shader is only executed once per fragment. The sample mask is then used to control which samples the resulting fragment is written to.

Say you use 4x MSAA, where each fragment consists of 2x2 samples. If the edge of a triangle passes through a fragment, only the samples on the inside of the edge are updated with a new color. So if the fragment is only partly inside the triangle, 1, 2, or 3 of the 4 samples may be updated. But the samples that are updated are all updated with the same color. Therefore, the fragment shader only needs to be evaluated once.

The big advantage of this approach is that it is very efficient. It will often add only a very modest overhead compared to rendering without MSAA. As already established, the number of shader executions is unchanged. The render target theoretically gets 4 times larger, which could increase memory usage substantially. But that memory can often be compressed effectively, so it is not as bad as it sounds. There obviously is a downsampling step at the end of rendering the frame, which does add overhead.

The disadvantage is that MSAA only helps to smooth triangle boundaries and intersections. If you have sharp transitions within a triangle, e.g. because of texture content, or due to procedural textures, it will not help at all. Mipmapping can reduce jagged edges from texturing, and procedural textures can reduce sharp transitions by taking the gradient into account. But MSAA does not help.

If you want anti-aliasing that addresses all sources of aliasing from sharp transitions, you can go all out and use supersampling. This means that you render the whole scene at a higher resolution. For example, if the size of your final render target is w times h, you render to a surface with size 2 * w times 2 * h, and downsample in the end. This is substantially more expensive, since you now execute the fragment shader 4 times as often, and compression on the larger surface will also not be nearly as effective as on the MSAA surface.

I haven't used the ARB_sample_shading extension you found. But from what I understand about it, it tries to approach the visual quality of supersampling while maintaining at least some of the performance benefits of MSAA.

The sample_shading extension is needed: "In standard multisample rendering, an implementation is allowed to assign the same color and texture coordinate values to each sample, which then allows the optimization where the shader is only evaluated once and then distributed to the samples that have been determined to be covered by the primitive currently being rasterized."

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!