OverlayBlend.shader 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Custom/UIScreenBlend"
  3. {
  4. Properties
  5. {
  6. [PerRendererData]
  7. _MainTex("Sprite Texture", 2D) = "white" {}
  8. _Color("Tint", Color) = (1,1,1,1)
  9. _StencilComp("Stencil Comparison", Float) = 8
  10. _Stencil("Stencil ID", Float) = 0
  11. _StencilOp("Stencil Operation", Float) = 0
  12. _StencilWriteMask("Stencil Write Mask", Float) = 255
  13. _StencilReadMask("Stencil Read Mask", Float) = 255
  14. _ColorMask("Color Mask", Float) = 15
  15. }
  16. SubShader
  17. {
  18. Tags
  19. {
  20. "Queue" = "Transparent"
  21. "IgnoreProjector" = "True"
  22. "RenderType" = "Transparent"
  23. "PreviewType" = "Plane"
  24. }
  25. Stencil
  26. {
  27. Ref[_Stencil]
  28. Comp[_StencilComp]
  29. Pass[_StencilOp]
  30. ReadMask[_StencilReadMask]
  31. WriteMask[_StencilWriteMask]
  32. }
  33. Cull Off
  34. Lighting Off
  35. ZWrite Off
  36. ZTest[unity_GUIZTestMode]
  37. Fog { Mode Off }
  38. Blend SrcAlpha OneMinusSrcAlpha
  39. ColorMask[_ColorMask]
  40. GrabPass { }
  41. Pass
  42. {
  43. CGPROGRAM
  44. #include "UnityCG.cginc"
  45. #pragma vertex ComputeVertex
  46. #pragma fragment ComputeFragment
  47. sampler2D _MainTex;
  48. sampler2D _GrabTexture;
  49. fixed4 _Color;
  50. struct VertexInput
  51. {
  52. float4 vertex : POSITION;
  53. float4 color : COLOR;
  54. float2 texcoord : TEXCOORD0;
  55. };
  56. struct VertexOutput
  57. {
  58. float4 vertex : SV_POSITION;
  59. fixed4 color : COLOR;
  60. half2 texcoord : TEXCOORD0;
  61. float4 screenPos : TEXCOORD1;
  62. };
  63. VertexOutput ComputeVertex(VertexInput vertexInput)
  64. {
  65. VertexOutput vertexOutput;
  66. vertexOutput.vertex = UnityObjectToClipPos(vertexInput.vertex);
  67. vertexOutput.screenPos = vertexOutput.vertex;
  68. vertexOutput.texcoord = vertexInput.texcoord;
  69. vertexOutput.color = vertexInput.color * _Color;
  70. return vertexOutput;
  71. }
  72. fixed4 Screen(fixed4 a, fixed4 b)
  73. {
  74. fixed4 r = 1.0 - (1.0 - a) * (1.0 - b);
  75. r.a = b.a;
  76. return r;
  77. }
  78. fixed4 ComputeFragment(VertexOutput vertexOutput) : SV_Target
  79. {
  80. half4 color = tex2D(_MainTex, vertexOutput.texcoord) * vertexOutput.color;
  81. float2 grabTexcoord = vertexOutput.screenPos.xy / vertexOutput.screenPos.w;
  82. grabTexcoord.x = (grabTexcoord.x + 1.0) * .5;
  83. grabTexcoord.y = (grabTexcoord.y + 1.0) * .5;
  84. #if UNITY_UV_STARTS_AT_TOP
  85. grabTexcoord.y = 1.0 - grabTexcoord.y;
  86. #endif
  87. fixed4 grabColor = tex2D(_GrabTexture, grabTexcoord);
  88. return Screen(grabColor, color);
  89. }
  90. ENDCG
  91. }
  92. }
  93. Fallback "UI/Default"
  94. }