Set shader variables with material property values
Use material properties to set variables in ShaderLab code or in HLSL code.
읽는 시간 1분최근 업데이트: 24일 전
Using material properties to set variables in ShaderLab code
To set the value of a variable in your ShaderLab code from a material property, put the material property name in square brackets in your ShaderLab code.
This example code demonstrates the syntax for using a material property to set the value of the ShaderLab command.
unitsOffsetShader "Examples/MaterialPropertyShaderLab"{ Properties { // Change this value in the Material Inspector to affect the value of the Offset command _OffsetUnitScale ("Offset unit scale", Integer) = 1 } SubShader { // The code that defines the rest of the SubShader goes here Pass { Offset 0, [_OffsetUnitScale] // The code that defines the rest of the Pass goes here } }}
Using material properties to set variables in HLSL code
To set the value of a variable in HLSL code using a material property, give the material property the same name as the shader property.
You can see this technique in the following articles, which include working code examples: