Article directory
Preface
In the previous article, we got the simplest URP Shader.
In this article, let's take a look at URP Shader's constant buffer CBUFFER.
1. Steps to use constant buffer CBUFFER
使用步骤和BRP下的属性使用步骤几乎一致
1. Define the attributes we need to use in the attribute panel
Properties
{
_Color("Color",Color) = (0,0,0,0)
}
2. In Pass, you need to declare it in advance before using it.
这里声明,必须声明在 这 两个标识中间 才能发挥 常量缓冲区 的作用。
CBUFFER_START(UnityPerMaterial)
half4 _Color;
CBUFFER_END
-
What do these two logos do?
-
UnityPerMaterial represents the data in our property panel
-
After this declaration, our programmable rendering pipeline can be allowed to be batched
-
Without using a constant buffer, programmable rendering pipeline batching is not allowed.
3. When using, just use it directly
half4 frag(Varyings i) : SV_TARGET
{
half4 c;
c = _Color;
return c;
}
2. Benefits of using constant buffer CBUFFER
Ability to support our Shader being allowed by SRP Batcher (Programmable Rendering Pipeline Batch), thus saving rendering performance.
3. ShaderGraph attributes and corresponding Shader functions
1. We create a color attribute
2. Use (drag it out from the properties panel and connect the output to the color input port)
3. ShaderGraph uses the constant buffer CBUFFER by default.
- Let’s compile and take a look