Unity's Rendering Pipeline
Shaders define both how an object looks by itself (its material properties) and how it reacts to the light. Because lighting calculations must be built into the shader, and there are many possible light & shadow types, writing quality shaders that "just work" would be an involved task. To make it easier, Unity 3 introduces Surface Shaders, where all the lighting, shadowing, lightmapping, forward vs. deferred lighting things are taken care of automatically.
着色器定义一个物体的外观如何(其材料特性),以及它对光的反应。由于光照计算,必须建立到着色器中,并有可能用到许多光与阴影类型,编写高质量的着色器,“只是工作”将是一个复杂的任务。为了更方便,Unity3d介绍了Surface Shaders,其中所有的照明,阴影,lightmapping,与延迟照明的东西都被自动处理。
This document describes the pecularities of Unity's lighting & rendering pipeline and what happens behind the scenes of Surface Shaders.
本文档介绍了Unity3d灯光渲染管线的特点和表面着色的场景背后发生了什么。
Rendering Paths
渲染路径
How lighting is applied and which Passes of the shader are used depends on which Rendering Path is used. Each pass in a shader communicates its lighting type via Pass Tags.
照明被如何应用取决于着色器使用了啥样的渲染路径。在着色器中的每一个通道,通过通道标签类型来计算它的光照类型。
In
Deferred Lighting ,
PrepassBase
and
PrepassFinal
passes are used. 延迟照明,使用PrepassBase和PrepassFinal通道。
In
Forward Rendering ,
ForwardBase
and
ForwardAdd
passes are used. 正向渲染,使用ForwardBase和ForwardAdd通道。
In
Vertex Lit ,
Vertex
,
VertexLMRGBM
and
VertexLM
passes are used. 顶点光照,使用Vertex,VertexLMRGBM VertexLM通道。
In any of the above, to render
Shadows ,
ShadowCaster
and
ShadowCollector
passes are used. 在上述任何一种,都用了渲染阴影, 使用ShadowCaster 和ShadowCollector通道。
Deferred Lighting path
延迟照明路径
PrepassBase pass renders normals & specular exponent; PrepassFinal pass renders final color by combining textures, lighting & emissive material properties. All regular in-scene lighting is done separately in screen-space. SeeDeferred Lighting
PrepassBase通道渲染法线和镜面反射指数; PrepassFinal通道通过纹理,照明及发光材料的性能相结合的方式渲染最终的颜色。所有现场照明都是在屏幕空间中立完成的。延迟照明的详细信息请查看:Deferred Lighting
Forward Rendering path
正向渲染路径
ForwardBase
pass renders ambient, lightmaps, main directional light and not important (vertex/SH) lights at once.
ForwardAdd
pass is used for any additive per-pixel lights; one invocation per object illuminated by such light is done. SeeForward Rendering
ForwardBase通道渲染环境,光线贴图,主要的方向光,和不重要的 (vertex/SH) 光线被一次处理。ForwardAdd 通道被用于处理附加的逐像素光照;。一次调用使逐个物体发光。查阅正向光照细节: Forward Rendering
If forward rendering is used, but a shader does not have forward-suitable passes (i.e. neither ForwardBase nor ForwardAdd pass types are present), then that object is rendered just like it would in Vertex Lit path, see below. 如果正向渲染被使用,但着色器没有forward-suitable通道(既不存在ForwardBase的也不存在ForwardAdd通道类型),那么该对象被渲染成类似它在顶点光照路径中的那样,请参阅下文。
Vertex Lit Rendering path
顶点光照的渲染路径
Since vertex lighting is most often used on platforms that do not support programmable shaders, Unity can't create multiple shader permutations internally to handle lightmapped vs. non-lightmapped cases. So to handle lightmapped and non-lightmapped objects, multiple passes have to be written explicitly.
由于顶点光照是最常用在那些不支持可编程着色器的平台上,Unity不能创建多个着色器的排列在内部处理lightmapped与非lightmapped的情况。因此,处理多lightmapped 和non-lightmapped objects的多通道必须被显式写入。
Vertex pass is used for non-lightmapped objects. All lights are rendered at once, using a fixed function OpenGL/Direct3D lighting model (Blinn-Phong) 顶点通道用于非lightmapped对象。所有光照均被渲染一次,使用一个固定的功能OpenGL/Direct3D光照模型(Blinn-Phong)
VertexLMRGBM pass is used for lightmapped objects, when lightmaps are RGBM encoded (this happens on most desktops and consoles). No realtime lighting is applied; pass is expected to combine textures with a lightmap. VertexLMRGBM通道用于lightmapped对象,当lightmaps 是RGBM编码时(这种情况发生在大多数台式机和游戏机)。没有实时光照应用,通道通过结合纹理与光照使用。
VertexLMM pass is used for lightmapped objects, when lightmaps are double-LDR encoded (this happens on mobiles and old desktops). No realtime lighting is applied; pass is expected to combine textures with a lightmap. VertexLMM通道用于lightmapped对象,当lightmaps 是双LDR编码时候(这种情况发生在手机和旧的台式机)。没有实时光照应用,通道通过结合纹理与光照使用。