源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 rivejä
3.0 KiB

1 kuukausi sitten
  1. Shader "SaberShad/GrayImageEffect"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Main Texture", 2D) = "white" {}
  6. // _RPath ("RPath", Range(0, 1)) = 0.2125
  7. // _GPath ("GPath", Range(0, 1)) = 0.7154
  8. // _BPath ("BPath", Range(0, 1)) = 0.0721
  9. // _GrayAmount("GrayAmount", Range(0, 1)) = 0.5
  10. _Contrast("Contrast", float) = 1//调整对比度
  11. _Saturation("Saturation", float) = 0.63//调整饱和度
  12. _Brightness("Brightness", float) = 0.72//调整亮度(明度)
  13. _Color ("Tint", Color) = (1,1,1,0)
  14. _StencilComp ("Stencil Comparison", Float) = 8
  15. _Stencil ("Stencil ID", Float) = 0
  16. _StencilOp ("Stencil Operation", Float) = 0
  17. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  18. _StencilReadMask ("Stencil Read Mask", Float) = 255
  19. _ColorMask ("Color Mask", Float) = 15
  20. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0
  21. }
  22. SubShader
  23. {
  24. Tags
  25. {
  26. "Queue"="Transparent"
  27. "IgnoreProjector"="True"
  28. "RenderType"="Transparent"
  29. "PreviewType"="Plane"
  30. "CanUseSpriteAtlas"="True"
  31. }
  32. Stencil
  33. {
  34. Ref [_Stencil]
  35. Comp [_StencilComp]
  36. Pass [_StencilOp]
  37. ReadMask [_StencilReadMask]
  38. WriteMask [_StencilWriteMask]
  39. }
  40. Blend SrcAlpha OneMinusSrcAlpha
  41. Cull Off
  42. ZWrite Off
  43. ZTest Always
  44. ZTest [unity_GUIZTestMode]
  45. ColorMask [_ColorMask]
  46. Pass
  47. {
  48. Name "Default"
  49. CGPROGRAM
  50. #pragma vertex vert
  51. #pragma fragment frag
  52. #pragma target 2.0
  53. #include "UnityCG.cginc"
  54. #include "UnityUI.cginc"
  55. #pragma multi_compile __ UNITY_UI_ALPHACLIP
  56. struct appdata_t
  57. {
  58. float4 vertex : POSITION;
  59. float4 color : COLOR;
  60. float2 texcoord : TEXCOORD0;
  61. };
  62. struct v2f
  63. {
  64. float4 vertex : SV_POSITION;
  65. fixed4 color : COLOR;
  66. half2 texcoord : TEXCOORD0;
  67. };
  68. fixed4 _Color;
  69. float4 _ClipRect;
  70. sampler2D _MainTex;
  71. float4 _MainTex_ST;
  72. // fixed _RPath, _GPath, _BPath;
  73. fixed _Contrast, _Saturation, _Brightness;
  74. v2f vert(appdata_t IN)
  75. {
  76. v2f OUT;
  77. OUT.vertex = UnityObjectToClipPos(IN.vertex);
  78. OUT.texcoord = IN.texcoord;
  79. #ifdef UNITY_HALF_TEXEL_OFFSET
  80. OUT.vertex.xy += (_ScreenParams.zw-1.0) * float2(-1,1) * OUT.vertex.w;
  81. #endif
  82. OUT.color = IN.color * _Color;
  83. return OUT;
  84. }
  85. fixed4 frag(v2f i) : SV_Target
  86. {
  87. fixed4 col = tex2D(_MainTex, i.texcoord);
  88. //brigtness亮度
  89. fixed3 finalColor = col * _Brightness;
  90. //saturation调整饱和度
  91. fixed gray = 0.2125 * col.r + 0.7154 * col.g + 0.0721 * col.b;
  92. fixed3 grayColor = fixed3(gray, gray, gray);
  93. finalColor = lerp(grayColor, finalColor, _Saturation);
  94. //contrast调整对比度
  95. fixed3 avgColor = fixed3(0.5, 0.5, 0.5);
  96. finalColor = lerp(avgColor, finalColor, _Contrast);
  97. return fixed4(finalColor, col.a);
  98. }
  99. ENDCG
  100. }
  101. }
  102. }