AVProVideo-Internal-ResolveOES.shader 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. Shader "AVProVideo/Internal/ResolveOES"
  2. {
  3. Properties
  4. {
  5. _MainTex("Texture", any) = "" {}
  6. _ChromaTex("Chroma", any) = "" {}
  7. _Color ("Tint", Color) = (1,1,1,1)
  8. _VertScale("Vertical Scale", Range(-1, 1)) = 1.0
  9. [Toggle(USE_HSBC)] _UseHSBC("Use HSBC", Float) = 0
  10. _Hue("Hue", Range(0, 1.0)) = 0
  11. _Saturation("Saturation", Range(0, 1.0)) = 0.5
  12. _Brightness("Brightness", Range(0, 1.0)) = 0.5
  13. _Contrast("Contrast", Range(0, 1.0)) = 0.5
  14. _InvGamma("InvGamma", Range(0.0001, 10000.0)) = 1.0
  15. [KeywordEnum(None, Top_Bottom, Left_Right)] Stereo("Stereo Mode", Float) = 0
  16. [KeywordEnum(None, Left, Right)] ForceEye ("Force Eye Mode", Float) = 0
  17. [KeywordEnum(None, Top_Bottom, Left_Right)] AlphaPack("Alpha Pack", Float) = 0
  18. [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  19. [Toggle(USE_YPCBCR)] _UseYpCbCr("Use YpCbCr", Float) = 0
  20. }
  21. SubShader
  22. {
  23. Tags
  24. {
  25. "IgnoreProjector" = "True"
  26. "PreviewType" = "Plane"
  27. }
  28. Lighting Off
  29. Cull Off
  30. ZWrite Off
  31. ZTest Always
  32. Pass
  33. {
  34. Name "RESOLVE-OES"
  35. GLSLPROGRAM
  36. #pragma only_renderers gles gles3
  37. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  38. #pragma multi_compile MONOSCOPIC STEREO_TOP_BOTTOM STEREO_LEFT_RIGHT
  39. #pragma multi_compile ALPHAPACK_NONE ALPHAPACK_TOP_BOTTOM ALPHAPACK_LEFT_RIGHT
  40. #pragma multi_compile __ APPLY_GAMMA
  41. #pragma multi_compile __ USE_HSBC
  42. #extension GL_OES_EGL_image_external : require
  43. #extension GL_OES_EGL_image_external_essl3 : enable
  44. #include "UnityCG.glslinc"
  45. #if defined(STEREO_MULTIVIEW_ON)
  46. UNITY_SETUP_STEREO_RENDERING
  47. #endif
  48. #define SHADERLAB_GLSL
  49. #include "../AVProVideo.cginc"
  50. #ifdef VERTEX
  51. varying vec4 varTexCoord;
  52. varying vec4 varColor;
  53. uniform vec4 _Color;
  54. uniform vec4 _MainTex_ST;
  55. uniform vec4 _MainTex_TexelSize;
  56. uniform mat4 _TextureMatrix;
  57. uniform float _VertScale;
  58. INLINE bool Android_IsStereoEyeLeft()
  59. {
  60. #if defined(STEREO_MULTIVIEW_ON)
  61. int eyeIndex = SetupStereoEyeIndex();
  62. return (eyeIndex == 0);
  63. #else
  64. return IsStereoEyeLeft();
  65. #endif
  66. }
  67. vec2 transformTex(vec4 texCoord, vec4 texST)
  68. {
  69. return (texCoord.xy * texST.xy + texST.zw);
  70. }
  71. void main()
  72. {
  73. #if defined(STEREO_MULTIVIEW_ON)
  74. int eyeIndex = SetupStereoEyeIndex();
  75. mat4 vpMatrix = GetStereoMatrixVP(eyeIndex);
  76. gl_Position = vpMatrix * unity_ObjectToWorld * gl_Vertex;
  77. #else
  78. gl_Position = XFormObjectToClip(gl_Vertex);
  79. #endif
  80. varColor = gl_Color * _Color;
  81. varTexCoord.xy = transformTex(gl_MultiTexCoord0, _MainTex_ST);
  82. varTexCoord.zw = vec2(0.0, 0.0);
  83. // Apply texture transformation matrix - adjusts for offset/cropping (when the decoder decodes in blocks that overrun the video frame size, it pads)
  84. varTexCoord.xy = (_TextureMatrix * vec4(varTexCoord.x, varTexCoord.y, 0.0, 1.0)).xy;
  85. #if defined(STEREO_TOP_BOTTOM) || defined(STEREO_LEFT_RIGHT)
  86. vec4 scaleOffset = GetStereoScaleOffset(Android_IsStereoEyeLeft(), false);
  87. varTexCoord.xy *= scaleOffset.xy;
  88. varTexCoord.xy += scaleOffset.zw;
  89. #endif
  90. #if defined (ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  91. varTexCoord = OffsetAlphaPackingUV(_MainTex_TexelSize.xy, varTexCoord.xy, false);
  92. #if defined(ALPHAPACK_TOP_BOTTOM)
  93. varTexCoord.yw = varTexCoord.wy;
  94. #endif
  95. #endif
  96. }
  97. #endif
  98. #ifdef FRAGMENT
  99. varying vec4 varTexCoord;
  100. varying vec4 varColor;
  101. uniform samplerExternalOES _MainTex;
  102. #if defined(USE_HSBC)
  103. uniform float _Hue, _Saturation, _Brightness, _Contrast, _InvGamma;
  104. #endif
  105. void main()
  106. {
  107. vec4 col = TEX_EXTERNAL(_MainTex, varTexCoord.xy);
  108. #if defined(APPLY_GAMMA)
  109. col.rgb = GammaToLinear(col.rgb);
  110. #endif
  111. #if defined(ALPHAPACK_TOP_BOTTOM) || defined(ALPHAPACK_LEFT_RIGHT)
  112. vec4 colAlpha = TEX_EXTERNAL(_MainTex, varTexCoord.zw);
  113. col.a = (colAlpha.r + colAlpha.g + colAlpha.b) / 3.0;
  114. #endif
  115. #if defined(USE_HSBC)
  116. col.rgb = ApplyHSBEffect(col.rgb, vec4(_Hue, _Saturation, _Brightness, _Contrast));
  117. col.rgb = pow(col.rgb, vec3(_InvGamma));
  118. #endif
  119. gl_FragColor = col * varColor;
  120. }
  121. #endif
  122. ENDGLSL
  123. }
  124. }
  125. Fallback off
  126. }