AVProVideo-Internal-UI-AndroidOES.shader 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. Shader "AVProVideo/Internal/UI/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. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  15. [KeywordEnum(None, Top_Bottom, Left_Right)] Stereo("Stereo Mode", Float) = 0
  16. [Toggle(STEREO_DEBUG)] _StereoDebug("Stereo Debug Tinting", Float) = 0
  17. [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  18. }
  19. SubShader
  20. {
  21. Tags
  22. {
  23. "Queue" = "Transparent"
  24. "IgnoreProjector" = "True"
  25. "RenderType" = "Transparent"
  26. "PreviewType" = "Plane"
  27. "CanUseSpriteAtlas" = "True"
  28. }
  29. Stencil
  30. {
  31. Ref[_Stencil]
  32. Comp[_StencilComp]
  33. Pass[_StencilOp]
  34. ReadMask[_StencilReadMask]
  35. WriteMask[_StencilWriteMask]
  36. }
  37. Cull Off
  38. Lighting Off
  39. ZWrite Off
  40. ZTest[unity_GUIZTestMode]
  41. Fog{ Mode Off }
  42. Blend SrcAlpha OneMinusSrcAlpha
  43. ColorMask[_ColorMask]
  44. Pass
  45. {
  46. GLSLPROGRAM
  47. #pragma only_renderers gles gles3
  48. #pragma multi_compile MONOSCOPIC STEREO_TOP_BOTTOM STEREO_LEFT_RIGHT STEREO_CUSTOM_UV
  49. #pragma multi_compile __ STEREO_DEBUG
  50. #pragma multi_compile __ APPLY_GAMMA
  51. #pragma multi_compile __ USING_DEFAULT_TEXTURE
  52. #pragma multi_compile __ USING_URP
  53. #extension GL_OES_EGL_image_external : require
  54. #extension GL_OES_EGL_image_external_essl3 : enable
  55. precision mediump float;
  56. #ifdef VERTEX
  57. #include "UnityCG.glslinc"
  58. #if defined(STEREO_MULTIVIEW_ON)
  59. UNITY_SETUP_STEREO_RENDERING
  60. #endif
  61. #define SHADERLAB_GLSL
  62. #include "../AVProVideo.cginc"
  63. INLINE bool Android_IsStereoEyeLeft()
  64. {
  65. #if defined(STEREO_MULTIVIEW_ON)
  66. int eyeIndex = SetupStereoEyeIndex();
  67. return (eyeIndex == 0);
  68. #else
  69. return IsStereoEyeLeft();
  70. #endif
  71. }
  72. varying vec2 texVal;
  73. uniform mat4 _MainTex_Xfrm;
  74. #if defined(STEREO_DEBUG)
  75. varying vec4 tint;
  76. #endif
  77. void main()
  78. {
  79. #if defined(STEREO_MULTIVIEW_ON)
  80. int eyeIndex = SetupStereoEyeIndex();
  81. mat4 vpMatrix = GetStereoMatrixVP(eyeIndex);
  82. gl_Position = vpMatrix * unity_ObjectToWorld * gl_Vertex;
  83. #else
  84. gl_Position = XFormObjectToClip(gl_Vertex);
  85. #endif
  86. texVal = gl_MultiTexCoord0.xy;
  87. // Apply texture transformation matrix - adjusts for offset/cropping (when the decoder decodes in blocks that overrun the video frame size, it pads)
  88. texVal.xy = (_MainTex_Xfrm * vec4(texVal.x, texVal.y, 0.0, 1.0)).xy;
  89. #if defined(STEREO_TOP_BOTTOM) | defined(STEREO_LEFT_RIGHT)
  90. vec4 scaleOffset = GetStereoScaleOffset(Android_IsStereoEyeLeft(), false);
  91. texVal.xy *= scaleOffset.xy;
  92. texVal.xy += scaleOffset.zw;
  93. #elif defined (STEREO_CUSTOM_UV)
  94. if (!Android_IsStereoEyeLeft())
  95. {
  96. texVal = gl_MultiTexCoord1.xy;
  97. texVal = vec2(1.0, 1.0) - texVal;
  98. }
  99. #endif
  100. #if defined(STEREO_DEBUG)
  101. tint = GetStereoDebugTint(Android_IsStereoEyeLeft());
  102. #endif
  103. }
  104. #endif
  105. #ifdef FRAGMENT
  106. varying vec2 texVal;
  107. #if defined(STEREO_DEBUG)
  108. varying vec4 tint;
  109. #endif
  110. #if defined(APPLY_GAMMA)
  111. vec3 GammaToLinear(vec3 col)
  112. {
  113. return pow(col, vec3(2.2, 2.2, 2.2));
  114. }
  115. #endif
  116. uniform vec4 _Color;
  117. #if defined(USING_DEFAULT_TEXTURE)
  118. uniform sampler2D _MainTex;
  119. #else
  120. uniform samplerExternalOES _MainTex;
  121. #endif
  122. void main()
  123. {
  124. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  125. #if __VERSION__ < 300
  126. vec4 col = texture2D(_MainTex, texVal.xy);
  127. #else
  128. vec4 col = texture(_MainTex, texVal.xy);
  129. #endif
  130. #else
  131. vec4 col = vec4(1.0, 1.0, 0.0, 1.0);
  132. #endif
  133. #if defined(APPLY_GAMMA)
  134. col.rgb = GammaToLinear(col.rgb);
  135. #endif
  136. col *= _Color;
  137. #if defined(STEREO_DEBUG)
  138. col *= tint;
  139. #endif
  140. gl_FragColor = col;
  141. }
  142. #endif
  143. ENDGLSL
  144. }
  145. }
  146. Fallback "AVProVideo/Internal/UI/Stereo"
  147. }