AVProVideo-Internal-UI-Default-Transparent-Android OES.shader 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. Shader "AVProVideo/Internal/UI/Transparent Packed (stereo) - AndroidOES"
  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. _VertScale("Vertical Scale", Range(-1, 1)) = 1.0
  15. [KeywordEnum(None, Top_Bottom, Left_Right)] AlphaPack("Alpha Pack", Float) = 0
  16. [KeywordEnum(None, Top_Bottom, Left_Right)] Stereo("Stereo Mode", Float) = 0
  17. [KeywordEnum(None, Left, Right)] ForceEye ("Force Eye Mode", Float) = 0
  18. [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  19. [Toggle(STEREO_DEBUG)] _StereoDebug("Stereo Debug Tinting", Float) = 0
  20. [Toggle(USE_YPCBCR)] _UseYpCbCr("Use YpCbCr", Float) = 0
  21. }
  22. SubShader
  23. {
  24. Tags
  25. {
  26. "Queue"="Transparent"
  27. "IgnoreProjector"="True"
  28. "RenderType"="Transparent"
  29. "PreviewType"="Plane"
  30. "CanUseSpriteAtlas"="True"
  31. }
  32. Stencil
  33. {
  34. Ref [_Stencil]
  35. Comp [_StencilComp]
  36. Pass [_StencilOp]
  37. ReadMask [_StencilReadMask]
  38. WriteMask [_StencilWriteMask]
  39. }
  40. Cull Off
  41. Lighting Off
  42. ZWrite Off
  43. ZTest [unity_GUIZTestMode]
  44. Fog { Mode Off }
  45. Blend SrcAlpha OneMinusSrcAlpha
  46. ColorMask [_ColorMask]
  47. Pass
  48. {
  49. GLSLPROGRAM
  50. #pragma only_renderers gles gles3
  51. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  52. #pragma multi_compile ALPHAPACK_NONE ALPHAPACK_TOP_BOTTOM ALPHAPACK_LEFT_RIGHT
  53. #pragma multi_compile MONOSCOPIC STEREO_TOP_BOTTOM STEREO_LEFT_RIGHT
  54. #pragma multi_compile FORCEEYE_NONE FORCEEYE_LEFT FORCEEYE_RIGHT
  55. #pragma multi_compile __ APPLY_GAMMA
  56. #pragma multi_compile __ STEREO_DEBUG
  57. #pragma multi_compile __ USE_YPCBCR
  58. #pragma multi_compile __ USING_DEFAULT_TEXTURE
  59. #pragma multi_compile __ USING_URP
  60. #extension GL_OES_EGL_image_external : require
  61. #extension GL_OES_EGL_image_external_essl3 : enable
  62. #if defined(APPLY_GAMMA)
  63. //#pragma target 3.0
  64. #endif
  65. #ifdef VERTEX
  66. #include "UnityCG.glslinc"
  67. #if defined(STEREO_MULTIVIEW_ON)
  68. UNITY_SETUP_STEREO_RENDERING
  69. #endif
  70. // TODO: once we drop support for Unity 4.x then we can include this
  71. //#include "UnityUI.cginc"
  72. #define SHADERLAB_GLSL
  73. #include "../AVProVideo.cginc"
  74. INLINE bool Android_IsStereoEyeLeft()
  75. {
  76. #if defined(STEREO_MULTIVIEW_ON)
  77. int eyeIndex = SetupStereoEyeIndex();
  78. return (eyeIndex == 0);
  79. #else
  80. return IsStereoEyeLeft();
  81. #endif
  82. }
  83. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  84. varying vec4 texVal;
  85. #else
  86. varying vec2 texVal;
  87. #endif
  88. #if defined(STEREO_DEBUG)
  89. varying vec4 tint;
  90. #endif
  91. uniform vec4 _MainTex_ST;
  92. uniform vec4 _MainTex_TexelSize;
  93. uniform mat4 _MainTex_Xfrm;
  94. /// @fix: explicit TRANSFORM_TEX(); Unity's preprocessor chokes when attempting to use the TRANSFORM_TEX() macro in UnityCG.glslinc
  95. /// (as of Unity 4.5.0f6; issue dates back to 2011 or earlier: http://forum.unity3d.com/threads/glsl-transform_tex-and-tiling.93756/)
  96. vec2 transformTex(vec4 texCoord, vec4 texST)
  97. {
  98. return (texCoord.xy * texST.xy + texST.zw);
  99. }
  100. void main()
  101. {
  102. #if defined(STEREO_MULTIVIEW_ON)
  103. int eyeIndex = SetupStereoEyeIndex();
  104. mat4 vpMatrix = GetStereoMatrixVP(eyeIndex);
  105. gl_Position = vpMatrix * unity_ObjectToWorld * gl_Vertex;
  106. #else
  107. gl_Position = XFormObjectToClip(gl_Vertex);
  108. #endif
  109. texVal.xy = transformTex(gl_MultiTexCoord0, _MainTex_ST);
  110. // Apply texture transformation matrix - adjusts for offset/cropping (when the decoder decodes in blocks that overrun the video frame size, it pads)
  111. texVal.xy = (_MainTex_Xfrm * vec4(texVal.x, texVal.y, 0.0, 1.0)).xy;
  112. #if defined(STEREO_TOP_BOTTOM) || defined(STEREO_LEFT_RIGHT)
  113. vec4 scaleOffset = GetStereoScaleOffset( Android_IsStereoEyeLeft(), _MainTex_ST.y < 0.0 );
  114. texVal.xy *= scaleOffset.xy;
  115. texVal.xy += scaleOffset.zw;
  116. #endif
  117. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  118. texVal = OffsetAlphaPackingUV(_MainTex_TexelSize.xy, texVal.xy, _MainTex_ST.y < 0.0);
  119. #if defined(ALPHAPACK_TOP_BOTTOM)
  120. texVal.yw = texVal.wy;
  121. #endif
  122. #endif
  123. #if defined(STEREO_DEBUG)
  124. tint = GetStereoDebugTint( Android_IsStereoEyeLeft() );
  125. #endif
  126. }
  127. #endif
  128. #ifdef FRAGMENT
  129. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  130. varying vec4 texVal;
  131. #else
  132. varying vec2 texVal;
  133. #endif
  134. #if defined(USING_DEFAULT_TEXTURE)
  135. uniform sampler2D _MainTex;
  136. #else
  137. uniform samplerExternalOES _MainTex;
  138. #endif
  139. #if defined(STEREO_DEBUG)
  140. varying vec4 tint;
  141. #endif
  142. #if defined(APPLY_GAMMA)
  143. vec3 GammaToLinear(vec3 col)
  144. {
  145. return pow(col, vec3(2.2, 2.2, 2.2));
  146. }
  147. #endif
  148. void main()
  149. {
  150. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  151. #if __VERSION__ < 300
  152. vec4 col = texture2D(_MainTex, texVal.xy);
  153. #else
  154. vec4 col = texture(_MainTex, texVal.xy);
  155. #endif
  156. #else
  157. vec4 col = vec4(1.0, 1.0, 0.0, 1.0);
  158. #endif
  159. #if defined(APPLY_GAMMA)
  160. col.rgb = GammaToLinear(col.rgb);
  161. #endif
  162. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  163. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  164. #if __VERSION__ < 300
  165. vec3 rgb = texture2D(_MainTex, texVal.zw).rgb;
  166. #else
  167. vec3 rgb = texture(_MainTex, texVal.zw).rgb;
  168. #endif
  169. col.a = (rgb.r + rgb.g + rgb.b) / 3.0;
  170. #else
  171. col.a = 1.0;
  172. #endif
  173. #endif
  174. #if defined(STEREO_DEBUG)
  175. col *= tint;
  176. #endif
  177. gl_FragColor = col;
  178. }
  179. #endif
  180. ENDGLSL
  181. }
  182. }
  183. Fallback "AVProVideo/Internal/UI/Transparent Packed (stereo)"
  184. }