Anti-Aliasing Best Practices
抗锯齿最佳实践
Qt Quick 3D has multiple ways to combat aliasing (the jagged edges) while rendering 3D models. Each technique offers its own benefits and limitations. Multiple techniques can be combined, but with additional performance cost.
Qt-Quick 3D有多种方法可以在渲染3D模型时消除锯齿(锯齿边缘)。每种技术都有其优点和局限性。多种技术可以结合使用,但会带来额外的性能成本。
Causes of Aliasing
消除锯齿的原因
Although aliasing is a useful tool in rendering graphics, it could affect performance of your application if not used wisely. The following sections summarize the different aliasing techniques to choose from. Understanding which technology best targets your problems will help balance visual quality with sufficient rendering speed.
尽管消除锯齿在渲染图形时是一个有用的工具,但如果使用不当,它可能会影响应用程序的性能。以下各节总结了可供选择的不同消除锯齿技术。了解哪种技术最适合您的问题将有助于平衡视觉质量和足够的渲染速度。
Geometry Aliasing
几何体消除锯齿
By default, all geometry is rendered one on-screen pixel at a time. As you can see on the left in the image below, this leaves harsh edges that may be easily noticeable in high-contrast cases (most noticeably in this black-and-white case).
默认情况下,所有几何体一次渲染一个屏幕像素。正如您在下图左侧所看到的,这会留下在高对比度情况下很容易注意到的粗糙边缘(在黑白情况下最明显)。
The most correct fix for this is to use Multisample Anti-Aliasing, as it gathers more geometric detail only as needed. Using Temporal Anti-Aliasing or Progressive Anti-Aliasing can also mitigate the issue in a correct manner.
最正确的解决方法是使用“多采样消除锯齿”,因为它仅根据需要收集更多几何细节。使用临时消除锯齿或渐进消除锯齿也可以以正确的方式缓解问题。
Finally, in certain cases you can use a silhouette opacity map to smooth the edges of selected geometry.
最后,在某些情况下,可以使用轮廓不透明度贴图来平滑选定几何体的边缘。
Texture Aliasing
纹理锯齿
When a texture is sub-sampled, fewer pixels than in the original are displayed, resulting in undesirable artifacts based on which pixels are chosen. This effect is worsened when the model is moving, as different pixels are chosen at different times. In the image below, notice how the line between E3 and F3 is missing, strongly present between G3 and H3, then gone for the next 5 columns, and so on.
对纹理进行子采样时,显示的像素数比原始纹理中的像素数少,从而导致基于像素选择的不希望出现的伪影。当模型移动时,由于在不同的时间选择不同的像素,这种效果会恶化。在下图中,请注意E3和F3之间的线是如何缺失的,G3和H3之间强烈存在,然后在接下来的5列中消失,以此类推。
The simplest (and arguably the best) fix for this problem is to use mipmapping in the image texture itself. Alternative fixes include using either Temporal AA or Progressive AA to gather more information from the texture.
解决这个问题最简单(也可以说是最好)的方法是在图像纹理本身中使用mipmapping。替代修复包括使用时间AA或渐进AA从纹理收集更多信息。
Using Multisample Anti-Aliasing will not fix this problem.
使用多采样消除锯齿无法解决此问题。
Reflection Aliasing
反射锯齿
Similar to Texture Aliasing, a material reflecting the environment will sub-sample the image. In some cases, as seen on the left in the image below, it becomes obvious when fine details are being skipped.
与纹理锯齿类似,反射环境的材质将对图像进行子采样。在某些情况下,如下图左侧所示,当跳过精细细节时,这一点变得很明显。
The most correct solution in this case is using Temporal AA or Progressive AA to find the extra information.
在这种情况下,最正确的解决方案是使用时间AA或渐进AA来找到额外的信息。
A simple alternative solution that may be acceptable is to make the material less glossy, more rough. In this case lower-resolution mipmaps of the environment are automatically used, blending the sharp details together.
可以接受的一个简单的替代解决方案是使材料不太光滑,更粗糙。在这种情况下,将自动使用环境的低分辨率MIP贴图,将清晰的细节混合在一起。
Anti-Aliasing Techniques
抗锯齿技术
Aliasing is caused when there is more information present in the original than we can represent in the pixels on screen. Anti-aliasing techniques fall into three categories:
当原始图像中存在的信息比屏幕上的像素所能表示的信息更多时,就会产生锯齿。抗锯齿技术分为三类:
- Techniques that find additional information for a single pixel and represent them all at the same time.
- 为单个像素找到附加信息并同时表示它们的技术。
- Image effects that attempt to find where things look bad and sweep the problems under the carpet.
- 图像效果试图找出事情看起来不好的地方,并将问题隐藏起来。
- Techniques employed by artists that attempt to workaround the limitations.
- 艺术家试图解决这些限制的技术。
Techniques that find additional information
查找附加信息的技术
Multisample Anti-Aliasing
多采样抗锯齿
Multisample AA (MSAA) operates on an entire layer. The edges of geometry are super-sampled, resulting in smoother silhouettes. This technique has no effect on the materials inside geometry, however.
多采样AA(MSAA)在整个层上运行。几何体的边缘被超级采样,从而产生更平滑的轮廓。但是,该技术对几何体内部的材质没有影响。
- Pros: Good results on geometry silhouettes, where aliasing is often most noticeable. Works with fast animation without an issue. Many recent GPUs support 2x or 4x MSAA without any performance issue.
- 优点:在几何轮廓上效果良好,其中锯齿通常最为明显。与快速动画一起工作,没有任何问题。许多最新的GPU支持2倍或4倍MSAA,没有任何性能问题。
- Cons: Can be expensive to use. Does not help with texture or reflection issues.
- 缺点:使用起来可能很贵。对纹理或反射问题没有帮助。
Temporal Anti-Aliasing
随机采样抗锯齿
Temporal AA operates on an entire layer. The camera is jiggled very slightly between frames, and the result of each new frame is blended with the previous frame.
时间AA在整个层上运行。相机在帧之间轻微抖动,每个新帧的结果与前一帧混合。
- Pros: Due to the jiggling camera it finds real details that were otherwise lost. Low impact on performance.
- 优点:由于摄像机抖动,它可以找到原本丢失的真实细节。对性能的影响较小。
- Cons: Fast-moving objects cause one-frame ghosting.
- 缺点:快速移动的物体会导致一帧重影。
Progressive Anti-Aliasing
渐进抗锯齿
Progressive AA (PAA) operates on an entire layer. When all content of the layer has stopped moving, the camera is jiggled very slightly between frames, and the result of each new frame is blended with the previous frames. The more frames you accumulate, better looking the result.
渐进式AA(PAA)在整个层上运行。当层的所有内容停止移动时,相机在帧之间轻微抖动,每个新帧的结果与先前帧混合。累积的帧越多,结果越好看。
- Pros: Provides detailed static images with no performance cost.
- 优点:提供详细的静态图像,无性能成本。
- Cons: Does not take effect if any visual changes are occurring. 8x PAA takes one eighth of a second to finish rendering (at 60fps), which may be noticeable.
- 缺点:如果发生任何视觉变化,则不生效。8x PAA需要八分之一秒的时间才能完成渲染(以60fps),这可能是显而易见的。
Mipmaps
纹理映射
Mipmapping stores the texture along with its pre-calculated lower resolution versions. Whenever the texture is being displayed at a smaller size, the rendering system automatically uses these low-resolution images (which combine many details into a single pixel) blending them into the result as needed.
Mipmapping存储纹理及其预计算的低分辨率版本。无论何时纹理以较小的尺寸显示,渲染系统都会自动使用这些低分辨率图像(将许多细节合并为单个像素),并根据需要将其混合到结果中。
- Pros: Very low performance impact. Greatly improves image quality for textures. Encourages you to use compressed textures, which load and render faster than uncompressed imnages.
- 优点:性能影响非常低。极大地提高了纹理的图像质量。鼓励您使用压缩纹理,这比未压缩的iManager加载和渲染更快。
- Cons: Requires using external tools to optimize your images. Uses 33% more graphics memory than the same image without mipmaps.
- 缺点:需要使用外部工具优化图像。使用的图形内存比不使用mipmaps的图像多33%。
Supersample Anti-Aliasing
超采样抗锯齿
Supersample AA (SSAA) operates on an entire layer, or even multiple layers. It is not mentioned or compared above because the performance penalty can be severe, and because it requires additional work from the artist. This technique should be used as a last resort.
超采样AA(SSAA)在整个层甚至多个层上运行。上面没有提到或比较,因为性能消耗可能很严重,而且需要艺术家的额外工作。这种技术应作为最后手段使用。
- Pros: Provides full-scene anti-aliasing with no limitations on animation.
- 优点:提供全场景抗锯齿,对动画没有限制。
- Cons: Can severely degrade performance when your scene is already limited by the fill-rate of the graphics system, which is often the case.
- 缺点:当您的场景已经受到图形系统填充率的限制时,会严重降低性能,通常情况就是这样。
Artist-Employed Cheats
受雇艺术家的欺骗
Silhouette Opacity Maps
轮廓不透明度贴图
When your model has a consistent silhouette, you can apply an opacity map that makes the outer edge of the geometry transparent. Using a gradient for the opacity will let the edge of the object smoothly disappear. However, even if your opacity map transitions directly from fully-opaque to fully-transparent over the space of one pixel, the result will still provide anti-aliased edges as seen in the example above. This is because image maps, including opacity maps, use bilinear interpolation.
当模型具有一致的轮廓时,可以应用不透明度贴图,使几何体的外边缘透明。为不透明度使用渐变将使对象的边缘平滑消失。但是,即使不透明度贴图在一个像素的空间上直接从完全不透明过渡到完全透明,结果仍将提供抗锯齿边,如上面的示例所示。这是因为图像贴图(包括不透明度贴图)使用双线性插值。
- Pros: Can show softer transitions than normal AA. Can be applied per model instead of per-layer.
- 优点:可以显示比正常AA更柔和的过渡。可以应用于每个模型而不是每个层。
- Cons: Cannot be used if the silhouette of the object will ever change. Multiple overlapping models that employ transparency consume fill rate performance, which is often at a premium.
- 缺点:如果对象的轮廓将发生变化,则不能使用。使用透明性的多个重叠模型会消耗填充率性能,这通常是一个额外消耗。
Modifying Materials or Geometry
修改材质或几何体
As demonstrated in the image for Reflection Aliasing above, sometimes the simplest fix for problems is to change the artwork. If you are getting distracting specular glints on the corner of your model, ask yourself: Can I make the material softer? Can I modify the geometry to smooth or change the reflection angle? Can I edit the environment map to reduce sharp transitions?
正如上面的反射锯齿图像所示,有时解决问题最简单的方法是更改艺术品。如果您的模型角上出现分散注意力的镜面反射,请扪心自问:我可以使材质更柔和吗?我可以修改几何体以平滑或更改反射角度吗?我可以编辑环境贴图以减少急剧过渡吗?
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.