shaoxiadiablo/Assets/AGame/Res/Shaders/MY/MYMotionShadow.shader

92 lines
2.2 KiB
Plaintext
Raw Normal View History

2025-05-18 01:04:31 +08:00
Shader "MY/MotionShadow"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_BlurSize("BlurSize", Range(0.01, 0.99)) = 0.9
_Offset("xy = uv zw = motion",Vector) = (0,0,0,0)
_Brightness("Brightness", Range(0,10)) = 1
_Flash("Flash", Range(0,1)) = 1
_Alpha("Alpha",Range(0,1)) = 1
}
SubShader
{
Tags{ "RenderType" = "Opaque" }
ZTest Off
cull Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
Name "Main"
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex:POSITION;
float2 uv:TEXCOORD0;
};
struct v2f
{
float4 pos:SV_POSITION;
float2 uv:TEXCOORD0;
};
sampler2D _MainTex;
half4 _Offset;
half _BlurSize;
half _Brightness;
//half _Saturation;
//half _Contrast;
half _Flash;
half _Alpha;
v2f vert(appdata v)
{
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = v.uv + _Offset.xy;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
//降低中心人物的运动模糊start
float r = length((i.uv.x - _Offset.z, i.uv.y - _Offset.w));
float a = _BlurSize * pow((1 - r + 0.01), 2);
col.a = max(a, 1 - _BlurSize);
//降低中心人物的运动模糊end
//亮度计算直接叠加
half3 color = col.rgb*_Brightness;
////饱和度和灰度有关,先计算最低灰度系数下的图像,随后对原始的图像进行插值操作
//fixed3 gray = fixed3(0.2125, 0.7154, 0.0721);
////点积得到最低灰度值,构成最低灰度图像
//fixed minGray = dot(gray, col.rgb);
//fixed3 grayColor = fixed3(minGray, minGray, minGray);
////对灰度图像和原始图像插值操作以得到最终系数的显示图像
//color = lerp(grayColor, color, _Saturation);
//对比度效果类似,先计算最低对比度图像,即(0.5,0.5,0.5),随后插值操作
fixed3 flash = fixed3(1, 1, 1);
color = lerp(color, flash, _Flash);
////得到所有处理完成后的图像颜色但alpha保持不变
return fixed4(color, col.a * _Alpha);
}
ENDCG
}
}
}