Unity3d Illumination Pre-knowledge--rendering Paths (rendering path) and Lightmode (illumination mode) translation solution

Source: Internet
Author: User
Tags unity 5

Briefly

Unity supports different Rendering Paths. You should choose which one of the depending on your game content and target platform/hardware. Different rendering paths has Different performance characteristics that mostly affect Lights and Shadows. See render pipeline for technical details.

U3D supports different rendering path (render path), developers should choose which rendering path to use based on game content and target platform, hardware, etc. Different rendering paths have different performance effects, many of which are reflected in light and shadow. Check the render pipeline for more details.

The rendering Path used by your project are chosen in Player Settings. Additionally, you can override it for each Camera.

You can set the default rendering Path in Player setting, or you can set it for a separate camera.

If the graphics card can ' t handle a selected rendering path, Unity would automatically use a lower fidelity one. For example, the on a GPUs that can ' t handle Deferred shading, Forward Rendering would be used.

If the target platform's graphics card is not able to handle the selected hardware, unity will automatically transition to a low-fidelity grade rendering path. For example, some GPUs can not handle deferred shading, it will automatically adopt forward Rendering.

The following rendering Path is explained in order from high effect to low effect.

Deferred Shading Rendering Path overview

Because deferred shading is not commonly used in mobile development, this section is not described in detail.

Lightmode Pass tag:deferred used in shader

The Deferred shading has the best lighting and shading effects. Using deferred shading is also the best solution when there is a lot of real-time lighting in the scene. Of course deferred shading has a slightly higher requirement for hardware.

Deferred shading is a screen space coloring technique that is called Deferred (delayed, postponed) because the timing of the shading is not within the vertex and pixel/fragment functions of the first pass, but there is a delay, It is not executed until the second pass.

Deferred shading has no limit on the number of light sources that affect an object, all light sources are per-pixel (per pixel) illumination, that is, all light sources can be correctly computed with normal maps. In addition, all lights can have light cookies and shadows. The performance overhead is proportional to the number of light sources, which means a performance boost can be achieved by controlling the amount of light affected by the light area and reducing the number of individual objects affected by the illumination. Another advantage of Deferred shading is that the results can be easily predicted by a light source that is pixel-wise, with a consistent light calculation process.

The downside is that it doesn't really support antialiasing and translucent objects (translucent objects are rendered using Forward Rendering). It also does not support the receive shadows function of the mesh renderer component in Unity3d, and the support for culling masks is not perfect, up to four culling masks can be used.

Q: What is a light Cookie?
A:light cookies are also known as Cucoloris. is an application in the filming of the small tricks, the following two pictures, specific explanations can be viewed in Wiki,unity3d application can view the Unity3d cookies manual or Unity3d Spot light cookies, The implementation video process in Unity3d can be clicked here:

Requirements

The graphics card should support multiple render Targets (MRT), Shader Model 3.0 (and higher), Depth render textures. Most PC graphics from 2006 onwards support this feature.
Because of the lack of support for MRT function, this feature is not supported on mobile side. (some GPU support, but the degree of support is very limited.) )
Note: Deferred rendering is not applicable when using orthographic projection (orthographic projection). When orthogonal projections are used, they are reduced to Forward Rendering.

Performance aspects

The performance impact depends on the number of objects affected by the light source, not the complexity of the scene. A small area of point light or spotlight, or a light source that is partially or completely blocked, can be a good way to reduce performance overhead.

Shaded light sources are more expensive in deferred rendering, which are affected by the projection light, and the objects that can be projected remain to be computed for each projection light that affects them. Shaded light shader is also certainly more expensive than no shadow.

Forward Rendering Rendering Path overview

Lightmode Pass tag:forwardbase and Forwardadd used in shader
Renders with legacy Vertex Lit Rendering Path effect when forward is not available

Forward is a traditional rendering path. All Unity graphics features are supported. By default, only a few of the brightest light sources can become per-pixel light sources. Other light sources are considered per-vertex.

Depending on the number of light sources affecting the object, Forward renders the object within a single or multiple passes. It is important to note that depending on the setting or intensity, the light source itself will have different characteristics.

User Guide

