This page details the Deferred Shading rendering pathThe technique Unity uses to render graphics. Choosing a different path affects the performance of your game, and how lighting and shading are calculated. Some paths are more suited to different platforms and hardware than others. More info
See in Glossary in Unity’s Built-in Render Pipeline. See Wikipedia: deferred shading for an introductory technical overview of deferred shading.
When using deferred shading, there is no limit on the number of lights that can affect a GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary. All lights are evaluated per-pixel, which means that they all interact correctly with normal mapsA type of Bump Map texture that allows you to add surface detail such as bumps, grooves, and scratches to a model which catch the light as if they are represented by real geometry. More info
See in Glossary, etc. Additionally, all lights can have cookies and shadows.
Deferred shading has the advantage that the processing overhead of lighting is proportional to the number of pixelsThe smallest unit in a computer image. Pixel size depends on your screen resolution. Pixel lighting is calculated at every screen pixel. More info
See in Glossary the light shines on. This is determined by the size of the light volume in the SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary regardless of how many GameObjects it illuminates. Therefore, performance can be improved by keeping lights small. Deferred shading also has highly consistent and predictable behaviour. The effect of each light is computed per-pixel, so there are no lighting computations that break down on large triangles.
On the downside, deferred shading has no real support for anti-aliasing and can’t handle semi-transparent GameObjects (these are rendered using forward rendering). There is also no support for the MeshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary Renderer’s Receive Shadows flag and culling masksAllows you to include or omit objects to be rendered by a Camera, by Layer.
See in Glossary are only supported in a limited way. You can only use up to four culling masks. That is, your culling layer maskA value defining which layers to include or exclude from an operation, such as rendering, collision or your own code. More info
See in Glossary must at least contain all layers minus four arbitrary layers, so 28 of the 32 layers must be set. Otherwise you get graphical artifacts.
It requires a graphics card with Multiple Render Targets (MRT), ShaderA program that runs on the GPU. More info
See in Glossary Model 3.0 (or later) and support for Depth render texturesA special type of Texture that is created and updated at runtime. To use them, first create a new Render Texture and designate one of your Cameras to render into it. Then you can use the Render Texture in a Material just like a regular Texture. More info
See in Glossary. Most PC graphics cards made after 2006 support deferred shading, starting with GeForce 8xxx, Radeon X2400, Intel G45.
On mobile, deferred shading is supported on all devices running at least OpenGL ES 3.0.
Note: Deferred renderingThe process of drawing graphics to the screen (or to a render texture). By default, the main camera in Unity renders its view to the screen. More info
See in Glossary isn’t supported when using Orthographic projection. If the CameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary’s projection mode is set to Orthographic, the Camera falls back to Forward rendering.
Note: Deferred Rendering doesn’t support Single Pass Stereo Instancing in the Built-in Render Pipeline..
The rendering overhead of real-time lights in deferred shading is proportional to the number of pixels illuminated by the light and not dependent on Scene complexity. So small point or Spot Lights are very cheap to render and if they are fully or partially occluded by Scene GameObjects then they are even cheaper.
Of course, lights with shadows are much more expensive than lights without shadows. In deferred shading, shadow-casting GameObjects still need to be rendered once or more for each shadow-casting light. Furthermore, the lighting shader that applies shadows has a higher rendering overhead than the one used when shadows are disabled.
Objects with Shaders that do not support deferred shading are rendered after deferred shading is complete, using the forward renderingA rendering path that renders each object in one or more passes, depending on lights that affect the object. Lights themselves are also treated differently by Forward Rendering, depending on their settings and intensity. More info
See in Glossary path.
The default layout of the render targets (RT0 - RT4) in the G-buffer is listed below. Data types are placed in the various channels of each render target. The channels used are shown in parentheses.
So the default G-buffer layout is 160 bits/pixel (non-HDR) or 192 bits/pixel (HDR).
And thus the G-buffer layout is 192 bits/pixel (non-HDR) or 224 bits/pixel (HDR).
If the hardware does not support five concurrent rendertargets then objects using shadowmasks will fallback to the forward rendering path.
Emission+lighting buffer (RT3) is logarithmically encoded to provide greater dynamic range than is usually possible with an ARGB32 texture, when the Camera is not using HDRhigh dynamic range
See in Glossary.
Note that when the Camera is using HDR rendering, there’s no separate rendertarget being created for Emission+lighting buffer (RT3); instead the rendertarget that the Camera renders into (that is, the one that is passed to the image effects) is used as RT3.
The G-buffer pass renders each GameObject once. Diffuse and specular colors, surface smoothness, world space normal, and emission+ambient+reflections+lightmaps are rendered into G-buffer textures. The G-buffer textures are setup as global shader properties for later access by shaders (CameraGBufferTexture0 .. CameraGBufferTexture3 names).
The lighting pass computes lighting based on G-buffer and depth. Lighting is computed in screen space, so the time it takes to process is independent of Scene complexity. Lighting is added to the emission buffer.
Point and Spot Lights that do not cross the Camera’s near plane are rendered as 3D shapes, with the Z buffer’s test against the Scene enabled. This makes partially or fully occluded point and Spot Lights very cheap to render. Directional lights and point/Spot Lights that cross the near plane are rendered as fullscreen quadsA primitive object that resembles a plane but its edges are only one unit long, it uses only 4 vertices, and the surface is oriented in the XY plane of the local coordinate space. More info
See in Glossary.
If a light has shadows enabled then they are also rendered and applied in this pass. Note that shadows do not come for “free”; shadow casters need to be rendered and a more complex light shader must be applied.
The only lighting model available is Standard. If a different model is wanted you can modify the lighting pass shader, by placing the modified version of the Internal-DeferredShading.shader file from the Built-in shaders into a folder named “Resources” in your “Assets” folder. Then open the Graphics settings (menu: Edit > Project Settings, then click the Graphics category). Change the “Deferred” dropdown to “Custom Shader”. Then change the Shader option which appears to the shader you are using.
2017–06–08 Page published
Light Modes (ShadowmaskA Texture that shares the same UV layout and resolution with its corresponding lightmap. More info
See in Glossary and Distance ShadowmaskA version of the Shadowmask lighting mode that includes high quality shadows cast from static GameObjects onto dynamic GameObjects. More info
See in Glossary) added in 5.6