管道中的多重采样 [英] Multisampling in pipeline

查看:147
本文介绍了管道中的多重采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在多重采样中,在光栅化过程中,每个像素中有多个采样点,并决定哪些采样点构成原始图像。

像素中每个样本的哪些属性是相同的?我在某处读到颜色和纹理值相同,但像素中样本的深度和stensil值不同。但是由于片段着色器是针对每个采样点执行的,因此它们应该是不同的。

另外,在片段着色器之后,多个采样在流水线中解析的时间是多少?他们是线性平均吗?

解决方案

首先你必须了解多重采样是如何工作的以及为什么创建它。



我将从反锯齿的角度来讨论这个问题,因为这是多采样直到多采样纹理在GL3中引入的主要用例。



当多次采样时,这意味着每个采样点都包含多个采样。如果基元具有相对一致的特征(例如,在任何地方都具有相同的深度),并且智能GL /硬件实现能够识别这种情况并通过智能地读取/写入共享样本来减少存储器带宽(这类似于颜色,则这些样本可以彼此相同) /深度缓冲压缩)。然而,4x MSAA帧缓存所需的存储成本与4x SSAA相同,因为GL必须适应最糟糕的情况,其中每个样本都是唯一的。


像素中每个样本的哪些属性相同?

每个片段可能覆盖例如颜色,纹理坐标等属性的多个采样点。而不是频繁地调用片段着色器4x以实现4倍的抗锯齿,设计了一个技巧,其中每个属性将在片段中心被采样(这是默认设置)然后将单个输出写入每个覆盖样本位置。在片段的中心不是实际覆盖区域的一部分的情况下,默认行为有些缺乏 - 为此,引入了质心采样...顶点属性将被插值在片段内的基元覆盖区域的中心而不是片段本身的中心。

稍后,当需要为帧缓冲区写入颜色时,需要对所有这些样本进行平均以产生单个像素;我们称之为多重样本解决方案。这适用于某些事情,但它不能解决在片段着色过程中出现的混叠问题。



在执行片段着色器期间出现纹理,这意味着纹理的采样频率保持不变,所以MSAA通常不会帮助纹理别名。因此,尽管超级采样反锯齿可以改善几何边缘 纹理/着色器别名(像镜面反射亮点),多重抽样通常只会减少锯齿。


我在某处读到颜色和纹理值相同,但是样本的深度和stensil值在一个像素中是不同的。


简而言之,片段着色器中计算的所有内容对于所有覆盖样本都是相同的。任何可以在 之前确定的 片段着色(例如深度)可能会有所不同。

片段测试,例如深度/模板将针对每个子样本进行评估。但是多采样深度缓冲区会带来一些限制。在D3D 10.1之前,硬件不需要支持多重采样深度纹理,因此您无法在片段着色器中采样多重采样深度缓冲区。


但是因为片段着色器是针对每个样本点执行的,所以它们应该是不同的。


有一个称为样本着色的功能,通过改进栅格化期间生成的阴影和样本之间的比例,实现MSAA更像SSAA。但默认情况下,您所描述的行为不是多抽样。


何时在流水线中解析了多个样本,片段着色器之后?并且它们是线性平均的吗?


多重采样解决方案在 片段着色之后发生 ,任何时候您必须将多采样缓冲区的内容写入单采样缓冲区。这包括诸如 glBlitFramebuffer(...)之类的东西。如果您使用多重采样纹理,您也可以自己在 片段着色器中手动实施多重采样分辨率。



最后,关于用于多采样分辨率的处理,这与样本布局一样是特定于实现的。如果您打开显示驱动程序的控制面板并查看可用的多种反锯齿选项,则会看到多个选项用于样本布局和MSAA解析算法。






我强烈建议你看看这篇文章。虽然它与D3D10 +而不是OpenGL相关,但一般规则适用于两种API(D3D9有不同的规则),并且图表的质量非常好。

特别要特别注意三角形的MSAA光栅化规则部分,其中指出:


对于三角形,对每个样本位置执行覆盖测试(不是针对像素中心)。如果覆盖多个采样位置,像素着色器将在像素中心处插值属性运行一次。结果将被存储(复制)用于通过深度/模板测试的像素中的每个覆盖样本位置。