Forward, some (depending on the setting in quality setting) the brightest light source renders the object in per-pixel manner. Then there are four light sources for the Per-vetex light source. The rest of the light sources are calculated using the spherical harmonic function (sh:spherical harmonics), which is efficient but rough to get the results. Whether the light source is per-pixel or not is dependent 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 parallel light per-pixel
    • The source's render mode is set to important, then 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 will be set to per-pixel in order of light intensity from strong to weak.

Each object is rendered according to the following rules:

    • Base Pass will only use one per-pixel light source, and all other per-vertex or sh light sources
    • Other Per-pixel light sources are rendered in the additional pass, and each pass corresponds to a per-pixel light source

For example, an object is affected by the following a-h light source:

Assume that all light sources have the same strength and color, and that render mode is set to Auto. The brightest of the 4 light source a-d is the per-pixel light source, followed by four Per-vertex light source, D-g, the last remaining light source is the sh spherical harmonic light source, g-h.

Notice the overlapping part of the middle Light group. For example, the last one can be either a per-pixel light source or a per-vertex light source, so when an object or light source moves, it is less likely to produce light popping (the picture is not normal due to illumination).

For an example of light popping problem, click here, the questioner finally adjusts the illumination brightness to solve.

Light popping phenomenon

Base Pass

The Base pass uses only one per-pixel light source and all Sh/vertex light sources to render the object. In this pass can also be added by shader light map (lightmaps), ambient light (ambient), self-illumination (emissive) and so on. The parallel light creates a shadow within the pass.

Attention:

    • objects that use Lightmaps (baked objects) are not illuminated by the SH light source.
    • When using Passflag tag "onlydirectional" in shader, the forward base pass will only render the main parallel light, ambient light probe (Ambient/light Probe) and illumination map, The SH and vertex light sources are not included in the data for this pass.
Additional Passes

The Additional passes is used to render each additional per-pixel light source. The light source in these passes does not produce a shadow by default (that is, Forward rendering only supports one light source to produce a shadow by default). Unless you use the Multi_compile_fwdadd_fullshadows macro.

Performance-related

Spherical harmonics lights (spherical harmonic illumination) is very efficient. The CPU consumption is very small, there is no additional burden on the GPU (because the base pass will always calculate the sh Lighting; and the mechanism of spherical harmonic illumination has light, no matter how many spherical harmonic light exists, the consumption is the same).

Extended reading, enlighten's simplified spherical harmonic illumination document, spherical harmonic illumination: detail, spherical harmonic illumination: detail handout, spherical harmonic illumination principle

The disadvantages of SH illumination:

    • Using the vertices of an object (the plural form of a vertex word, the plural of the vertex is written in three ways: Vertexes,vertices, vertexs), not pixels. Normal maps and light Cookies are therefore not supported.
    • The SH illumination function is a very low-frequency illumination function that does not have a very sharp illumination 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 would "look wrong". Spherical harmonic illumination is not local (? Local coordinate system? ), the SH light in the form of a point or spotlight may not look normal when it is close to some surface.

In conclusion, SH light is suitable for small dynamic objects.

Legacy Deferred Lighting Rendering Path overview

Lightmode Pass tag:prepassbase and prepassfinal used in shader

Legacy Deferred (light prepass) is similar to Deferred shading, but has different emphasis on its use of different techniques. Unity5 physically Based standard Shader are not supported. The legacy Deferred principle can be seen in the RTR (real-time Rendering) website of the article "Deferred Lighting Approaches"

Deferred Lighting is considered a traditional feature from Unity 5.0 because it cannot support features such as Stander shader,reflection probes. The new project may consider using Deferred shading directly (not for mobile platforms).

Note: Deferred Rendering Path does not apply when orthographic projection is used. When using orthographic projections, it drops to Forward Rendering Path.
Note: 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 an object, all light sources are per-pixel light, that is, all light sources can be correctly calculated and the normal map is correct. In addition, light cookies and shadow are available for all lights. The performance overhead is proportional to the number of light sources, which means a performance boost can be achieved by controlling the amount of light affected by the light area and reducing the number of individual objects affected by the illumination. Another advantage of Deferred lighting is that the results can be easily predicted by a light source that is pixel-wise, with a consistent light calculation process.

The disadvantage is that it does not really support antialiasing and translucent objects (translucent objects with Forward Rendering render paths). It also does not support the receive shadows function of the mesh renderer component in Unity3d, and the support for culling masks is not perfect, up to four culling masks can be used.

