In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail the example analysis of Rendering Paths and LightMode in Unity3D. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Brief introduction
Unity supports different Rendering Paths. You should choose which one you use depending on your game content and target platform / hardware. Different rendering paths have different performance characteristics that mostly affect Lights and Shadows. See render pipeline for technical details.
U3D supports different Rendering Path (rendering paths). Developers should choose which Rendering Path to use according to the game content, target platform, hardware, etc. Different Rendering Path has different performance effects, and these differences are mostly reflected in the aspects of light and shadow. Check out Render Pipeline for more details.
The rendering Path used by your project is chosen in Player Settings. Additionally, you can override it for each Camera.
You can set the default Rendering Path in Player Setting or for a separate Camera.
If the graphics card can't handle a selected rendering path, Unity will automatically use a lower fidelity one. For example, on a GPU that can't handle Deferred Shading, Forward Rendering will be used.
If the graphics card of the target platform cannot handle the selected hardware, then Unity will automatically transition to low-fidelity Rendering Path. For example, if some GPU cannot handle Deferred Shading, it will automatically adopt Forward Rendering.
Let's explain the different Rendering Path in the order from high efficiency to low effect.
Overview of Deferred Shading Rendering Path
Since Deferred Shading is not commonly used in mobile development, this section does not go into detail.
LightMode Pass Tag: Deferred used in Shader
Deferred Shading has the best lighting and shadow effects. When there is a lot of real-time lighting in the scene, using Deferred Shading is also the best solution. Of course, Deferred Shading is a little more demanding on hardware.
Deferred Shading is a screen space coloring technique, so called Deferred (deferred, deferred) because the timing of Shading does not occur in the Vertex and Pixel/Fragment functions of the first Pass, but there is a delay until the second Pass.
Deferred Shading has no limit on the number of light sources that affect objects, all light sources are Per-Pixel (pixel-by-pixel) illumination, that is, all light sources can be correctly and normal mapping to get the correct calculation results. In addition, all light sources can have Light Cookie and shadows. Its performance overhead is proportional to the number of light sources, which means that the performance can be improved by controlling the illumination area and reducing the number of individual objects affected by light. Another advantage of Deferred Shading is that the results can be easily predicted. Each light source is illuminated pixel by pixel and has a consistent illumination calculation process.
The disadvantage is that it does not really support anti-aliasing and translucent objects (translucent objects are rendered using Forward Rendering). At the same time, it does not support the Receive Shadows function of the Mesh Renderer component in Unity3D, and the support for Culling Masks is not perfect, and up to four Culling Mask can be used.
Q: what is Light Cookie?
A: Light Cookie is also known as Cucoloris. It's a tip for movie production. Here are two pictures. For more information, you can see the application in Wiki,Unity3D. You can see the Unity3D Cookies manual or the implementation video process in Unity3d Spot Light Cookie,Unity3D. Click here:
Request
The graphics card should support Multiple Render Targets (MRT), Shader Model 3.0 (and higher), Depth Render Textures. Most PC graphics cards produced after 2006 support this feature.
Due to the lack of support for MRT, this feature is not supported on the mobile side. (some GPU supports it, but the degree of support is also very limited. )
Note: Deferred rendering is not applicable when using Orthographic projection (Orthographic projection). Drops to Forward Rendering when orthographic projection is used.
Performance aspect
The performance impact depends on the number of objects affected by the light source, not on the complexity of the scene. A small area of point light or spotlight, or the light source is partially or completely blocked, can well reduce the performance overhead.
The light source with shadow is more expensive, in Deferred rendering, it is affected by the projection light source, and the projectable object still needs to calculate each projection light source that affects it. Lighting Shader with shadows is certainly more expensive than no shadows.
Overview of Forward Rendering Rendering Path
LightMode Pass Tag used in Shader: ForwardBase and ForwardAdd
When Forward is not available, it will be rendered as Legacy Vertex Lit Rendering Path.
Forward is a traditional rendering path. All Unity drawing features are supported. By default, only a few of the brightest lights can become Per-Pixel lights. Other light sources are treated as Per-Vertex.
Depending on the number of lights that affect the object, Forward renders the object within a single or multiple Pass. It should be noted that the light source itself will have different characteristics depending on the setting or intensity.
User's guide
Under Forward, some of the brightest light sources (depending on the settings in Quality Setting) render objects as Per-Pixel. Four light sources can then be Per-Vetex light sources. The rest of the light sources are calculated by spherical harmonic function (SH:Spherical Harmonics), which can get the calculation results efficiently but roughly. Whether the light source is Per-Pixel or not, it depends on the following rules:
If the Render Mode of the light source is set to Not Important, it is not a Per-Pixel light source
The brightest directional light is the Per-Pixel light source
If the Render Mode of the light source is set to Important, it is the Per-Pixel light source.
If the number of per-pixel lights in the scene is less than the number of Pixel Light Count settings in Quality Setting, more lights are set to per-pixel in order of light intensity from strong to weak.
Each object is rendered according to the following rules:
Base Pass uses only one per-pixel light source, as well as all other Per-Vertex or SH light sources
Other per-pixel light sources are rendered in Additional Pass, and each Pass corresponds to a per-pixel light source.
For example, some objects are affected by the following Amurh light source:
Assume that all light sources have the same intensity and color, and that Render Mode is set to Auto. The brightest four light sources are per-pixel light source, followed by four per-vertex light sources, Dmurg G, and the last remaining light source is SH spherical harmonic light source, Gmurh H.
Notice the overlap of the light source groups in the image above. For example, the last one can be either a per-pixel light source or a per-vertex light source, so when the object or light source moves, it is less likely to produce Light Popping (abnormal picture caused by lighting).
For an example of the Light Popping problem, click here, and the questioner can finally solve it by adjusting the brightness of the light.
Light Popping phenomenon
Base Pass
Base Pass uses only one per-pixel light source and all SH/Vertex light sources to render objects. In this pass, you can also add light mapping (Lightmaps), ambient light (ambient), self-luminous (Emissive) and so on through shader. Directional light creates shadows within this Pass.
Note:
Objects that use LightMaps (baked objects) will not be illuminated by SH light sources.
When using Passflag tag "OnlyDirectional" in Shader, forward base pass will only render the main directional light, ambient light probe (Ambient/Light Probe) and Lightmap, SH and vertex light sources are not included in this pass data.
Additional Passes
Additional Passes is used to render each additional per-pixel light source. Lights in these pass do not produce shadows by default (that is, Forward Rendering defaults to only one light source that can produce shadows). Unless you use multi_compile_fwdadd_fullshadows macros.
Performance dependent
Spherical Harmonics lights (spherical harmonic illumination) is very efficient. The consumption of CPU is extremely small, and there is no additional burden on GPU (because base pass already calculates the mechanism of SH Lighting; and spherical harmonic light is light, no matter how much spherical harmonic light exists, the consumption is the same).
Extended Reading, Enlighten's simplified spherical Harmonic Lighting document, "spherical Harmonic Lighting: details", "spherical Harmonic Lighting: details" handouts, spherical Harmonic Illumination principles
Disadvantages of SH lighting:
Use the vertices of an object (the plural form of the word Vertex, the plural of Vertex can be written in three ways: vertexes,vertices, vertexs) to calculate, rather than pixels. Therefore, normal mapping and Light Cookies are not supported.
The SH lighting function is a very low frequency lighting function that does not have a very sharp lighting transition and only responds to Diffuse Lighting (diffuse reflection), which is too low for Specular Highlight (specular highlights).
SH lighting is not local; point or spot SH lights close to some surface will "look wrong". Spherical harmonic illumination is not local (? Local coordinate system? SH Light in the form of a point light or spotlight will look abnormal when it is close to some surfaces.
To sum up, SH Light is suitable for small dynamic objects.
Overview of Legacy Deferred Lighting Rendering Path
LightMode Pass Tag used in Shader: PrepassBase and PrepassFinal
Legacy Deferred (light prepass) is similar to Deferred Shading, but has a different emphasis than it uses different technologies. Physically Based Standard Shader for Unity5 is not supported. For information about the principles of Legacy Deferred, see the article "Deferred lighting approaches" on the RTR (Real-Time Rendering) website.
Deferred Lighting has been considered a traditional feature since Unity 5. 0 because it cannot support features such as Stander Shader,Reflection Probes. New projects can consider using Deferred Shading directly (not suitable for mobile platforms).
Note: Deferred Rendering Path is not applicable when using Orthographic projection. Drops to Forward Rendering Path when orthographic projection is used.
Note: both Legacy Deferred Lighting Rendering Path and Deferred Shading Rendering Path are Deferred rendering.
Deferred Lighting has no limit on the number of light sources that affect objects, all light sources are Per-Pixel lighting, that is, all light sources can be correctly and normal mapped to get the correct calculation results. In addition, all light sources can have Light Cookie and Shadow. Its performance overhead is proportional to the number of light sources, which means that the performance can be improved by controlling the illumination area and reducing the number of individual objects affected by light. Another advantage of Deferred Lighting is that the results can be easily predicted. Each light source is illuminated pixel by pixel and has a consistent illumination calculation process.
Its disadvantage is that it can not really support anti-aliasing and translucent objects (translucent objects use Forward Rendering rendering path). At the same time, it does not support the Receive Shadows function of the Mesh Renderer component in Unity3D, and the support for Culling Masks is not perfect, and up to four Culling Mask can be used.
Request
The graphics card should support Shader Model 3.0 (or newer version), Depth Render Textures,Two-sided Stencil Buffers. Most PC graphics cards produced after 2004 support this feature.
On the mobile side, all GPU that supports OpenGL ES 3.0r supports Deferred Lighting. Some OpenGL ES 2.0 GPU is also supported (because Depth Textures is supported).
Note: Deferred rendering is not applicable when using Orthographic projection (Orthographic projection). Drops to Forward Rendering when orthographic projection is used.
Performance aspect
The performance impact depends on the number of objects affected by the light source, not on the complexity of the scene. A small area of point light or spotlight, or the light source is partially or completely blocked, can well reduce the performance overhead.
The light source with shadow is more expensive, in Deferred Rendering, it is affected by the projection light source, and the projectable object still needs to calculate each projection light source that affects it. Lighting Shader with shadows is certainly more expensive than no shadows.
User's guide
With Deferred Lighting, the rendering process occurs in three kinds of Pass.
Base Pass: objects generate screen-space buffers, including depth, normals, specular power and other information.
Lighting Pass: the Scree-space buffers generated in the previous stage is used to calculate the light and put into another screen-space buffers.
Final Pass: the object is processed again, get the lighting information calculated in the previous stage, combine the color texture, and add ambient/emissive Lighting.
If the object uses Shader that is not suitable for Deferred Lighting Rendering Path, Forward rendering path will be used.
Base Pass
Base pass will deal with the object once. View sapce normals (field of view space normal) and Specular Power (highlight intensity) are processed as a Render Texture in ARGB32 format (RGB value is normals, An is Specular Power). If the target platform and hardware allow Z buffer to be read in the form of textures, no additional rendering process is required. On the contrary, it is processed in the Shader of another Pass that uses Shader Replacement.
Lighting Pass
Lighting passs calculates the light based on Depth,Normal and Specular power. Lighting calculations take place in Screen Space (screen space), so time consumption depends on the complexity of the scene. Lighting Buffer is an ARGB32 Render Texture,Diffuse Lighting that uses its RGB channel and Specular Lighting uses its A channel.
Final Pass
Processing texture, self-luminous and other content, in addition, light mapping is also done here.
Legacy Vertex Lit Rendering Path
LightMode Pass Tag used in Shader: Vertex,VertexLMRGBM and VertexLM
The effect is the worst and real-time shadows are not supported. Belongs to a subset of Forward Rendering Path. Is the highest-performing and most supported Rendering Path (but not applicable on the host).
All lighting calculations are done at the Vertex level, so most per-pixel effects, such as shadows, normal maps, Light Cookies, and fine highlights, cannot be supported.
LightMode Tags
LightMode tag defines Pass' role in the lighting pipeline. See render pipeline for details. These tags are rarely used manually; most often shaders that need to interact with lighting are written as Surface Shaders and then all those details are taken care of.
Possible values for LightMode tag are:
Always: Always rendered; no lighting is applied.
ForwardBase: Used in Forward rendering, ambient, main directional light, vertex/SH lights and lightmaps are applied.
ForwardAdd: Used in Forward rendering; additive per-pixel lights are applied, one pass per light.
Deferred: Used in Deferred Shading; renders g-buffer.
ShadowCaster: Renders object depth into the shadowmap or a depth texture.
PrepassBase: Used in legacy Deferred Lighting, renders normals and specular exponent.
PrepassFinal: Used in legacy Deferred Lighting, renders final color by combining textures, lighting and emission.
Vertex: Used in legacy Vertex Lit rendering when object is not lightmapped; all vertex lights are applied.
VertexLMRGBM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is RGBM encoded (PC & console).
VertexLM: Used in legacy Vertex Lit rendering when object is lightmapped; on platforms where lightmap is double-LDR encoded (mobile platforms).
Rendering Paths Comparison-DeferredForwardLegacy DeferredVertex LitFeatures
Per-pixel lighting (normal maps, light cookies) YesYesYes-Realtime shadowsYesWith caveatsYes-Reflection ProbesYesYes--Depth&Normals BuffersYesAdditional render passesYes-Soft ParticlesYes-Yes-Semitransparent objects-Yes-YesAnti-Aliasing-Yes-YesLight Culling MasksLimitedYesLimitedYesLighting FidelityAll per-pixelSome per-pixelAll per-pixelAll per-vertexPerformance
Cost of a per-pixel LightNumber of pixels it illuminatesNumber of pixels * Number of objects it illuminatesNumber of pixels it illuminates-Number of times objects are normally rendered1Number of per-pixel lights21Overhead for simple scenesHighNoneMediumNonePlatform Support
PC (Windows/Mac) Shader Model 3.0 + & MRTAllShader Model 3.0+AllMobile (iOS/Android) OpenGL ES 3.0 & MRTAllOpenGL ES 2.0AllConsolesXB1, PS4AllXB1, PS4, 360-the article on "sample Analysis of Rendering Paths and LightMode in Unity3D" ends here. I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.