AVProVideo-Internal-UI-Default-Stereo.shader 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. Shader "AVProVideo/Internal/UI/Stereo"
  2. {
  3. Properties
  4. {
  5. [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
  6. [PerRendererData] _ChromaTex ("Sprite Texture", 2D) = "white" {}
  7. _Color ("Tint", Color) = (1,1,1,1)
  8. _StencilComp ("Stencil Comparison", Float) = 8
  9. _Stencil ("Stencil ID", Float) = 0
  10. _StencilOp ("Stencil Operation", Float) = 0
  11. _StencilWriteMask ("Stencil Write Mask", Float) = 255
  12. _StencilReadMask ("Stencil Read Mask", Float) = 255
  13. _ColorMask ("Color Mask", Float) = 15
  14. [KeywordEnum(None, Top_Bottom, Left_Right)] Stereo("Stereo Mode", Float) = 0
  15. [KeywordEnum(None, Left, Right)] ForceEye ("Force Eye Mode", Float) = 0
  16. [Toggle(STEREO_DEBUG)] _StereoDebug("Stereo Debug Tinting", Float) = 0
  17. [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  18. [Toggle(USE_YPCBCR)] _UseYpCbCr("Use YpCbCr", Float) = 0
  19. }
  20. SubShader
  21. {
  22. Tags
  23. {
  24. "Queue"="Transparent"
  25. "IgnoreProjector"="True"
  26. "RenderType"="Transparent"
  27. "PreviewType"="Plane"
  28. "CanUseSpriteAtlas"="True"
  29. }
  30. Stencil
  31. {
  32. Ref [_Stencil]
  33. Comp [_StencilComp]
  34. Pass [_StencilOp]
  35. ReadMask [_StencilReadMask]
  36. WriteMask [_StencilWriteMask]
  37. }
  38. Cull Off
  39. Lighting Off
  40. ZWrite Off
  41. ZTest [unity_GUIZTestMode]
  42. Fog { Mode Off }
  43. Blend SrcAlpha OneMinusSrcAlpha
  44. ColorMask [_ColorMask]
  45. Pass
  46. {
  47. CGPROGRAM
  48. #pragma vertex vert
  49. #pragma fragment frag
  50. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  51. #pragma multi_compile MONOSCOPIC STEREO_TOP_BOTTOM STEREO_LEFT_RIGHT
  52. #pragma multi_compile FORCEEYE_NONE FORCEEYE_LEFT FORCEEYE_RIGHT
  53. #pragma multi_compile __ APPLY_GAMMA
  54. #pragma multi_compile __ STEREO_DEBUG
  55. #pragma multi_compile __ USE_YPCBCR
  56. #include "UnityCG.cginc"
  57. #include "../AVProVideo.cginc"
  58. struct appdata_t
  59. {
  60. float4 vertex : POSITION;
  61. float4 color : COLOR;
  62. float2 texcoord : TEXCOORD0;
  63. };
  64. struct v2f
  65. {
  66. float4 vertex : SV_POSITION;
  67. fixed4 color : COLOR;
  68. half2 texcoord : TEXCOORD0;
  69. };
  70. uniform fixed4 _Color;
  71. uniform sampler2D _MainTex;
  72. #if USE_YPCBCR
  73. uniform sampler2D _ChromaTex;
  74. uniform float4x4 _YpCbCrTransform;
  75. #endif
  76. uniform float4 _MainTex_ST;
  77. uniform float4 _MainTex_TexelSize;
  78. v2f vert(appdata_t IN)
  79. {
  80. v2f OUT;
  81. OUT.vertex = XFormObjectToClip(IN.vertex);
  82. #ifdef UNITY_HALF_TEXEL_OFFSET
  83. OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
  84. #endif
  85. OUT.texcoord.xy = IN.texcoord.xy;
  86. #if STEREO_TOP_BOTTOM | STEREO_LEFT_RIGHT
  87. float4 scaleOffset = GetStereoScaleOffset(IsStereoEyeLeft(), _MainTex_ST.y < 0.0);
  88. OUT.texcoord.xy *= scaleOffset.xy;
  89. OUT.texcoord.xy += scaleOffset.zw;
  90. #endif
  91. OUT.color = IN.color * _Color;
  92. #if STEREO_DEBUG
  93. OUT.color *= GetStereoDebugTint(IsStereoEyeLeft());
  94. #endif
  95. return OUT;
  96. }
  97. fixed4 frag(v2f IN) : SV_Target
  98. {
  99. fixed4 col;
  100. #if USE_YPCBCR
  101. col = SampleYpCbCr(_MainTex, _ChromaTex, IN.texcoord, _YpCbCrTransform);
  102. #else
  103. col = SampleRGBA(_MainTex, IN.texcoord);
  104. #endif
  105. col *= IN.color;
  106. return col;
  107. }
  108. ENDCG
  109. }
  110. }
  111. }