Shader - The Unity rendering pipeline

Appearance (material properties) is used to define a shader object and its optical response, because the lighting calculations must be built in the shader, but there may be many types of lighting, it is one thing to write Shader very troublesome. To simplify the preparation Unity Shader, there is provided a Surface Shaders, it will all lighting, shadows, light maps, rendering the forward automatically rendering and processing delay.

How to choose rendering pass (Pass) and how lighting applications, what rendering path depends employed. Shaer Each Pass is suitable for what kind of rendering path is defined by PassTags of the LightMode.
Unity rendering path included are:

Rendering path Supported LightMode
Forwawrd Rendering (forward rendering) ForwardBase and ForwardAdd Pass will be used
Deferred Shading (deferred shading) Deferred Pass will be used
legacy Deferred Lighting (legacy delay light) PrepassBase and PrepassFinal Pass will be used
legacy Vertex Lit (left vertex lighting) Vertex, VertexLMRGBM and VertexLM Pass will be used
Rendering any of the aforementioned path, in order to render shadows or depth texturing, ShadowCaster Pass will be used

Forward Rendering path (forward rendering path) :
the Forward Rendering path, in the light of all the affected objects, some of the brightest pixel by pixel lamp lighting manner, then there will be four vertices wise manner light illuminates the remaining light will be rendered to SH (spherical harmonics) manner. The main rules are as follows:

1.将渲染模式设置为"Not Important"的灯始终是按顶点或者SH进行渲染
2.最亮的平行光会以逐像素的方式进行渲染。
3.将渲染模式设置为“Important”的灯始终为逐像素进行渲染。
4.最多会有4个光源按照逐顶点的方式进行渲染
5.经过以上操作后,如果逐像素渲染的灯光个数小于Quality Setting设置中Pixel Light Count的数量话,会按照亮度从高到低的顺序,选择合适的灯光数量,进行逐像素渲染。

The rendering process is as follows:

1.Forward Base Pass 会执行最亮的逐像素平行光和所有的逐顶点/SH灯光渲染。
2.Forward Add Pass 会在每个逐像素灯光(除逐像素平行光以外的)进行一次渲染。 

For example:
Here Insert Picture Description
the figure above, the object (circle) to influence by light H of A, A to H is assumed to have the same color and intensity, and all the lights are rendered automatic mode, so they will be ordered in accordance with the object distance, in front of the light will render (AD, the specific number will be set according to the data quality settings) to pixel-wise manner, and that by-vertex lighting rendering (DG, most to four lights), the remaining light will be SH (GH) in a manner for rendering. Figure:
Here Insert Picture Description

注意,在不同的模式渲染中有重叠渲染的部分,这样当物体和光线移动时,不会出现太多的"灯光跳跃"
除A灯光外,其余逐像素渲染灯光会调用Forward Add Pass。

ForwardBase: using a parallel light and a pixel-wise all SH / vertex shaders render target, in this process also adds texture shader light, ambient light from the light emitting. In this rendering process may have a directional light shading (note lightmaps objects do not obtain the illumination lamp SH).
If the "OnlyDirectional" Pass the label, ForwardBase rendering only the main channel directional light, ambient / light detector and light texture (SH light and not included in the vertex data Pass).
ForwardAdd: renders the light source for all the pixels by the primary impact of the object (except for the main parallel light). By default, these processes are not light shadows, unless the compiler directives such multi_compile_fwdadd_fullshadows, shader programs to generate a plurality of variants.
If not provide adequate shader Pass (i.e. not exist without ForwardBase ForwardAdd), the same rendering language Vertex Lit path to the object in the rendering.

SH (spherical harmonics) rendering speed is very block, and the cost is low on the CPU, in fact, free to apply GPU (ForwardBase SH illumination channels are always calculated, since SH works, so no matter how much light SH the cost is the same).
SH disadvantages are:

1.它们是在顶点的基础上进行计算,所以不支持Cookie和法线贴图
2.SH照明频率很低,无法有明显的照明过度。也只影响漫反射光照(镜面高管的频率太低)。
3.SH照明不是局部的,靠近某些表面的球谐函数点光源或聚光灯会看起来有些别扭。

Deferred shading Rendering path (coloring rendering path delay) :
When using the Deferred shading, lighting can affect the number of no GameObject limit, all the lights will be assessed by light pixel by pixel manner, they can be properly switched to the normal title FIG like, all Cookie can have lights and shadows.
Deferred shading advantages:

照明的处理开销与光照的像素数量成正比,这是由场景中光的大小决定,而不是它照亮了多少游戏物体,因此可以通过保持较小的光线来提高性能。
延迟着色也具有高度一致和可预测的行为,每个光的效果都是按像素计算的,因此没有在大三角形上分解的光照计算。

Deferred shading disadvantages:

