AK056/Assets/GameLogic/Origin/shader/AlarmFlash.shader

67 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 "Custom/AlarmFlash"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {} // 主纹理
_BaseColor ("Base Color", Color) = (1,1,1,1) // 原始颜色
_FlashColor ("Flash Color", Color) = (1,0,0,1) // 报警颜色(红色)
_FlashSpeed ("Flash Speed", Float) = 1.0 // 闪烁速度
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float4 _BaseColor;
float4 _FlashColor;
float _FlashSpeed;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// 根据时间生成闪烁因子0~1
float t = sin(_Time.y * _FlashSpeed);
float flashFactor = abs(t); // 将 -1~1 映射为 0~1
// 混合基础色和红色
fixed4 baseColor = tex2D(_MainTex, i.uv) * _BaseColor;
fixed4 finalColor = lerp(baseColor, _FlashColor, flashFactor);
return finalColor;
}
ENDCG
}
}
}