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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. #extension GL_OES_EGL_image_external : require
  60. #extension GL_OES_EGL_image_external_essl3 : enable
  61. #if defined(APPLY_GAMMA)
  62. //#pragma target 3.0
  63. #endif
  64. #ifdef VERTEX
  65. #include "UnityCG.glslinc"
  66. #if defined(STEREO_MULTIVIEW_ON)
  67. UNITY_SETUP_STEREO_RENDERING
  68. #endif
  69. // TODO: once we drop support for Unity 4.x then we can include this
  70. //#include "UnityUI.cginc"
  71. #define SHADERLAB_GLSL
  72. #include "../AVProVideo.cginc"
  73. INLINE bool Android_IsStereoEyeLeft()
  74. {
  75. #if defined(STEREO_MULTIVIEW_ON)
  76. int eyeIndex = SetupStereoEyeIndex();
  77. return (eyeIndex == 0);
  78. #else
  79. return IsStereoEyeLeft();
  80. #endif
  81. }
  82. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  83. varying vec4 texVal;
  84. #else
  85. varying vec2 texVal;
  86. #endif
  87. #if defined(STEREO_DEBUG)
  88. varying vec4 tint;
  89. #endif
  90. uniform vec4 _MainTex_ST;
  91. uniform vec4 _MainTex_TexelSize;
  92. uniform mat4 _TextureMatrix;
  93. /// @fix: explicit TRANSFORM_TEX(); Unity's preprocessor chokes when attempting to use the TRANSFORM_TEX() macro in UnityCG.glslinc
  94. /// (as of Unity 4.5.0f6; issue dates back to 2011 or earlier: http://forum.unity3d.com/threads/glsl-transform_tex-and-tiling.93756/)
  95. vec2 transformTex(vec4 texCoord, vec4 texST)
  96. {
  97. return (texCoord.xy * texST.xy + texST.zw);
  98. }
  99. void main()
  100. {
  101. #if defined(STEREO_MULTIVIEW_ON)
  102. int eyeIndex = SetupStereoEyeIndex();
  103. mat4 vpMatrix = GetStereoMatrixVP(eyeIndex);
  104. gl_Position = vpMatrix * unity_ObjectToWorld * gl_Vertex;
  105. #else
  106. gl_Position = XFormObjectToClip(gl_Vertex);
  107. #endif
  108. texVal.xy = transformTex(gl_MultiTexCoord0, _MainTex_ST);
  109. // Apply texture transformation matrix - adjusts for offset/cropping (when the decoder decodes in blocks that overrun the video frame size, it pads)
  110. texVal.xy = (_TextureMatrix * vec4(texVal.x, texVal.y, 0.0, 1.0)).xy;
  111. #if defined(STEREO_TOP_BOTTOM) || defined(STEREO_LEFT_RIGHT)
  112. vec4 scaleOffset = GetStereoScaleOffset( Android_IsStereoEyeLeft(), _MainTex_ST.y < 0.0 );
  113. texVal.xy *= scaleOffset.xy;
  114. texVal.xy += scaleOffset.zw;
  115. #endif
  116. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  117. texVal = OffsetAlphaPackingUV(_MainTex_TexelSize.xy, texVal.xy, _MainTex_ST.y < 0.0);
  118. #if defined(ALPHAPACK_TOP_BOTTOM)
  119. texVal.yw = texVal.wy;
  120. #endif
  121. #endif
  122. #if defined(STEREO_DEBUG)
  123. tint = GetStereoDebugTint( Android_IsStereoEyeLeft() );
  124. #endif
  125. }
  126. #endif
  127. #ifdef FRAGMENT
  128. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  129. varying vec4 texVal;
  130. #else
  131. varying vec2 texVal;
  132. #endif
  133. #if defined(USING_DEFAULT_TEXTURE)
  134. uniform sampler2D _MainTex;
  135. #else
  136. uniform samplerExternalOES _MainTex;
  137. #endif
  138. #if defined(STEREO_DEBUG)
  139. varying vec4 tint;
  140. #endif
  141. #if defined(APPLY_GAMMA)
  142. vec3 GammaToLinear(vec3 col)
  143. {
  144. return pow(col, vec3(2.2, 2.2, 2.2));
  145. }
  146. #endif
  147. void main()
  148. {
  149. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  150. #if __VERSION__ < 300
  151. vec4 col = texture2D(_MainTex, texVal.xy);
  152. #else
  153. vec4 col = texture(_MainTex, texVal.xy);
  154. #endif
  155. #else
  156. vec4 col = vec4(1.0, 1.0, 0.0, 1.0);
  157. #endif
  158. #if defined(APPLY_GAMMA)
  159. col.rgb = GammaToLinear(col.rgb);
  160. #endif
  161. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  162. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  163. #if __VERSION__ < 300
  164. vec3 rgb = texture2D(_MainTex, texVal.zw).rgb;
  165. #else
  166. vec3 rgb = texture(_MainTex, texVal.zw).rgb;
  167. #endif
  168. col.a = (rgb.r + rgb.g + rgb.b) / 3.0;
  169. #else
  170. col.a = 1.0;
  171. #endif
  172. #endif
  173. #if defined(STEREO_DEBUG)
  174. col *= tint;
  175. #endif
  176. gl_FragColor = col;
  177. }
  178. #endif
  179. ENDGLSL
  180. }
  181. }
  182. Fallback "AVProVideo/Internal/UI/Transparent Packed (stereo)"
  183. }