Shader "SaberShad/GrayImageEffect"
|
|
{
|
|
Properties
|
|
{
|
|
_MainTex ("Main Texture", 2D) = "white" {}
|
|
// _RPath ("RPath", Range(0, 1)) = 0.2125
|
|
// _GPath ("GPath", Range(0, 1)) = 0.7154
|
|
// _BPath ("BPath", Range(0, 1)) = 0.0721
|
|
// _GrayAmount("GrayAmount", Range(0, 1)) = 0.5
|
|
_Contrast("Contrast", float) = 1//调整对比度
|
|
_Saturation("Saturation", float) = 0.63//调整饱和度
|
|
_Brightness("Brightness", float) = 0.72//调整亮度(明度)
|
|
_Color ("Tint", Color) = (1,1,1,0)
|
|
|
|
_StencilComp ("Stencil Comparison", Float) = 8
|
|
_Stencil ("Stencil ID", Float) = 0
|
|
_StencilOp ("Stencil Operation", Float) = 0
|
|
_StencilWriteMask ("Stencil Write Mask", Float) = 255
|
|
_StencilReadMask ("Stencil Read Mask", Float) = 255
|
|
|
|
_ColorMask ("Color Mask", Float) = 15
|
|
|
|
[Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
|
|
}
|
|
|
|
SubShader
|
|
{
|
|
Tags
|
|
{
|
|
"Queue"="Transparent"
|
|
"IgnoreProjector"="True"
|
|
"RenderType"="Transparent"
|
|
"PreviewType"="Plane"
|
|
"CanUseSpriteAtlas"="True"
|
|
}
|
|
|
|
Stencil
|
|
{
|
|
Ref [_Stencil]
|
|
Comp [_StencilComp]
|
|
Pass [_StencilOp]
|
|
ReadMask [_StencilReadMask]
|
|
WriteMask [_StencilWriteMask]
|
|
}
|
|
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
Cull Off
|
|
ZWrite Off
|
|
ZTest Always
|
|
|
|
ZTest [unity_GUIZTestMode]
|
|
ColorMask [_ColorMask]
|
|
|
|
Pass
|
|
{
|
|
Name "Default"
|
|
CGPROGRAM
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#pragma target 2.0
|
|
|
|
#include "UnityCG.cginc"
|
|
#include "UnityUI.cginc"
|
|
|
|
#pragma multi_compile __ UNITY_UI_ALPHACLIP
|
|
|
|
struct appdata_t
|
|
{
|
|
float4 vertex : POSITION;
|
|
float4 color : COLOR;
|
|
float2 texcoord : TEXCOORD0;
|
|
};
|
|
|
|
struct v2f
|
|
{
|
|
float4 vertex : SV_POSITION;
|
|
fixed4 color : COLOR;
|
|
half2 texcoord : TEXCOORD0;
|
|
};
|
|
|
|
fixed4 _Color;
|
|
float4 _ClipRect;
|
|
|
|
sampler2D _MainTex;
|
|
float4 _MainTex_ST;
|
|
// fixed _RPath, _GPath, _BPath;
|
|
fixed _Contrast, _Saturation, _Brightness;
|
|
v2f vert(appdata_t IN)
|
|
{
|
|
v2f OUT;
|
|
OUT.vertex = UnityObjectToClipPos(IN.vertex);
|
|
OUT.texcoord = IN.texcoord;
|
|
#ifdef UNITY_HALF_TEXEL_OFFSET
|
|
OUT.vertex.xy += (_ScreenParams.zw-1.0) * float2(-1,1) * OUT.vertex.w;
|
|
#endif
|
|
OUT.color = IN.color * _Color;
|
|
return OUT;
|
|
}
|
|
|
|
fixed4 frag(v2f i) : SV_Target
|
|
{
|
|
fixed4 col = tex2D(_MainTex, i.texcoord);
|
|
//brigtness亮度
|
|
fixed3 finalColor = col * _Brightness;
|
|
//saturation调整饱和度
|
|
fixed gray = 0.2125 * col.r + 0.7154 * col.g + 0.0721 * col.b;
|
|
fixed3 grayColor = fixed3(gray, gray, gray);
|
|
finalColor = lerp(grayColor, finalColor, _Saturation);
|
|
//contrast调整对比度
|
|
fixed3 avgColor = fixed3(0.5, 0.5, 0.5);
|
|
finalColor = lerp(avgColor, finalColor, _Contrast);
|
|
|
|
return fixed4(finalColor, col.a);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
}
|