Version: Unity 6.2 Alpha (6000.2)
Language : English
Access material properties in a script
Control material properties in the Inspector window

Set shader variables with material property values

Using material properties to set variables in ShaderLab code

To set the value of a variable in your ShaderLabUnity’s language for defining the structure of Shader objects. More info
See in Glossary
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 units value of the ShaderLab Offset command.

Shader "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 shaderA program that runs on the GPU. More info
See in Glossary
property.

You can see this technique in the following articles, which include working code examples:


对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答
Access material properties in a script
Control material properties in the Inspector window
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961