AVProVideo-Unlit-AndroidOES.shader 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. Shader "AVProVideo/Unlit/Opaque (texture+color+stereo support) - Android OES ONLY"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Base (RGB)", 2D) = "black" {}
  6. _ChromaTex("Chroma", 2D) = "gray" {} // For fallback shader
  7. _Color("Main Color", Color) = (1,1,1,1) // For fallback shader
  8. [KeywordEnum(None, Top_Bottom, Left_Right)] Stereo("Stereo Mode", Float) = 0
  9. [Toggle(STEREO_DEBUG)] _StereoDebug("Stereo Debug Tinting", Float) = 0
  10. [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  11. }
  12. SubShader
  13. {
  14. Tags { "RenderType"="Opaque" "IgnoreProjector"="False" "Queue"="Geometry" }
  15. LOD 100
  16. Lighting Off
  17. Cull Off
  18. Pass
  19. {
  20. GLSLPROGRAM
  21. #pragma only_renderers gles gles3
  22. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  23. #pragma multi_compile MONOSCOPIC STEREO_TOP_BOTTOM STEREO_LEFT_RIGHT STEREO_CUSTOM_UV
  24. #pragma multi_compile __ APPLY_GAMMA
  25. #pragma multi_compile __ USING_DEFAULT_TEXTURE
  26. #pragma multi_compile __ STEREO_DEBUG
  27. #pragma multi_compile __ USING_URP
  28. #extension GL_OES_EGL_image_external : require
  29. #extension GL_OES_EGL_image_external_essl3 : enable
  30. precision mediump float;
  31. #ifdef VERTEX
  32. #include "UnityCG.glslinc"
  33. #if defined(STEREO_MULTIVIEW_ON)
  34. UNITY_SETUP_STEREO_RENDERING
  35. #endif
  36. #define SHADERLAB_GLSL
  37. #include "AVProVideo.cginc"
  38. varying vec2 texVal;
  39. uniform vec4 _MainTex_ST;
  40. uniform mat4 _MainTex_Xfrm;
  41. #if defined(STEREO_DEBUG)
  42. varying vec4 tint;
  43. #endif
  44. /// @fix: explicit TRANSFORM_TEX(); Unity's preprocessor chokes when attempting to use the TRANSFORM_TEX() macro in UnityCG.glslinc
  45. /// (as of Unity 4.5.0f6; issue dates back to 2011 or earlier: http://forum.unity3d.com/threads/glsl-transform_tex-and-tiling.93756/)
  46. vec2 transformTex(vec4 texCoord, vec4 texST)
  47. {
  48. return (texCoord.xy * texST.xy + texST.zw);
  49. }
  50. INLINE bool Android_IsStereoEyeLeft()
  51. {
  52. #if defined(STEREO_MULTIVIEW_ON)
  53. int eyeIndex = SetupStereoEyeIndex();
  54. return (eyeIndex == 0);
  55. #else
  56. return IsStereoEyeLeft();
  57. #endif
  58. }
  59. void main()
  60. {
  61. #if defined(STEREO_MULTIVIEW_ON)
  62. int eyeIndex = SetupStereoEyeIndex();
  63. mat4 vpMatrix = GetStereoMatrixVP(eyeIndex);
  64. gl_Position = vpMatrix * unity_ObjectToWorld * gl_Vertex;
  65. #else
  66. gl_Position = XFormObjectToClip(gl_Vertex);
  67. #endif
  68. texVal = transformTex(gl_MultiTexCoord0, _MainTex_ST);
  69. //texVal.x = 1.0 - texVal.x;
  70. // Apply texture transformation matrix - adjusts for offset/cropping (when the decoder decodes in blocks that overrun the video frame size, it pads)
  71. texVal.xy = (_MainTex_Xfrm * vec4(texVal.x, texVal.y, 0.0, 1.0) ).xy;
  72. #if defined(STEREO_TOP_BOTTOM) || defined(STEREO_LEFT_RIGHT)
  73. vec4 scaleOffset = GetStereoScaleOffset(Android_IsStereoEyeLeft(), false);
  74. texVal.xy *= scaleOffset.xy;
  75. texVal.xy += scaleOffset.zw;
  76. #endif
  77. #if defined(STEREO_DEBUG)
  78. tint = GetStereoDebugTint(Android_IsStereoEyeLeft());
  79. #endif
  80. }
  81. #endif
  82. #ifdef FRAGMENT
  83. varying vec2 texVal;
  84. #if defined(APPLY_GAMMA)
  85. vec3 GammaToLinear(vec3 col)
  86. {
  87. return col * (col * (col * 0.305306011 + 0.682171111) + 0.012522878);
  88. }
  89. #endif
  90. #if defined(USING_DEFAULT_TEXTURE)
  91. uniform sampler2D _MainTex;
  92. #else
  93. uniform samplerExternalOES _MainTex;
  94. #endif
  95. #if defined(STEREO_DEBUG)
  96. varying vec4 tint;
  97. #endif
  98. void main()
  99. {
  100. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  101. vec4 col = texture2D(_MainTex, texVal.xy);
  102. #else
  103. vec4 col = vec4(1.0, 1.0, 0.0, 1.0);
  104. #endif
  105. #if defined(APPLY_GAMMA)
  106. col.rgb = GammaToLinear(col.rgb);
  107. #endif
  108. #if defined(STEREO_DEBUG)
  109. col *= tint;
  110. #endif
  111. gl_FragColor = col;
  112. }
  113. #endif
  114. ENDGLSL
  115. }
  116. }
  117. Fallback "AVProVideo/Unlit/Opaque (texture+color+fog+stereo support)"
  118. }