ZhangZhouSpecialEquipment/Assets/mod/Materials/ControllableEmission.shader

64 lines
1.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
}
}