Shader "Unlit/ControllableEmission" { Properties { _MainColor ("基础颜色", Color) = (1,1,1,1) // 物体本身颜色 _EmissionColor ("发光颜色", Color) = (1,1,1,1) // 发光颜色 _EmissionIntensity ("发光强度", Range(0, 20)) = 1 // 发光强度 //_FlickerSpeed ("闪烁速度(0=不闪烁)", Range(0, 10)) = 0 // 可选:闪烁效果 } SubShader { Tags { "RenderType"="Opaque" "Queue"="Geometry" } LOD 100 Pass { CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" // 顶点输入 struct appdata { float4 vertex : POSITION; }; // 片元输入 struct v2f { float4 pos : SV_POSITION; }; // Properties变量 fixed4 _MainColor; fixed4 _EmissionColor; float _EmissionIntensity; //float _FlickerSpeed; // 顶点着色器 v2f vert (appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); // 转换顶点到裁剪空间 return o; } // 片元着色器(计算最终颜色) fixed4 frag (v2f i) : SV_Target { // 基础颜色 fixed4 col = _MainColor; // 计算发光强度(可选:添加闪烁效果) float intensity = _EmissionIntensity; // if (_FlickerSpeed > 0) { // intensity *= 0.5 + 0.5 * sin(_Time.y * _FlickerSpeed); // 0.5~1之间波动 // } // 叠加自发光(发光颜色 * 强度) col.rgb += _EmissionColor.rgb * intensity; return col; } ENDCG } } }