延迟渲染 (或延迟着色/延迟光照)

From Valve Developer Community
< Zh
Revision as of 18:22, 14 June 2025 by BlueMicro (talk | contribs)
Jump to navigation Jump to search
Under construction.png
This page is actively undergoing a major edit.
As a courtesy, please do not edit this while this message is displayed.
If this page has not been edited for at least several hours to a few days, please remove this template. This message is intended to help reduce edit conflicts; please remove it between editing sessions to allow others to edit the page.

The person who added this notice will be listed in its edit history should you wish to contact them.

Info content.png
This page is being translated.
You can help by finishing the translation.
If this page cannot be translated for some reason, or is left untranslated for an extended period of time after this notice is posted, the page should be requested to be deleted.
Also, please make sure the article complies with the alternate languages guide.(en)
English (en)中文 (zh)Translate (Translate)

延迟着色 是一种在顶点与像素着色器完成操作后进行的屏幕空间的着色技术。顾名思义“延迟”,即将着色计算延迟到 geometry pass 之后的第二个 lighting pass。

延迟光照 (也被称作 Light Prepass) 是延迟着色的一个变体,与传统延迟渲染的 2 个 pass 不同的是,延迟光照的管线有 3 个 pass。延迟光照的管线里只有光照的着色是被延迟的,而整个着色操作本身并未被延迟。

延迟渲染使得高性能大量光源渲染得以可能。

不过,延迟光照要比延迟着色的要求更高,因为它创建了一个多的 pass。但是延迟光照只有光照着色信息会在最后的 pass 得到处理,所以它的内存开销比延迟着色低,并且延迟光照管线对半透明以及 MSAA 的支持也更好。

尽管如此, 这和起源 起源默认的辐射度( radiosity )光照(静态的)有巨大的不同(它用的是 前向渲染)。延迟渲染使用大量的 lighting pass 生成更高质量的光照,并且伴随实时阴影。

起源2 起源2 的游戏也通常使用前向渲染管线, 例如 半衰期:爱莉克斯 半衰期:爱莉克斯, 但如 Dota 2 Dota 2Deadlock Deadlock 则使用了延迟渲染。

与原版光照的区别

当编译 Valve Valve's 游戏的地图时, 每张地图必须通过 VRAD (它花费大量时间,视硬件性能和 optimizations 参数而定), VRAD 使用所有光源有关的数据并将最终光照结果覆写到 光照贴图上, 即使 VRAD 能提供高质量且多种形状的光照,然而它是完全静态的,只能提供 stationary 的光照切换,而不能提供实时变化的光照。radiosity和延迟管线的区别就在于延迟管线实时计算所有光照,并且开销低。游戏使用物体的法线、几何、Albedo 以及高光反射的信息(都来自 G-Buffer)来实时生成高质量光照。

前向管线的动态光照

前向渲染性能在过多动态光源实体(可投射阴影的 env_projectedtexture,本质上是手电筒阴影,从起源2007开始就有)。 别的类型的动态光源,例如light_dynamic,当光照贴图的分辨率很高或是光源有自己的 custom appearance 时,也会降低性能表现。另外, env_projectedtexture 也被起源 本身的默认配置所限制,也就是只有 1 个env_projectedtexture实体时才能正常工作,除非对引擎进行大幅改动。

延迟光照 (以及延迟着色) 就没有以上的问题或限制,它支持很多光照,并且性能远高于前向管道。不过,也有很多别的渲染管线,例如"Forward+/Tile-Based Forward" 或 Clustered Forward ,也可以使多动态光源渲染的性能与传统方法相比大幅降低。(例如 传送门 2:社区特供版 传送门 2:社区特供版 ,它是目前唯一一个使用 Clustered Forward 管线的起源游戏;并且还有 Operation: Black Mesa Operation: Black Mesa 正在逐步实现这个技术)。

特性

  • 高性能实时阴影和多光源渲染。
  • 支持近乎无限个动态光源 (而 Source 默认只支持 1 个 env_projectedtexture)。
  • 高保真的圣光( godrays)。
  • 体渲染(Volumetric lighting)。
  • Light cookies (预先设定的实时阴影图形状)。

缺点

  • 传统的 MSAA抗锯齿一般不会在延迟渲染管线内启用,因为它会造成极大的性能损失,由于对整个 G-Buffer 进行多重采样。例如在 Apex Legends Apex Legends 以及 黑山 黑山 里你将看不到 MSAA 的画质选项。 (黑山 黑山 将 MSAA 替换成了 FXAA,由于 MSAA 还产生了图形错误),[1] 需要再次注意的是,延迟管线的 MSAA 并不是不能用,只是不建议用。例如在异形丛生 延迟Lambda Wars 仍然可以启用 MSAA,但仍然建议使用后处理的抗锯齿(例如 FXAA,SMAA,TAA,FSR,DLSS 之类)而非着色阶段采样的抗锯齿(例如 MSAA,SSAA),这样会在延迟渲染管线内获得更好的效果以及最佳的性能。延迟管线的 MSAA 比前向管线实现的性能要求高得多,并且也更难实现。
  • 所有烘焙光照将不可用。 (存在于 异形丛生 延迟 之中)
  • 对旧式硬件的影响更大,由于延迟管线的内存带宽的要求高。不过,我们可以使用 Tile-Based 的延迟管道来减缓内存带宽带来的瓶颈。
  • 只支持 DirectX 9(SM3)或更新的图形 API, 不支持更旧的 DirectX 兼容版本。

Media

Deferred phong ref.png

应用

Source

只有少数 起源引擎 游戏使用了延迟渲染技术, 因为它很难实现。以下是应用了该技术的游戏列表:

延迟着色

延迟光照

Source 2

延迟着色

教程

也见

Entities

延迟渲染科普

参考文献

参考文献
1. Xen Technical Beta and Screenshot by [TC]Ciaиєz ITA:

Known Issues - Haloing Around Props/Object
MSAA is causing outlines around certain objects. MSSA is a performance killer and we hope to have a better solution for anti-aliasing with the Xen release. To remove the haloing/outline, simply turn off MSAA.. Retrieved on May 10, 2024.

2. Several commands related to deferred rendering such as r_deferred_ can be seen in Dota 2. Additionally, enabling MSAA via console commands in the original (Source 1) release of Dota 2 will breaks the renderer. Since April 27, 2012, it is confirmed that Dota 2 uses deferred shading, and use FXAA (referred as Screen-space Anti-aliasing when the Dota 2 page on VDC was edited in 2012)..