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
        }
    }
}
相关推荐
电子羊4 分钟前
Spec 编程工作流文档
前端
GISer_Jing11 分钟前
从CLI到GUI桌面应用——前端工程化进阶之路
前端·人工智能·aigc·交互
还是大剑师兰特28 分钟前
Vue3 报错:computed value is readonly 解决方案
前端·vue.js
leaves falling36 分钟前
有效的字母异位词
java·服务器·前端
We་ct44 分钟前
LeetCode 35. 搜索插入位置:二分查找的经典应用
前端·算法·leetcode·typescript·个人开发
左耳咚1 小时前
Claude Code 中的 SubAgent
前端·ai编程·claude
FPGA小迷弟1 小时前
高频时钟设计:FPGA 多时钟域同步与时序收敛实战方案
前端·学习·fpga开发·verilog·fpga
IT古董1 小时前
【前端】企业级前端调试体系设计(含日志埋点 + Eruda 动态注入 + Sentry)
前端·sentry
gis开发1 小时前
cesium 中添加鹰眼效果
前端·javascript
前端付豪1 小时前
Memory V1:让 AI 记住你的关键信息
前端·后端·llm