DepthOffsetSprite.shader 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. Shader "udSDK/Demo/DepthOffsetSprite"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
  6. _Color("Tint", Color) = (1,1,1,1)
  7. [MaterialToggle] PixelSnap("Pixel snap", Float) = 0
  8. _ZOffset("Z Offset", float) = 0.0
  9. }
  10. SubShader
  11. {
  12. Tags
  13. {
  14. "Queue" = "Transparent"
  15. "IgnoreProjector" = "True"
  16. "RenderType" = "Transparent"
  17. "PreviewType" = "Plane"
  18. "CanUseSpriteAtlas" = "True"
  19. }
  20. Cull Off
  21. Lighting Off
  22. ZWrite Off
  23. Blend One OneMinusSrcAlpha
  24. Pass
  25. {
  26. CGPROGRAM
  27. #pragma vertex vert
  28. #pragma fragment frag
  29. #pragma multi_compile _ PIXELSNAP_ON
  30. #include "UnityCG.cginc"
  31. fixed4 _Color;
  32. uniform float _ZOffset;
  33. struct appdata_t
  34. {
  35. float4 vertex : POSITION;
  36. float4 color : COLOR;
  37. float2 texcoord : TEXCOORD0;
  38. };
  39. struct v2f
  40. {
  41. float4 vertex : SV_POSITION;
  42. fixed4 color : COLOR;
  43. float2 texcoord : TEXCOORD0;
  44. };
  45. v2f vert(appdata_t IN)
  46. {
  47. v2f OUT;
  48. OUT.vertex = mul(UNITY_MATRIX_P,
  49. float4(UnityObjectToViewPos(IN.vertex.xyz), 1.0 + _ZOffset)
  50. );
  51. OUT.texcoord = IN.texcoord;
  52. OUT.color = IN.color * _Color;
  53. #ifdef PIXELSNAP_ON
  54. OUT.vertex = UnityPixelSnap(OUT.vertex);
  55. #endif
  56. return OUT;
  57. }
  58. sampler2D _MainTex;
  59. sampler2D _AlphaTex;
  60. float _AlphaSplitEnabled;
  61. fixed4 SampleSpriteTexture(float2 uv)
  62. {
  63. fixed4 color = tex2D(_MainTex, uv);
  64. #if UNITY_TEXTURE_ALPHASPLIT_ALLOWED
  65. if (_AlphaSplitEnabled)
  66. color.a = tex2D(_AlphaTex, uv).r;
  67. #endif
  68. return color;
  69. }
  70. fixed4 frag(v2f IN) : SV_Target
  71. {
  72. fixed4 c = SampleSpriteTexture(IN.texcoord) * IN.color;
  73. c.rgb *= c.a;
  74. return c;
  75. }
  76. ENDCG
  77. }
  78. }
  79. }