Requirements

The graphics card should support shader Model 3.0 (or later version), Depth Render textures,two-sided stencil buffers. Most PC graphics from 2004 onwards support this feature.
On the mobile side, all OpenGL ES 3.0r GPUs support deferred Lighting. Some OpenGL ES 2.0 GPUs can also be supported (because depth textures is supported).
Note: Deferred rendering is not applicable when using orthographic projection (orthographic projection). When orthogonal projections are used, they are reduced to Forward Rendering.

Performance aspects

The performance impact depends on the number of objects affected by the light source, not the complexity of the scene. A small area of point light or spotlight, or a light source that is partially or completely blocked, can be a good way to reduce performance overhead.

Shaded light sources are more expensive in deferred rendering, which are affected by the projection light, and the objects that can be projected remain to be computed for each projection light that affects them. Shaded light shader is also certainly more expensive than no shadow.

User Guide

With deferred Lighting, the rendering process takes place within three passes.

    1. Base Pass: Object generated screen-space buffers, including depth, normals, specular power and other information.
    2. Lighting Pass: The scree-space buffers generated in the previous phase is used to calculate the light and put another screen-space buffers.
    3. Final Pass: The object is processed again, obtaining the light information calculated from the previous stage, combining the color texture and adding ambient/emissive Lighting.

If the object uses a shader that does not apply to the deferred Lighting Rendering path, the forward Rendering path is used

Base Pass

The Base pass will handle the object once. View Sapce normals (visual field normals) and specular Power (highlight intensity) are processed into a ARGB32 format render Texture (RGB values are normals, A is specular power). If the target platform and hardware allow Z buffer to be read as a texture, no additional rendering process is necessary. Conversely, it is to be processed in another pass using the shader replacement shader.

Lighting Pass

Lighting PASSS calculates lighting based on depth,normal and specular power. Light calculations occur in screen space, so time consumption depends on how complex the scene is. Lighting buffer is a ARGB32 render Texture,diffuse Lighting uses its RGB channel, specular Lighting uses its a channel.

Final Pass

Handle textures, spontaneous light and other content, and the illumination map is also done here.

Legacy Vertex Lit Rendering Path

Use of Lightmode Pass TAG:VERTEX,VERTEXLMRGBM and vertexlm used in shader

The result is the worst and does not support real-time shading. belongs to a subset of forward Rendering path. is the highest performance, most supported rendering Path (but not on the host).
All lighting calculations are done at the vertex level and therefore cannot support most of the per-pixel effects, such as shadows, normal maps, light Cookies, fine-grained high-gloss effects.

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, need to interact with lighting is written as Surface shaders and then all those details is taken Care of.

Possible values for Lightmode tag is:

Always:always rendered; No lighting is applied.
Forwardbase:used in Forward rendering, ambient, main directional light, vertex/sh lights and lightmaps is applied.
Forwardadd:used in Forward rendering; Additive Per-pixel Lights is 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 is 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
- Deferred Forward Legacy Deferred Vertex Lit
Features
Per-pixel Lighting (normal maps, light cookies) Yes Yes Yes -
Realtime Shadows Yes With caveats Yes -
Reflection Probes Yes Yes - -
Depth&normals buffers Yes Additional Render Passes Yes -
Soft particles Yes - Yes -
Semitransparent objects - Yes - Yes
Anti-aliasing - Yes - Yes
Light culling masks Limited Yes Limited Yes
Lighting Fidelity All Per-pixel Some Per-pixel All Per-pixel All Per-vertex
Performance
Cost of a per-pixel light Number of pixels it illuminates Number of pixels * Number of objects it illuminates Number of pixels it illuminates -
Number of times objects is normally rendered 1 Number of Per-pixel lights 2 1
Overhead for simple scenes High None Medium None
Platform Support
PC (WINDOWS/MAC) Shader Model 3.0+ & MRT All Shader Model 3.0+ All
Mobile (ios/android) OpenGL ES 3.0 & MRT All OpenGL ES 2.0 All
Consoles XB1, PS4 All XB1, PS4, 360 -
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. 53006708

Unity3d Illumination Pre-knowledge--rendering Paths (render path) and Lightmode (illumination mode) translation solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.