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
        }
    }
}
相关推荐
前端 贾公子1 天前
Eruda:移动端网页调试利器
前端·javascript·vue.js
Hashan1 天前
Elpis:抽离业务代码,发布NPM包
前端·javascript·vue.js
quikai19811 天前
python练习第六组
java·前端·python
用户47949283569151 天前
0.1加0.2为什么不等于0.3-答不上来的都挂了
前端·javascript·面试
rit84324991 天前
C#实现的远程控制系统
前端·javascript·c#
诺斯贝克1 天前
Unable to create converter for xxx.NetworkResponse<Auth> for method AuthService
前端·后端
listhi5201 天前
针对燃油运输和车辆调度问题的蚁群算法MATLAB实现
前端·算法·matlab
LRX_1989271 天前
华为设备配置练习(七)VRRP 配置
服务器·网络·华为
渔_1 天前
uni-app 页面传参总丢值?3 种方法稳如狗!
前端
快被玩坏了1 天前
二次封装了个复杂的el-table表格
前端