TransparentNoOverlap.shader 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Custom/Depth Modulated (No Transparent Overlap)"
  3. {
  4. Properties
  5. {
  6. _MainTex ("Texture", 2D) = "white" {}
  7. _Color("Color", Color) = (1, 1, 1, 1)
  8. _BackColor("Color Behind Objects", Color) = (0.5,0.5,0.5,1)
  9. _Alpha("Total Alpha (Transparency)", Float) = 1.0
  10. }
  11. SubShader
  12. {
  13. Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" }
  14. CGINCLUDE
  15. #pragma vertex vert
  16. #pragma fragment frag
  17. #include "UnityCG.cginc"
  18. struct appdata
  19. {
  20. float4 vertex : POSITION;
  21. float2 uv : TEXCOORD0;
  22. };
  23. struct v2f
  24. {
  25. float2 uv : TEXCOORD0;
  26. float4 vertex : SV_POSITION;
  27. };
  28. sampler2D _MainTex;
  29. fixed4 _Color;
  30. fixed4 _BackColor;
  31. fixed _Alpha;
  32. v2f vert(appdata v)
  33. {
  34. v2f o;
  35. o.vertex = UnityObjectToClipPos(v.vertex);
  36. o.uv = v.uv;
  37. return o;
  38. }
  39. ENDCG
  40. Pass
  41. {
  42. Blend SrcAlpha OneMinusSrcAlpha
  43. ZTest Greater
  44. ZWrite Off
  45. Stencil {
  46. Ref 0
  47. Comp Equal
  48. Pass IncrSat
  49. }
  50. CGPROGRAM
  51. fixed4 frag (v2f i) : SV_Target
  52. {
  53. fixed4 col = tex2D(_MainTex, i.uv) * _BackColor;
  54. col.a *= _Alpha;
  55. return col;
  56. }
  57. ENDCG
  58. }
  59. Pass
  60. {
  61. Blend SrcAlpha OneMinusSrcAlpha
  62. ZTest LEqual
  63. ZWrite Off
  64. Stencil{
  65. Ref 0
  66. Comp Equal
  67. Pass IncrSat
  68. }
  69. CGPROGRAM
  70. fixed4 frag(v2f i) : SV_Target
  71. {
  72. fixed4 col = tex2D(_MainTex, i.uv) * _Color;
  73. col.a *= _Alpha;
  74. return col;
  75. }
  76. ENDCG
  77. }
  78. }
  79. }