您现在的位置是:首页 >其他 >Unity Shader Feature网站首页其他

Unity Shader Feature

Merlin-Ice 2025-08-27 00:01:05
简介Unity Shader Feature

Shader Feature

设置Keyword
//0:Red 1:Green 2:Blue
Mat.SetInt(“_Color”,0);

需要在创建时进行设置,运行时不可设置


Shader "Unlit/KeywordEnum"
{
    Properties
    {
        [KeywordEnum(Red,Green,Blue)] _Color("Color",int) = 0
    }
    SubShader
    {
        Pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            //Each keyword must start with the property name followed by _<Enum Value>. All in uppercase.
            #pragma  shader_feature _COLOR_RED _COLOR_GREEN _COLOR_BLUE

            #include "UnityCG.cginc"

            float4 vert(float4 positionOS : POSITION) : SV_POSITION
            {
                return UnityObjectToClipPos(positionOS);
            }

            float4 frag() : SV_Target
            {
                float4 color;

                #ifdef _COLOR_RED
                color = float4(1, 0, 0, 1);
                #elif _COLOR_GREEN
                color = float4(0, 1, 0, 1);
                #elif _COLOR_BLUE
                color = float4(0,0,1,1);
                #endif

                return color;
            }
            ENDHLSL
        }
    }
}

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。