Shader Tags: Understanding Unity's SubShader and Pass Functionality
1. Introduction
If you are a game developer using Unity, you may already be familiar with shaders, which are essential for creating visually stunning graphics in your games. Shaders are programs written in a special language that dictate how objects in your game world are rendered on the screen. Unity provides a powerful and flexible shader system that allows developers to control various rendering aspects, and in this article, we will delve into the world of Shader Tags, focusing on SubShader and Pass functionality.
In Unity, shaders consist of one or more SubShaders, and each SubShader contains one or more Passes. A SubShader is a collection of shaders that will be used depending on the target hardware and rendering capabilities. Within a SubShader, you can use SubShader Tags to control how the shaders behave and interact with the rendering pipeline. On the other hand, Pass Tags allow you to specify certain properties for individual Passes.
2. Understanding SubShader Tags
SubShader Tags are key-value data pairs that provide information about the SubShader. They allow you to specify certain settings that control how the SubShader is processed by the rendering pipeline. Let’s take a closer look at some essential SubShader Tags:
2.1 RenderPipeline
This tag is used to specify the render pipeline to which the SubShader is targeted. Different render pipelines have specific requirements and features, so setting the appropriate render pipeline tag is crucial for achieving the desired rendering behavior. You should set this value to UniversalPipeline for URP.
2.2 Queue
The Queue tag allows you to determine the render queue in which the SubShader should be executed. Render queues are used to control the rendering order of different objects in your scene, ensuring correct rendering and avoiding visual artifacts. This tag is very important.
2.3 RenderType
The RenderType tag defines the type of the SubShader, such as “Opaque,” “Transparent,” or “TransparentCutout.” This setting is actually not very important, but it is used to identify specific SubShaders to override using RenderStateBlocks.
2.4 DisableBatching
Batching is a technique used by Unity to optimize rendering performance by combining similar objects into a single draw call. The DisableBatching tag, when set to true, prevents Unity from batching objects using this SubShader.
2.5 ForceNoShadowCasting
If you want to exclude objects with this SubShader from casting shadows, you can use the ForceNoShadowCasting tag. In general, this would be used with override or replacement shaders.
2.6 CanUseSpriteAtlas
When using 2D sprites, the CanUseSpriteAtlas tag allows you to specify whether this SubShader can use sprite atlases for improved performance.
2.7 PreviewType
The PreviewType tag determines how the SubShader is previewed in the Unity editor’s inspector. It is useful for developers to visualize the appearance of the SubShader during development.
2.8 More Information on SubShader Tags
For more detailed information on SubShader Tags and how to use them effectively, refer to the official Unity documentation: Unity SubShader Tags
3. Exploring Pass Tags
Unlike SubShader Tags that apply to the entire SubShader, Pass Tags are specific to individual Passes within a SubShader. Passes allow you to define different rendering techniques for the same object, enabling complex and dynamic visual effects. In this section, we will cover the LightMode Pass Tag.
3.1 LightMode
The LightMode tag is used to define whether a specific Shader Pass should be rendered by a specific Render Pass. For example, when in the Deferred render path, Unity will render a GBuffer. When rendering the GBuffer, Unity looks for a Shader Pass with a LightMode of UniversalGBuffer, then renders that pass. Similarly, when rendering the Depth Texture, Unity looks for a Shader Pass with a LightMode of DepthOnly. If the corresponding Pass is not found, Unity will not render that shader for that Pass.
Create a free account, or log in.
Gain access to free articles, game development tools, and game assets.