AVProVideo-Internal-UI-Default-Transparent.shader 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. Shader "AVProVideo/Internal/UI/Transparent Packed (stereo)"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
  6. [PerRendererData] _ChromaTex ("Sprite Texture", 2D) = "white" {}
  7. _Color ("Tint", Color) = (1,1,1,1)
  8. _StencilComp ("Stencil Comparison", Float) = 8
  9. _Stencil ("Stencil ID", Float) = 0
  10. _StencilOp ("Stencil Operation", Float) = 0
  11. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  12. _StencilReadMask ("Stencil Read Mask", Float) = 255
  13. _ColorMask ("Color Mask", Float) = 15
  14. _ClipRect ("Clip Rect", vector) = (-32767, -32767, 32767, 32767)
  15. _VertScale("Vertical Scale", Range(-1, 1)) = 1.0
  16. [KeywordEnum(None, Top_Bottom, Left_Right)] AlphaPack("Alpha Pack", Float) = 0
  17. [KeywordEnum(None, Top_Bottom, Left_Right)] Stereo("Stereo Mode", Float) = 0
  18. [KeywordEnum(None, Left, Right)] ForceEye ("Force Eye Mode", Float) = 0
  19. [Toggle(STEREO_DEBUG)] _StereoDebug("Stereo Debug Tinting", Float) = 0
  20. [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  21. [Toggle(USE_YPCBCR)] _UseYpCbCr("Use YpCbCr", Float) = 0
  22. }
  23. SubShader
  24. {
  25. Tags
  26. {
  27. "Queue"="Transparent"
  28. "IgnoreProjector"="True"
  29. "RenderType"="Transparent"
  30. "PreviewType"="Plane"
  31. "CanUseSpriteAtlas"="True"
  32. }
  33. Stencil
  34. {
  35. Ref [_Stencil]
  36. Comp [_StencilComp]
  37. Pass [_StencilOp]
  38. ReadMask [_StencilReadMask]
  39. WriteMask [_StencilWriteMask]
  40. }
  41. Cull Off
  42. Lighting Off
  43. ZWrite Off
  44. ZTest [unity_GUIZTestMode]
  45. Fog { Mode Off }
  46. Blend SrcAlpha OneMinusSrcAlpha
  47. ColorMask [_ColorMask]
  48. Pass
  49. {
  50. CGPROGRAM
  51. #pragma vertex vert
  52. #pragma fragment frag
  53. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  54. #pragma multi_compile ALPHAPACK_NONE ALPHAPACK_TOP_BOTTOM ALPHAPACK_LEFT_RIGHT
  55. #pragma multi_compile MONOSCOPIC STEREO_TOP_BOTTOM STEREO_LEFT_RIGHT
  56. #pragma multi_compile FORCEEYE_NONE FORCEEYE_LEFT FORCEEYE_RIGHT
  57. #pragma multi_compile __ APPLY_GAMMA
  58. #pragma multi_compile __ STEREO_DEBUG
  59. #pragma multi_compile __ USE_YPCBCR
  60. #if APPLY_GAMMA
  61. //#pragma target 3.0
  62. #endif
  63. #include "UnityCG.cginc"
  64. // TODO: once we drop support for Unity 4.x then we can include this
  65. //#include "UnityUI.cginc"
  66. #include "../AVProVideo.cginc"
  67. struct appdata_t
  68. {
  69. float4 vertex : POSITION;
  70. float4 color : COLOR;
  71. float2 texcoord : TEXCOORD0;
  72. };
  73. struct v2f
  74. {
  75. float4 vertex : SV_POSITION;
  76. fixed4 color : COLOR;
  77. half4 uv : TEXCOORD0;
  78. float4 worldPosition : TEXCOORD1;
  79. };
  80. uniform fixed4 _Color;
  81. uniform sampler2D _MainTex;
  82. #if USE_YPCBCR
  83. uniform sampler2D _ChromaTex;
  84. uniform float4x4 _YpCbCrTransform;
  85. #endif
  86. uniform float4 _MainTex_TexelSize;
  87. uniform float _VertScale;
  88. uniform float4 _ClipRect;
  89. inline float UnityGet2DClipping (in float2 position, in float4 clipRect)
  90. {
  91. float2 inside = step(clipRect.xy, position.xy) * step(position.xy, clipRect.zw);
  92. return inside.x * inside.y;
  93. }
  94. v2f vert(appdata_t IN)
  95. {
  96. v2f OUT;
  97. OUT.worldPosition = IN.vertex;
  98. OUT.vertex = XFormObjectToClip(IN.vertex);
  99. #ifdef UNITY_HALF_TEXEL_OFFSET
  100. OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
  101. #endif
  102. OUT.uv.xy = IN.texcoord.xy;
  103. // Horrible hack to undo the scale transform to fit into our UV packing layout logic...
  104. if (_VertScale < 0.0)
  105. {
  106. OUT.uv.y = 1.0 - OUT.uv.y;
  107. }
  108. #if STEREO_TOP_BOTTOM | STEREO_LEFT_RIGHT
  109. float4 scaleOffset = GetStereoScaleOffset(IsStereoEyeLeft(), _MainTex_TexelSize.y < 0.0);
  110. OUT.uv.xy *= scaleOffset.xy;
  111. OUT.uv.xy += scaleOffset.zw;
  112. #endif
  113. OUT.uv = OffsetAlphaPackingUV(_MainTex_TexelSize.xy, OUT.uv.xy, _VertScale < 0.0);
  114. OUT.color = IN.color * _Color;
  115. #if STEREO_DEBUG
  116. OUT.color *= GetStereoDebugTint(IsStereoEyeLeft());
  117. #endif
  118. return OUT;
  119. }
  120. half4 frag(v2f i) : SV_Target
  121. {
  122. half4 col;
  123. #if USE_YPCBCR
  124. col = SampleYpCbCr(_MainTex, _ChromaTex, i.uv.xy, _YpCbCrTransform);
  125. #else
  126. col = SampleRGBA(_MainTex, i.uv.xy);
  127. #endif
  128. #if ALPHAPACK_TOP_BOTTOM | ALPHAPACK_LEFT_RIGHT
  129. col.a = SamplePackedAlpha(_MainTex, i.uv.zw);
  130. #endif
  131. col *= i.color;
  132. col.a *= UnityGet2DClipping(i.worldPosition.xy, _ClipRect);
  133. clip(col.a - 0.001);
  134. return col;
  135. }
  136. ENDCG
  137. }
  138. }
  139. }