AVProVideo-Unlit-Transparent-AndroidOES.shader 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. Shader "AVProVideo/Unlit/Transparent (texture+alpha 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)] AlphaPack("Alpha Pack", Float) = 0
  9. [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  10. }
  11. SubShader
  12. {
  13. Tags { "RenderType"="Transparent" "IgnoreProjector"="True" "Queue"="Transparent" }
  14. LOD 100
  15. ZWrite Off
  16. Blend SrcAlpha OneMinusSrcAlpha
  17. Lighting Off
  18. Cull Off
  19. Pass
  20. {
  21. GLSLPROGRAM
  22. #pragma only_renderers gles gles3
  23. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  24. #pragma multi_compile ALPHAPACK_NONE ALPHAPACK_TOP_BOTTOM ALPHAPACK_LEFT_RIGHT
  25. #pragma multi_compile __ APPLY_GAMMA
  26. #pragma multi_compile __ USING_DEFAULT_TEXTURE
  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. #define SHADERLAB_GLSL
  33. #include "AVProVideo.cginc"
  34. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  35. varying vec4 texVal;
  36. #else
  37. varying vec2 texVal;
  38. #endif
  39. uniform vec4 _MainTex_ST;
  40. uniform vec4 _MainTex_TexelSize;
  41. uniform mat4 _TextureMatrix;
  42. /// @fix: explicit TRANSFORM_TEX(); Unity's preprocessor chokes when attempting to use the TRANSFORM_TEX() macro in UnityCG.glslinc
  43. /// (as of Unity 4.5.0f6; issue dates back to 2011 or earlier: http://forum.unity3d.com/threads/glsl-transform_tex-and-tiling.93756/)
  44. vec2 transformTex(vec4 texCoord, vec4 texST)
  45. {
  46. return (texCoord.xy * texST.xy + texST.zw);
  47. }
  48. void main()
  49. {
  50. gl_Position = XFormObjectToClip(gl_Vertex);
  51. texVal.xy = transformTex(gl_MultiTexCoord0, _MainTex_ST);
  52. // Apply texture transformation matrix - adjusts for offset/cropping (when the decoder decodes in blocks that overrun the video frame size, it pads)
  53. texVal.xy = (_TextureMatrix * vec4(texVal.x, texVal.y, 0.0, 1.0) ).xy;
  54. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  55. texVal = OffsetAlphaPackingUV(_MainTex_TexelSize.xy, texVal.xy, _MainTex_ST.y < 0.0);
  56. #if defined(ALPHAPACK_TOP_BOTTOM)
  57. texVal.yw = texVal.wy;
  58. #endif
  59. #endif
  60. }
  61. #endif
  62. #ifdef FRAGMENT
  63. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  64. varying vec4 texVal;
  65. #else
  66. varying vec2 texVal;
  67. #endif
  68. #if defined(USING_DEFAULT_TEXTURE)
  69. uniform sampler2D _MainTex;
  70. #else
  71. uniform samplerExternalOES _MainTex;
  72. #endif
  73. #if defined(APPLY_GAMMA)
  74. vec3 GammaToLinear(vec3 col)
  75. {
  76. return col * (col * (col * 0.305306011 + 0.682171111) + 0.012522878);
  77. }
  78. #endif
  79. void main()
  80. {
  81. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  82. vec4 col = texture2D(_MainTex, texVal.xy);
  83. #else
  84. vec4 col = vec4(1.0, 1.0, 0.0, 1.0);
  85. #endif
  86. #if defined(APPLY_GAMMA)
  87. col.rgb = GammaToLinear(col.rgb);
  88. #endif
  89. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  90. #if defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)
  91. vec3 rgb = texture2D(_MainTex, texVal.zw).rgb;
  92. col.a = (rgb.r + rgb.g + rgb.b) / 3.0;
  93. #else
  94. col.a = 1.0;
  95. #endif
  96. #endif
  97. gl_FragColor = col;
  98. }
  99. #endif
  100. ENDGLSL
  101. }
  102. }
  103. Fallback "AVProVideo/Unlit/Transparent (texture+color+fog+stereo+alpha)"
  104. }