In multisampling, during rasterization there are more than one sample points in each pixel and sample points are decided which constitutes the primitive.

which attributes are same for each sample in a pixel? I read somewhere that color and texture values are same but depth and stensil values for samples in a pixel are different. But as fragment shader is executed for each sample points then they should be different.

Also, When does the multiple samples are resolved in pipeline, after fragment shader? And do they linearly average out?

解决方案

First you have to realize how multisampling works and why it was created.

I am going to approach this from the perspective of anti-aliasing, because that was the primary use-case for multisampling up until multisample textures were introduced in GL3.

When something is multisampled, this means that each sample point contains multiple samples. These samples may be identical to one another if a primitive has relatively uniform characteristics (e.g. has the same depth everywhere) and smart GL/hardware implementations are capable of identifying such situations and reducing memory bandwidth by reading/writing shared samples intelligently (similar to color/depth buffer compression). However, the cost in terms of required storage for a 4x MSAA framebuffer is the same as 4x SSAA because GL has to accommodate the worst-case scenario, where each of the 4 samples is unique.

Which attributes are same for each sample in a pixel?

Each fragment may cover multiple sample points for attributes such as color, texture coordinates, etc. Rather than invoking the fragment shader 4x as frequently to achieve 4x anti-aliasing, a trick was devised where each attribute would be sampled at the fragment center (this is the default) and then a single output written to each of the covered sample locations. The default behavior is somewhat lacking in the situation where the center of a fragment is not part of the actual coverage area - for this, centroid sampling was introduced... vertex attributes will be interpolated at the center of a primitive's coverage area within a fragment rather than the center of the fragment itself.

Later, when it comes time to write a color to the framebuffer, all of these samples need to be averaged to produce a single pixel; we call this multisample resolve. This works well for some things, but it does not address issues of aliasing that occurs during fragment shading itself.

Texturing occurs during the execution of a fragment shader, and this means that the sample frequency for texturing remains the same, so MSAA generally does not help with texture aliasing. Thus, while supersample anti-aliasing improves both aliasing at geometric edges and texture / shader aliasing (things like specular highlights), multisampling generally only reduces "jaggies."

I read somewhere that color and texture values are same but depth and stensil values for samples in a pixel are different.

In short, anything that is computed in the fragment shader will be the same for all covered samples. Anything that can be determined before fragment shading (e.g. depth) may vary.

Fragment tests such as depth/stencil are evaluated for each sub-sample. But multisampled depth buffers carry some restrictions. Up until D3D 10.1, hardware was not required to support multisampled depth textures so you could not sample multisampled depth buffers in a fragment shader.

But as fragment shader is executed for each sample points then they should be different.

There is a feature called sample shading, which can force an implementation of MSAA to work more like SSAA by improving the ratio between fragments shaded and samples generated during rasterization. But by default, the behavior you are describing is not multisampling.

When does the multiple samples are resolved in pipeline, after fragment shader? And do they linearly average out?

Multisample resolution occurs after fragment shading, anytime you have to write the contents of a multisampled buffer into a singlesampled buffer. This includes things like glBlitFramebuffer (...). You can also manually implement multisample resolution yourself in the fragment shader, if you use multisampled textures.

Finally, regarding the process used for multisample resolution, that is implementation-specific as is the sample layout. If you ever open your display driver's control panel and look at the myriad of anti-aliasing options available you will see multiple options for sample layout and MSAA resolve algorithm.


I would highly suggest you take a look at this article. While it is related to D3D10+ and not OpenGL, the general rules apply to both APIs (D3D9 has slightly different rules) and the quality of the diagrams is phenomenal.

In particular, pay special attention to the section on MSAA rasterization rules for triangles, which states:

For a triangle, a coverage test is performed for each sample location (not for a pixel center). If more than one sample location is covered, a pixel shader runs once with attributes interpolated at the pixel center. The result is stored (replicated) for each covered sample location in the pixel that passes the depth/stencil test.

这篇关于管道中的多重采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