Mask2DDisplay.shader 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //Identical to Unity's UI/Default except flips UV on Y axis to account for inverted UVs from ZED.
  2. //Used in Object Detection 2D sample to draw masks inside the bounding boxes.
  3. Shader "ZED/Mask2DDisplay"
  4. {
  5. Properties
  6. {
  7. [PerRendererData] _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. [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip("Use Alpha Clip", Float) = 0
  16. }
  17. SubShader
  18. {
  19. Tags
  20. {
  21. "Queue" = "Transparent"
  22. "IgnoreProjector" = "True"
  23. "RenderType" = "Transparent"
  24. "PreviewType" = "Plane"
  25. "CanUseSpriteAtlas" = "True"
  26. }
  27. Stencil
  28. {
  29. Ref[_Stencil]
  30. Comp[_StencilComp]
  31. Pass[_StencilOp]
  32. ReadMask[_StencilReadMask]
  33. WriteMask[_StencilWriteMask]
  34. }
  35. Cull Off
  36. Lighting Off
  37. ZWrite Off
  38. ZTest[unity_GUIZTestMode]
  39. Blend SrcAlpha OneMinusSrcAlpha
  40. ColorMask[_ColorMask]
  41. Pass
  42. {
  43. Name "Default"
  44. CGPROGRAM
  45. #pragma vertex vert
  46. #pragma fragment frag
  47. #pragma target 2.0
  48. #include "UnityCG.cginc"
  49. #include "UnityUI.cginc"
  50. #pragma multi_compile_local _ UNITY_UI_CLIP_RECT
  51. #pragma multi_compile_local _ UNITY_UI_ALPHACLIP
  52. struct appdata_t
  53. {
  54. float4 vertex : POSITION;
  55. float4 color : COLOR;
  56. float2 texcoord : TEXCOORD0;
  57. UNITY_VERTEX_INPUT_INSTANCE_ID
  58. };
  59. struct v2f
  60. {
  61. float4 vertex : SV_POSITION;
  62. fixed4 color : COLOR;
  63. float2 texcoord : TEXCOORD0;
  64. float4 worldPosition : TEXCOORD1;
  65. UNITY_VERTEX_OUTPUT_STEREO
  66. };
  67. sampler2D _MainTex;
  68. fixed4 _Color;
  69. fixed4 _TextureSampleAdd;
  70. float4 _ClipRect;
  71. float4 _MainTex_ST;
  72. v2f vert(appdata_t v)
  73. {
  74. v2f OUT;
  75. UNITY_SETUP_INSTANCE_ID(v);
  76. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
  77. OUT.worldPosition = v.vertex;
  78. OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);
  79. //OUT.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
  80. OUT.texcoord = TRANSFORM_TEX(float2(v.texcoord.x, 1 - v.texcoord.y), _MainTex);
  81. OUT.color = v.color * _Color;
  82. return OUT;
  83. }
  84. fixed4 frag(v2f IN) : SV_Target
  85. {
  86. half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
  87. #ifdef UNITY_UI_CLIP_RECT
  88. color.a *= UnityGet2DClipping(IN.worldPosition.xy, _ClipRect);
  89. #endif
  90. #ifdef UNITY_UI_ALPHACLIP
  91. clip(color.a - 0.001);
  92. #endif
  93. return color;
  94. }
  95. ENDCG
  96. }
  97. }
  98. }