AVProVideo-Internal-Resolve.shader 3.1 KB

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