Zh/Deferred renderer: Difference between revisions

From Valve Developer Community
< Zh
Jump to navigation Jump to search
(Created page with "{{subst:#if: Translation of 'Deferred renderer' to '中文' via Template:LanguageBar buttons * * * * * * * * * * * * * * * * * * * * * * * * * * * *...")
 
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{subst:#if:|||{{LAuto/t}}
{{LanguageBar|title=延迟渲染 (或延迟着色/延迟光照)}}
 
__NOTOC__
--- DON'T JUST BLINDLY DELETE THIS PART. DO REPLACE THE LINKS AND CATEGORIES. THE PICTURE SHOWS HOW TO USE IT ! ---
'''[[WP:Deferred shading|延迟着色]]''' 是一种在顶点与像素着色器完成操作后进行的屏幕空间的着色技术。顾名思义“延迟”,即将着色计算延迟到 geometry pass 之后的第二个 lighting pass。
 
SEARCH FOR:
\[\[(?!#|File(?:[ _]talk)?:|Image(?:[ _]talk)?:|Media:|Template(?:[ _]talk)?:|MediaWiki(?:[ _]talk)?:|Talk:|Category[ _]talk:|Project[ _]talk:|Valve[ _]Developer[ _]Community[ _]talk:|Help[ _]talk:|User(?:[ _]talk)?:|c:|commons:|Dictionary:|Google:|GoogleGroups:|IMDB:|M:|Meta:|Metawikipedia:|MW:|SdkBug:|SourceForge:|Steampowered:|W:|Wiki:|WikiBooks:|Wikipedia:|Wikiquote:|Wiktionary:|WP:)(:?(?:Category|Category|Help|Project|Valve[ _]Developer[ _]Community|Special|)(?:[^\|\]]+))(\|?.*?)\]\]
 
REPLACE WITH:
{{subst:LAuto|$1$2}}


}}{{wip}}{{translating}}
'''[[WP:Deferred shading#Deferred lighting|延迟光照]]''' (也被称作 Light Prepass) 是延迟着色的一个变体,与传统延迟渲染的 2 个 pass 不同的是,延迟光照的管线有 3 个 pass。延迟光照的管线里只有光照的着色是被延迟的,而整个着色操作本身并未被延迟。
{{LanguageBar|title=Deferred renderer (shading & lighting)}}
__NOTOC__
'''[[WP:Deferred shading|Deferred shading]]''' is a screen-space shading technique that is performed on a second rendering pass, after the vertex and pixel shaders are rendered.


'''[[WP:Deferred shading#Deferred lighting|Deferred lighting]]''' (also known as Light Pre-Pass) is an modification of Deferred shading, which uses three passes, instead of two in deferred shading, where only the lighting calculations are deferred. The shading is still done in the initial pass, but the lighting component of the shading is calculated later.
延迟渲染使得高性能大量光源渲染得以可能。


Both deferred rendering techniques allows many lights to be rendered on the scene without a significant performance hit, however deferred lighting is slightly more demanding than deferred shading, but deferred lighting uses less memory than deferred shading, and rendering transparency & [[Anti-aliasing#MSAA|MSAA]] support is easier on deferred lighting.
不过,延迟光照要比延迟着色的要求更高,因为它创建了一个多的 pass。但是延迟光照只有光照着色信息会在最后的 pass 得到处理,所以它的内存开销比延迟着色低,并且延迟光照管线对半透明以及 [[Anti-aliasing#MSAA|MSAA]] 的支持也更好。


Nonetheless, it is much different from the default (usually static) [[radiosity]] lighting that comes with {{Src|4}} (primarily using '''Forward renderer'''). It uses many different lighting passes to generate higher quality lighting, with real-time shadows.
尽管如此, 这和{{Src|4}}默认的辐射度( [[radiosity]] )光照(静态的)有巨大的不同(它用的是 '''前向渲染''')。延迟渲染使用大量的 lighting pass 生成更高质量的光照,并且伴随实时阴影。


{{Src2|4}} games generally use forward rendering, like {{hlalyx|4}}, but games like {{d2|4}} and {{deadlock|4}} use deferred rendering.
{{Src2|4}} 的游戏也通常使用前向渲染管线, 例如 {{hlalyx|4}}, 但如 {{d2|4}} {{deadlock|4}} 则使用了延迟渲染。
==Differences from vanilla radiosity==
==与原版光照的区别==
When compiling a map in any of {{Valve|4|addtext='s}} games, each map is run through [[VRAD]] (which can take a long time depending on hardware and [[Lighting_optimization|optimizations]]), which takes data from all the light sources and compiles them into a '''lightmap''' texture. While this does provide high-quality and variable lighting, it is completely static, save for the limited ability to toggle on some lights in a scene. The difference between [[radiosity]] and deferred lighting is that deferred lighting computes all its lights in real-time, with a low performance cost ([[cheap]]). The game takes data from the normals of the object, its geometry, its albedo, and its specular lighting to create real-time accurate lighting.
当编译 {{Valve|4|addtext='s}} 游戏的地图时, 每张地图必须通过 [[VRAD]] (它花费大量时间,视硬件性能和 [[Lighting_optimization|optimizations]] 参数而定), VRAD 使用所有光源有关的数据并将最终光照结果覆写到 '''光照贴图'''上, 即使 VRAD 能提供高质量且多种形状的光照,然而它是完全静态的,只能提供 stationary 的光照切换,而不能提供实时变化的光照。[[radiosity]]和延迟管线的区别就在于延迟管线实时计算所有光照,并且开销低。游戏使用物体的法线、几何、Albedo 以及高光反射的信息(都来自 G-Buffer)来实时生成高质量光照。


==Dynamic lights in forward rendering==
==前向管线的动态光照==
Performance can be significantly reduced if there are too many dynamic light entities like {{code|[[env_projectedtexture]]}} (also used on [[player]]'s flashlight since {{src07}}) in forward rendering. Other dynamic lights such as {{code|light_dynamic}} also reduce performance if the lightmap has a small luxel scale and/or the light has [[Lightstyle|custom appearance]] (lightstyles). Additionally, {{code|env_projectedtexture}} is also limited by the {{src|1}} engine itself (by default), meaning that it only works properly with one {{code|env_projectedtexture}} entity without engine modifications.
前向渲染性能在过多动态光源实体(可投射阴影的 {{code|[[env_projectedtexture]]}},本质上是手电筒阴影,从{{src07}}开始就有)。 别的类型的动态光源,例如{{code|light_dynamic}},当光照贴图的分辨率很高或是光源有自己的 [[Lightstyle|custom appearance]] 时,也会降低性能表现。另外, {{code|env_projectedtexture}} 也被{{src|1}} 本身的默认配置所限制,也就是只有 1 个{{code|env_projectedtexture}}实体时才能正常工作,除非对引擎进行大幅改动。


Deferred lighting (and deferred shading) does not have these issues or limitations and almost an infinite number of dynamic lights can be active with faster performance than with forward rendering. However, there are also other rendering methods such as "Forward+/Tile" or [[Clustered rendering|Clustered Forward]] which can make dynamic lights less demanding on forward renderer (currently {{p2ce|2}} is the only upcoming Source game, along with {{obm|2}} utilizing this technique).
延迟光照 (以及延迟着色) 就没有以上的问题或限制,它支持很多光照,并且性能远高于前向管道。不过,也有很多别的渲染管线,例如"Forward+/Tile-Based Forward" [[Clustered rendering|Clustered Forward]] ,也可以使多动态光源渲染的性能与传统方法相比大幅降低。(例如 {{p2ce|2}} ,它是目前唯一一个使用 Clustered Forward 管线的起源游戏;并且还有 {{obm|2}} 正在逐步实现这个技术)


==Features==
==特性==
*Quite cheap real-time lighting and shadows.
*高性能实时阴影和多光源渲染。
*Almost an infinite number of dynamic lights that can be active (stock [[Source]] only allows for one {{ent|env_projectedtexture}} at a time).
*支持近乎无限个动态光源 ([[Source]] 默认只支持 1 个 {{ent|env_projectedtexture}})
*High-fidelity [[godrays]].
*高保真的圣光( [[godrays]])。
*[[Volumetric lighting]].
*体渲染([[Volumetric lighting]])。
*Light cookies (premade shadow maps).
*Light cookies (预先设定的实时阴影图形状)


==Drawbacks==
==缺点==
*Traditional anti-aliasing methods like [[MSAA]] might not work with deferred lighting and deferred shading, like in {{apex|2}} and {{bms|2}} (the latter title replaced it with FXAA because MSAA caused certain models to have a glowing outline),{{Cite|1}} but it depends how it's implemented in the game, as {{asd|1}}, and {{lw|1}} still support it, though it's recommended that you use post-processing anti-aliasing methods instead as they work best with deferred lighting, and have a smaller performance hit. MSAA is also more demanding with deferred lighting, and even more demanding on deferred shading compared to forward rendering, and MSAA is harder to implement on deferred shading, while it was easier to implement on deferred lighting.
*传统的 [[MSAA]]抗锯齿一般不会在延迟渲染管线内启用,因为它会造成极大的性能损失,由于对整个 G-Buffer 进行多重采样。例如在 {{apex|2}} 以及 {{bms|2}} 里你将看不到 MSAA 的画质选项。 ({{bms|2}} 将 MSAA 替换成了 FXAA,由于 MSAA 还产生了图形错误),{{Cite|1}} 需要再次注意的是,延迟管线的 MSAA 并不是不能用,只是不建议用。例如在{{asd|1}} {{lw|1}} 仍然可以启用 MSAA,但仍然建议使用后处理的抗锯齿(例如 FXAA,SMAA,TAA,FSR,DLSS 之类)而非着色阶段采样的抗锯齿(例如 MSAA,SSAA),这样会在延迟渲染管线内获得更好的效果以及最佳的性能。延迟管线的 MSAA 比前向管线实现的性能要求高得多,并且也更难实现。
*All lightmaps are disabled and only deferred lighting lights the world. {{only|{{asd}}}}
*所有烘焙光照将不可用。 {{only|{{asd}}}}
*Can be more taxing on older systems.
*对旧式硬件的影响更大,由于延迟管线的内存带宽的要求高。不过,我们可以使用 Tile-Based 的延迟管道来减缓内存带宽带来的瓶颈。
*DX9 SM3 or later only, older [[DirectX]] compatibility versions are not supported.
*只支持 DirectX 9(SM3)或更新的图形 API, 不支持更旧的 [[DirectX]] 兼容版本。


==Media==
==示例==
[[File:Deferred phong ref.png|800px]]
[[File:Deferred phong ref.png|800px]]


==Usage==
==应用==
=== Source ===
=== Source ===
Few {{src|1|nt=1}} games utilize this technique, as it's complicated to implement, the games that do use this are:
只有少数 {{src|1|nt=1}} 游戏使用了延迟渲染技术, 因为它很难实现。以下是应用了该技术的游戏列表:
==== Deferred shading ====
==== 延迟着色 ====
*{{Tfbranch|4}} (including {{apex|4}})
*{{Tfbranch|4}} (including {{apex|4}})
==== Deferred lighting ====
==== 延迟光照 ====
*{{asd|4}}  
*{{asd|4}}  
*{{bms|4}}
*{{bms|4}}
*{{lw|4}}
*{{lw|4}}
*{{p2d|4}}
*{{p2d|4}}
*{{hammer|4}} (Lighting Preview in stock HL2 and {{strata|4}})
*{{hammer|4}} (光照预览 in stock HL2 以及 {{strata|4}})
**{{Confirm|Hammer use Deferred lighting or shading?}}
**{{Confirm|Hammer 用了延迟渲染吗?}}
=== Source 2 ===
=== Source 2 ===
==== Deferred shading ====
==== 延迟着色 ====
* {{Dota2|4}}{{Cite|2}} (formerly {{src|1}} which also use deferred shading)
* {{Dota2|4}}{{Cite|2}} (原来的 {{src|1}} 版本也用了延迟着色)
* {{Deadlock|4}}
* {{Deadlock|4}}
* {{Hammer5|nt=0|4}}{{confirm}}
* {{Hammer5|nt=0|4}}{{confirm}}


==Tutorials==
==教程==
* [[Implementing Deferred lighting into Source 2013]]
* [[Implementing Deferred lighting into Source 2013]]


== See also ==
== 也见 ==
* {{asd|1}}
* {{asd|1}}
* [[Clustered rendering]] - similar technique, can be implemented on both forward and deferred renderer.
* [[Clustered rendering]] - 是一种提供高性能多光源渲染的解决方案,但它既可在前向管线又可在延迟管线内实现。
* [[Light editor]]
* [[Light editor]]
* [[Volumetric lighting]]
* [[Volumetric lighting]]
Line 78: Line 69:
* {{ent|light_deferred_global}}
* {{ent|light_deferred_global}}


==External links==
==延迟渲染科普==
* [https://learnopengl.com/Advanced-Lighting/Deferred-Shading Deferred Shading] on LearnOpenGL (basics)
* LearnOpenGL 的 [https://learnopengl.com/Advanced-Lighting/Deferred-Shading Deferred Shading] 基础课程
 
==译者注==
* 我们通常不对延迟着色 / 延迟光照作过于严格的区分,一般都'''统称延迟渲染'''。
* 延迟渲染只能和前向渲染这类东西并列起来,而不能像原文一样和 Radiosity 静态光照并列,俩不在一个维度上。原文作者的意图应该是'''强调在起源开发圈内,该技术实现了全动态光照。'''
* 在延迟渲染内实现静态光照是完全可以的,而非一定是原文所说的“不可用”。在一些成熟的商业化游戏引擎内,我们可以看到在延迟渲染内实现静态烘焙光照的实例(例如 Unreal Engine 的 Lightmass)。


{{references|1=
{{references|1=

Latest revision as of 18:40, 14 June 2025

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 兼容版本。

示例

Deferred phong ref.png

应用

Source

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

延迟着色

延迟光照

Source 2

延迟着色

教程

也见

Entities

延迟渲染科普

译者注

  • 我们通常不对延迟着色 / 延迟光照作过于严格的区分,一般都统称延迟渲染
  • 延迟渲染只能和前向渲染这类东西并列起来,而不能像原文一样和 Radiosity 静态光照并列,俩不在一个维度上。原文作者的意图应该是强调在起源开发圈内,该技术实现了全动态光照。
  • 在延迟渲染内实现静态光照是完全可以的,而非一定是原文所说的“不可用”。在一些成熟的商业化游戏引擎内,我们可以看到在延迟渲染内实现静态烘焙光照的实例(例如 Unreal Engine 的 Lightmass)。

参考文献

参考文献
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)..