AVProVideo-Internal-UI-AndroidOES.shader 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #extension GL_OES_EGL_image_external : require
  53. #extension GL_OES_EGL_image_external_essl3 : enable
  54. precision mediump float;
  55. #ifdef VERTEX
  56. #include "UnityCG.glslinc"
  57. #if defined(STEREO_MULTIVIEW_ON)
  58. UNITY_SETUP_STEREO_RENDERING
  59. #endif
  60. #define SHADERLAB_GLSL
  61. #include "../AVProVideo.cginc"
  62. INLINE bool Android_IsStereoEyeLeft()
  63. {
  64. #if defined(STEREO_MULTIVIEW_ON)
  65. int eyeIndex = SetupStereoEyeIndex();
  66. return (eyeIndex == 0);
  67. #else
  68. return IsStereoEyeLeft();
  69. #endif
  70. }
  71. varying vec2 texVal;
  72. uniform mat4 _TextureMatrix;
  73. #if defined(STEREO_DEBUG)
  74. varying vec4 tint;
  75. #endif
  76. void main()
  77. {
  78. #if defined(STEREO_MULTIVIEW_ON)
  79. int eyeIndex = SetupStereoEyeIndex();
  80. mat4 vpMatrix = GetStereoMatrixVP(eyeIndex);
  81. gl_Position = vpMatrix * unity_ObjectToWorld * gl_Vertex;
  82. #else
  83. gl_Position = XFormObjectToClip(gl_Vertex);
  84. #endif
  85. texVal = gl_MultiTexCoord0.xy;
  86. // Apply texture transformation matrix - adjusts for offset/cropping (when the decoder decodes in blocks that overrun the video frame size, it pads)
  87. texVal.xy = (_TextureMatrix * vec4(texVal.x, texVal.y, 0.0, 1.0)).xy;
  88. #if defined(STEREO_TOP_BOTTOM) | defined(STEREO_LEFT_RIGHT)
  89. vec4 scaleOffset = GetStereoScaleOffset(Android_IsStereoEyeLeft(), false);
  90. texVal.xy *= scaleOffset.xy;
  91. texVal.xy += scaleOffset.zw;
  92. #elif defined (STEREO_CUSTOM_UV)
  93. if (!Android_IsStereoEyeLeft())
  94. {
  95. texVal = gl_MultiTexCoord1.xy;
  96. texVal = vec2(1.0, 1.0) - texVal;
  97. }
  98. #endif
  99. #if defined(STEREO_DEBUG)
  100. tint = GetStereoDebugTint(Android_IsStereoEyeLeft());
  101. #endif
  102. }
  103. #endif
  104. #ifdef FRAGMENT
  105. varying vec2 texVal;
  106. #if defined(STEREO_DEBUG)
  107. varying vec4 tint;
  108. #endif
  109. #if defined(APPLY_GAMMA)
  110. vec3 GammaToLinear(vec3 col)
  111. {
  112. return pow(col, vec3(2.2, 2.2, 2.2));
  113. }
  114. #endif
  115. uniform vec4 _Color;
  116. #if defined(USING_DEFAULT_TEXTURE)
  117. uniform sampler2D _MainTex;
  118. #else
  119. uniform samplerExternalOES _MainTex;
  120. #endif
  121. void main()
  122. {
  123. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  124. #if __VERSION__ < 300
  125. vec4 col = texture2D(_MainTex, texVal.xy);
  126. #else
  127. vec4 col = texture(_MainTex, texVal.xy);
  128. #endif
  129. #else
  130. vec4 col = vec4(1.0, 1.0, 0.0, 1.0);
  131. #endif
  132. #if defined(APPLY_GAMMA)
  133. col.rgb = GammaToLinear(col.rgb);
  134. #endif
  135. col *= _Color;
  136. #if defined(STEREO_DEBUG)
  137. col *= tint;
  138. #endif
  139. gl_FragColor = col;
  140. }
  141. #endif
  142. ENDGLSL
  143. }
  144. }
  145. Fallback "AVProVideo/Internal/UI/Stereo"
  146. }