AVProVideo-Internal-Resolve.shader 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. Shader "AVProVideo/Internal/Resolve"
  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"
  35. CGPROGRAM
  36. #pragma exclude_renderers gles
  37. #pragma vertex vert
  38. #pragma fragment frag
  39. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  40. #pragma multi_compile MONOSCOPIC STEREO_TOP_BOTTOM STEREO_LEFT_RIGHT
  41. #pragma multi_compile ALPHAPACK_NONE ALPHAPACK_TOP_BOTTOM ALPHAPACK_LEFT_RIGHT
  42. #pragma multi_compile __ APPLY_GAMMA
  43. #pragma multi_compile __ USE_YPCBCR
  44. #pragma multi_compile __ USE_HSBC
  45. #include "UnityCG.cginc"
  46. #include "../AVProVideo.cginc"
  47. struct appdata_t
  48. {
  49. float4 vertex : POSITION;
  50. fixed4 color : COLOR;
  51. float2 texcoord : TEXCOORD0;
  52. };
  53. struct v2f
  54. {
  55. float4 vertex : SV_POSITION;
  56. fixed4 color : COLOR;
  57. float4 uv : TEXCOORD0;
  58. };
  59. uniform sampler2D _MainTex;
  60. #if USE_YPCBCR
  61. uniform sampler2D _ChromaTex;
  62. uniform float4x4 _YpCbCrTransform;
  63. #endif
  64. #if USE_HSBC
  65. uniform fixed _Hue, _Saturation, _Brightness, _Contrast, _InvGamma;
  66. #endif
  67. uniform fixed4 _Color;
  68. uniform float4 _MainTex_ST;
  69. uniform float4 _MainTex_TexelSize;
  70. uniform float4x4 _MainTex_Xfrm;
  71. uniform float _VertScale;
  72. v2f vert(appdata_t v)
  73. {
  74. v2f o;
  75. o.vertex = XFormObjectToClip(v.vertex);
  76. o.color = v.color * _Color;
  77. o.uv.xy = mul(_MainTex_Xfrm, float4(v.texcoord, 0.0f, 1.0f)).xy;
  78. o.uv.wz = 0.0;
  79. #if STEREO_TOP_BOTTOM || STEREO_LEFT_RIGHT
  80. float4 scaleOffset = GetStereoScaleOffset(IsStereoEyeLeft(), _MainTex_ST.y < 0.0);
  81. o.uv.xy *= scaleOffset.xy;
  82. o.uv.xy += scaleOffset.zw;
  83. #endif
  84. // NOTE: this always runs because it's also used to flip vertically
  85. o.uv = OffsetAlphaPackingUV(_MainTex_TexelSize.xy, o.uv.xy, _VertScale < 0.0);
  86. return o;
  87. }
  88. half4 frag(v2f i) : SV_Target
  89. {
  90. half4 col;
  91. #if USE_YPCBCR
  92. col = SampleYpCbCr(_MainTex, _ChromaTex, i.uv.xy, _YpCbCrTransform);
  93. #else
  94. col = SampleRGBA(_MainTex, i.uv.xy);
  95. #endif
  96. #if ALPHAPACK_TOP_BOTTOM || ALPHAPACK_LEFT_RIGHT
  97. col.a = SamplePackedAlpha(_MainTex, i.uv.zw);
  98. #endif
  99. #if USE_HSBC
  100. col.rgb = ApplyHSBEffect(col.rgb, fixed4(_Hue, _Saturation, _Brightness, _Contrast));
  101. col.rgb = pow(col.rgb, _InvGamma);
  102. #endif
  103. return col * i.color;
  104. }
  105. ENDCG
  106. }
  107. }
  108. Fallback off
  109. }