延迟照明没有真正的抗锯齿支持,也无法处理半透明的GameObject(这些是使用Forward Rendering渲染的)。
Mesh Render(网格渲染器)和Receive Shadows(接收阴影)标志也不支持。
剔除遮蔽图的支持方式有限(最多可以使用四个剔除遮蔽图,即:剔除层遮蔽图必须至少包含减去 4 个任意层后的所有层,所以 32 层中必须设置 28 层。否则会得到图形假象。)。

Requirements:

1.需要具有多个渲染目标(MRT)的显卡,Shader Model 3.0(或以上)的图形卡,并支持深度渲染纹理。2006年后大多数pc显卡都支持延迟着色,从GeForce 8xxx,Radeon x2400,Intel G45开始。
2.移动设备上不支持,主要由于使用MRT格式(某些GPU支持多个渲染目标,但只支持非常有限的位数)。
3.使用正交投影时,不支持延迟渲染。如果相机的投影模式设置为'Orthographic(正交)',则相机会退回到“Forward Rdndering”。

Performance:
delay proportional to the number of pixels rendered overhead lighting and light coloring in real time, regardless of the complexity of the scene, so small and so light and point the spotlight on performance advantage. If they are scenes of game objects completely or partially blocked, you may get better results.
Shaded than lighting of no light shadows to spend more performance, delay in rendering, game objects cast shadows are still required for each projection light shadow rendering one or more times. Furthermore, the application of light shadow shaders higher than when not using the shadow rendering overhead.

detail:

使用延迟渲染着色时,Unity中的渲染过程分为两步:
G-buffer Pass:游戏对象被渲染成具有漫反射色、高光色、平滑度、世界空间法线、发射和深度的屏幕空间缓冲器。
Lighting Pass:先前生成的缓冲区用于将照明添加到发射缓冲区。

Not colored rendering processing delay (objects), will use the Forward Rendering path rendered after the process is complete.

默认g-buff布局:
RT0,ARGB32格式:漫反射颜色(RGB),遮挡(A)。
RT1,ARGB32格式:镜面反射颜色(RGB),粗糙度(A)。
RT2,ARGB2101010格式:世界空间标准(RGB),未使用(A)。
RT3,ARGB2101010(非HDR)或ARGBHalf(HDR)格式:Emission+lighting+lightmaps+reflectin 侦探 缓冲。
深度+模板缓冲区。

默认的g缓冲区布局时160位/像素(非HDR)或192位/像素(HDR)。
相机不使用HDR时,Emission+lighting缓冲区(RT3)以对数方式编码,以提供比ARGB32纹理通常可能的更大的动态范围。
注意,相机使用HDR渲染时,没有为Emission +光照缓冲区(RT3)创建单独的渲染目标; 相反,Camera渲染的渲染目标(即传递给图像效果的渲染目标)用作RT3。

G-Buffer Pass:
render each time Gameobject, diffuse and specular color, surface smoothness, and world space normal environmental emission + + + reflected light map texture rendered g buffer. g-buffer is provided to the texture shader global attributes, for later access Shader

Lighting Pass:
lighting g illumination buffer and a depth-based computing. Lighting is calculated in the screen space, the processing time is independent of the scene complexity. Light emission is added to the buffer.
Without passing through the camera plane near the point light source and a spotlight will be rendered as a 3D shape, and to enable the Z-buffer test scenario, which partially or completely blocked such that the points have a very light spot, and fast rendering block. Near plane passing through the point and have directional lamp / spotlight as a full screen presentation quadrilateral.
If the light is turned on shadows, they will be rendered and used in this process, the shadow is not "free" appears. We need to render shadow projector and use more sophisticated lighting shaders.
The only illumination model is available Standard, different models if necessary, can be modified illumination channel shader, a modified version of the built-in file Internal-DeferredShading.sharder shader placed Asset / Resources folder, then Edit / Project Settings / Graphics window, "Deferred" changed to "Custom shader", then this change in the use of shaders option.

Legacy Deferred Lighting Rendering Paht (Older lighting rendering path delay):
Similar Deferred shadering, From Unity5.0 version is considered to be traditional functions, because he does not support some of the rendering capabilities (e.g., standard shaders, reflective detectors, etc.).

When using delayed light, Unity of the rendering process will be divided into three steps:

1.Base Pass:渲染对象以生成具有深度,法线和镜面反射功率的屏幕空间缓冲区。
2.Light Pass:使用前面生成的缓冲区用于计算照明到另一个屏幕空空间缓冲区(唯一可用的照明模型为Blinn-Phong)。
3.Final Pass:再次渲染对象。它们获取计算出的光照,将其与颜色纹理相结合,并添加任何环境/发光照明。

Vertex Lit Rendering Path (vertex illumination path) :
Vertex Lit path typically rendered in a single pass for each object, and the object vertices calculated illumination of all light sources.
Vertex Lit is the fastest rendering path, and has the broadest hardware support (do not use with the console).
Since all the vertices in light level are computed, thus rendering this path is not supported by the majority of the pixel effect: the shadow is not supported, normal maps, Cookie and very delicate specular highlights.

Published 28 original articles · won praise 18 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_18192161/article/details/90544284