Unity Shader Feature

Shader Feature

设置Keyword

//0:Red 1:Green 2:Blue

Mat.SetInt("_Color",0);

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

bash 复制代码
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
        }
    }
}
相关推荐
brzhang2 小时前
我操,终于有人把 AI 大佬们 PUA 程序员的套路给讲明白了!
前端·后端·架构
止观止3 小时前
React虚拟DOM的进化之路
前端·react.js·前端框架·reactjs·react
goms3 小时前
前端项目集成lint-staged
前端·vue·lint-staged
谢尔登3 小时前
【React Natve】NetworkError 和 TouchableOpacity 组件
前端·react.js·前端框架
saynaihe3 小时前
ubuntu 22.04 anaconda comfyui安装
linux·运维·服务器·ubuntu
小蜜蜂爱编程3 小时前
ubuntu透网方案
运维·服务器·ubuntu
Lin Hsüeh-ch'in3 小时前
如何彻底禁用 Chrome 自动更新
前端·chrome
头发那是一根不剩了4 小时前
nginx:SSL_CTX_use_PrivateKey failed
运维·服务器
augenstern4165 小时前
HTML面试题
前端·html
张可5 小时前
一个KMP/CMP项目的组织结构和集成方式
android·前端·kotlin