AVProVideo-Unlit-AndroidOES.shader 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #extension GL_OES_EGL_image_external : require
  28. #extension GL_OES_EGL_image_external_essl3 : enable
  29. precision mediump float;
  30. #ifdef VERTEX
  31. #include "UnityCG.glslinc"
  32. #if defined(STEREO_MULTIVIEW_ON)
  33. UNITY_SETUP_STEREO_RENDERING
  34. #endif
  35. #define SHADERLAB_GLSL
  36. #include "AVProVideo.cginc"
  37. varying vec2 texVal;
  38. uniform vec4 _MainTex_ST;
  39. uniform mat4 _TextureMatrix;
  40. #if defined(STEREO_DEBUG)
  41. varying vec4 tint;
  42. #endif
  43. /// @fix: explicit TRANSFORM_TEX(); Unity's preprocessor chokes when attempting to use the TRANSFORM_TEX() macro in UnityCG.glslinc
  44. /// (as of Unity 4.5.0f6; issue dates back to 2011 or earlier: http://forum.unity3d.com/threads/glsl-transform_tex-and-tiling.93756/)
  45. vec2 transformTex(vec4 texCoord, vec4 texST)
  46. {
  47. return (texCoord.xy * texST.xy + texST.zw);
  48. }
  49. INLINE bool Android_IsStereoEyeLeft()
  50. {
  51. #if defined(STEREO_MULTIVIEW_ON)
  52. int eyeIndex = SetupStereoEyeIndex();
  53. return (eyeIndex == 0);
  54. #else
  55. return IsStereoEyeLeft();
  56. #endif
  57. }
  58. void main()
  59. {
  60. #if defined(STEREO_MULTIVIEW_ON)
  61. int eyeIndex = SetupStereoEyeIndex();
  62. mat4 vpMatrix = GetStereoMatrixVP(eyeIndex);
  63. gl_Position = vpMatrix * unity_ObjectToWorld * gl_Vertex;
  64. #else
  65. gl_Position = XFormObjectToClip(gl_Vertex);
  66. #endif
  67. texVal = transformTex(gl_MultiTexCoord0, _MainTex_ST);
  68. //texVal.x = 1.0 - texVal.x;
  69. // Apply texture transformation matrix - adjusts for offset/cropping (when the decoder decodes in blocks that overrun the video frame size, it pads)
  70. texVal.xy = (_TextureMatrix * vec4(texVal.x, texVal.y, 0.0, 1.0) ).xy;
  71. #if defined(STEREO_TOP_BOTTOM) || defined(STEREO_LEFT_RIGHT)
  72. vec4 scaleOffset = GetStereoScaleOffset(Android_IsStereoEyeLeft(), false);
  73. texVal.xy *= scaleOffset.xy;
  74. texVal.xy += scaleOffset.zw;
  75. #endif
  76. #if defined(STEREO_DEBUG)
  77. tint = GetStereoDebugTint(Android_IsStereoEyeLeft());
  78. #endif
  79. }
  80. #endif
  81. #ifdef FRAGMENT
  82. varying vec2 texVal;
  83. #if defined(APPLY_GAMMA)
  84. vec3 GammaToLinear(vec3 col)
  85. {
  86. return col * (col * (col * 0.305306011 + 0.682171111) + 0.012522878);
  87. }
  88. #endif
  89. #if defined(USING_DEFAULT_TEXTURE)
  90. uniform sampler2D _MainTex;
  91. #else
  92. uniform samplerExternalOES _MainTex;
  93. #endif
  94. #if defined(STEREO_DEBUG)
  95. varying vec4 tint;
  96. #endif
  97. void main()
  98. {
  99. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  100. vec4 col = texture2D(_MainTex, texVal.xy);
  101. #else
  102. vec4 col = vec4(1.0, 1.0, 0.0, 1.0);
  103. #endif
  104. #if defined(APPLY_GAMMA)
  105. col.rgb = GammaToLinear(col.rgb);
  106. #endif
  107. #if defined(STEREO_DEBUG)
  108. col *= tint;
  109. #endif
  110. gl_FragColor = col;
  111. }
  112. #endif
  113. ENDGLSL
  114. }
  115. }
  116. Fallback "AVProVideo/Unlit/Opaque (texture+color+fog+stereo support)"
  117. }