ShaderLab: defining a SubShader
ShaderLab: assigning a LOD value to a SubShader
ShaderLab: assigning tags to a SubShaderThis page contains information on using a Tags
block in your ShaderLabUnityâs language for defining the structure of Shader objects. More info
See in Glossary code to assign tags to a SubShader.
For information on defining SubShader, see ShaderLab: defining a SubShader. For information on how a ShaderA program that runs on the GPU. More info
See in Glossary object works, and the relationship between Shader objects, SubShaders and Passes, see Shader objectsAn instance of the Shader class, a Shader object is container for shader programs and GPU instructions, and information that tells Unity how to use them. Use them with materials to determine the appearance of your scene. More info
See in Glossary.
Tags are key-value pairs of data. Unity uses predefined keys and values to determine how and when to use a given SubShader, or you can also create your own custom SubShader tags with custom values. You can access SubShader tags from C# code.
Render pipeline compatibility Feature name Built-in Render PipelineA series of operations that take the contents of a Scene, and displays them on a screen. Unity lets you choose from pre-built render pipelines, or write your own. More infoNote: in a custom SRP, you can define your own rendering order and choose whether or not to use render queues. For more information, see DrawingSettings and SortingCriteria.
ShaderLab: RenderType SubShader tag Yes Yes Yes Yes ShaderLab: DisableBatching SubShader tag Yes Yes Yes Yes ShaderLab: ForceNoShadowCasting SubShader tag Yes Yes YesThis disables regular shadows, but has no effect on contact shadows.
Yes ShaderLab: CanUseSpriteAtlas SubShader tag Yes Yes Yes Yes ShaderLab: PreviewType SubShader tag Yes Yes Yes Yes Using the Tags block in a SubShaderIn ShaderLab, you assign tags to a SubShader by placing a Tags
block inside a SubShader
block.
Note that both SubShaders and Passes use the Tags
block, but they work differently. Assigning SubShader tags to a Pass has no effect, and vice versa. The difference is where you put the Tags
block:
Tags
block inside a Pass
block.Tags
block inside a SubShader
block but outside a Pass
block.For information on assigning tags to a Pass, see Assigning tags to a Pass.
Signature Function Tags { â[name1]â = â[value1]â â[name2]â = â[value2]â} Applies the given tags to the SubShader.You can define as many tags as you like.
Using SubShader tags with C# codeYou can read SubShader tags from a C# script using the Material.GetTag API, like this:
using UnityEngine;
public class Example : MonoBehaviour
{
// Attach this to a gameObject that has a Renderer component
string tagName = "ExampleTagName";
void Start()
{
Renderer myRenderer = GetComponent<Renderer>();
string tagValue = myRenderer.material.GetTag(ExampleTagName, true, "Tag not found");
Debug.Log(tagValue);
}
}
RenderPipeline tag
The RenderPipeline
tag tells Unity whether a SubShader is compatible with the Universal Render Pipeline (URP) or the High Definition Render Pipeline (HDRP).
This example code declares that a SubShader is compatible with URP:
Shader "ExampleShader" {
SubShader {
Tags { "RenderPipeline" = "UniversalRenderPipeline" }
Pass {
â¦
}
}
}
Queue tag
The Queue
tag tells Unity which render queue to use for geometry that it renders. The render queue is one of the factors that determines the order that Unity renders geometry in.
You can use the Queue
tag in two ways: you can tell Unity to use a named render queue, or an unnamed render queue that it renders after a named render queue.
An example of when this is useful is in the case of transparent water, which you should draw after opaque objects but before transparent objects.
Signature Value Function [queue name] Background Specifies the Background render queue. Geometry Specifies the Geometry render queue. AlphaTest Specifies the AlphaTest render queue. Transparent Specifies the Transparent render queue. Overlay Specifies the Overlay render queue. [offset] integer Specifies the index at which Unity renders the unnamed queue, relative to the named queue. Using this tag with C# codeYou can use Shader.renderQueue to read the Queue tag value of a Shader objectâs active SubShader.
By default, Unity renders geometry in the render queue specified in the [Queue] tag. You can override this value on a per-material basis. In the Unity Editor, you can do this in the material Inspector by setting the Render Queue property. In a C# script, you can do this by setting the value of Material.renderQueue using the Rendering.RenderQueue enum.
ExamplesThis example code creates a SubShader that renders geometry as part of the Transparent render queue:
Shader "ExampleShader" {
SubShader {
Tags { "Queue" = "Transparent" }
Pass {
â¦
}
}
}
This example code creates a SubShader that renders geometry in an unnamed queue, after the Geometry queue.
Shader "ExampleShader" {
SubShader {
Tags { "Queue" = "Geometry+1" }
Pass {
â¦
}
}
}
RenderType tag
Use the RenderType
tag to override the behavior of a Shader object.
In the Built-in Render Pipeline, you can swap SubShaders at runtime using a technique called shader replacement. This technique works by identifying SubShaders that have matching RenderType
tag values. This is used in some cases to produce cameraâs depth texture.
In a render pipeline based on the Scriptable Render Pipeline, you can override the render state defined in a Shader object using a RenderStateBlock
struct. You can use the value of the RenderType
tag to identify SubShaders to override.
The RenderType
SubShader tags for Unityâs legacy built-in shaders are listed on the shader replacement page.
You can also create your own values for your custom SubShaders.
Using this tag with C# codeFor information on shader replacement in the Built-in Render Pipeline, see Shader replacement. For information on using a RenderStateBlock in the Scriptable Render Pipeline, see the API documentation for ScriptableRenderContext.DrawRenderers.
ExamplesThis example code creates a SubShader with a RenderType value of TransparentCutout
:
Shader "ExampleShader" {
SubShader {
Tags { "RenderType" = "TransparentCutout" }
Pass {
â¦
}
}
}
ForceNoShadowCasting tag
The ForceNoShadowCasting
tag prevents geometry in a SubShader from casting (and sometimes receiving) shadows. The exact behavior depends on the render pipeline and rendering pathThe technique that a render pipeline uses to render graphics. Choosing a different rendering path affects how lighting and shading are calculated. Some rendering paths are more suited to different platforms and hardware than others. More info
See in Glossary
.
This can be useful if you are using shader replacement, but you do not want to inherit a shadow pass from another SubShader.
Syntax and valid values Signature Function âForceNoShadowCastingâ = â[state]â Whether to prevent shadow casting (and sometimes receiving) for all geometry that uses this SubShader. Signature Value Function [state] True Unity prevents the geometry in this SubShader from casting shadows.In the Built in Render Pipeline, with the Forward, Legacy Vertex Lit or Legacy Deferred rendering paths, Unity also prevents the geometry in this SubShader from receiving shadows.
In HDRP, this does not prevent the geometry from casting contact shadows.
False Unity does not prevent the geometry in this SubShader from casting or receiving shadows. This is the default value. ExamplesThis example code creates a SubShader with a ForceNoShadowCasting value of True
:
Shader "ExampleShader" {
SubShader {
Tags { "ForceNoShadowCasting" = "True" }
Pass {
â¦
}
}
}
DisableBatching tag
The DisableBatching
SubShader Tag prevents Unity from applying Dynamic BatchingAn automatic Unity process which attempts to render multiple meshes as if they were a single mesh for optimized graphics performance. The technique transforms all of the GameObject vertices on the CPU and groups many similar vertices together. More info
See in Glossary
to geometry that uses this SubShader.
This is useful for shader programs that perform object space operations. Dynamic Batching transforms all geometry into world space, meaning that shader programs can no longer access object space. Shader programs that rely on object space therefore do not render correctly. To avoid this problem, use this SubShader Tag to prevent Unity from applying Dynamic Batching.
Syntax and valid values Signature Function âDisableBatchingâ = â[state]â Whether Unity prevents Dynamic Batching for all geometry that uses this SubShader. Signature Value Function [state] True Unity prevents Dynamic Batching for geometry that uses this SubShader. False Unity does not prevent Dynamic Batching for geometry that uses this SubShader. This is the default value. LODFading Unity prevents Dynamic Batching for all geometry that is part of a LODGroup with a Fade Mode value that is not None. Otherwise, Unity does not prevent Dynamic Batching. ExamplesThis example code creates a SubShader with a DisableBatching value of True
:
Shader "ExampleShader" {
SubShader {
Tags { "DisableBatching" = "True" }
Pass {
â¦
}
}
}
IgnoreProjector tag
In the Built-in Render Pipeline, the IgnoreProjector
SubShader tag tells Unity whether geometry is affected by Projectors. This is mostly useful for excluding semi-transparent geometry, which Projectors are not compatible with.
This tag has no effect in other render pipelines.
Syntax and valid values Signature Function âIgnoreProjectorâ = â[state]â Whether Unity ignores Projectors when rendering this geometry. Signature Value Function [state] True Unity ignores Projectors when rendering this geometry. False Unity does not ignore Projectors when rendering this geometry. This is the default value. ExamplesThis example code creates a SubShader with an IgnoreProjectors value of True
:
Shader "ExampleShader" {
SubShader {
Tags { "IgnoreProjector" = "True" }
Pass {
â¦
}
}
}
PreviewType tag
The PreviewType
SubShader Tag tells the Unity Editor how to display a material that uses this SubShader in the Material InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary
.
This example code creates a SubShader with an PreviewType value of Plane
:
Shader "ExampleShader" {
SubShader {
Tags { "PreviewType" = "Plane" }
Pass {
â¦
}
}
}
CanUseSpriteAtlas tag
Use this SubShader tag in projects that use the Legacy Sprite Packer to warn users that your shader relies on original texture coordinates, and that they should therefore not pack its textures into atlases.
Syntax and valid values Signature Function âCanUseSpriteAtlasâ = â[state]â Whether the Sprites that use this SubShader are compatible with the Legacy SpriteA 2D graphic objects. If you are used to working in 3D, Sprites are essentially just standard textures but there are special techniques for combining and managing sprite textures for efficiency and convenience during development. More infoWhen a SubShader with a CanUseSpriteAtlas
value of False
is used with a Sprite that has a Legacy Sprite Packer packing tag, Unity shows an error message in the Inspector.
This example code creates a SubShader with an CanUseSpriteAtlas value of False
:
Shader "ExampleShader" {
SubShader {
Tags { "CanUseSpriteAtlas" = "False" }
Pass {
â¦
}
}
}
ShaderLab: defining a SubShader
ShaderLab: assigning a LOD value to a SubShader
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4