AVProVideo-Unlit-Transparent.shader 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. Shader "AVProVideo/Unlit/Transparent (texture+color+fog+stereo+alpha)"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Base (RGB) Trans (A)", 2D) = "black" {}
  6. _Color("Main Color", Color) = (1,1,1,1)
  7. _ChromaTex("Chroma", 2D) = "gray" {}
  8. [KeywordEnum(None, Top_Bottom, Left_Right)] AlphaPack("Alpha Pack", Float) = 0
  9. [KeywordEnum(None, Top_Bottom, Left_Right, Custom_UV)] Stereo("Stereo Mode", Float) = 0
  10. [Toggle(STEREO_DEBUG)] _StereoDebug("Stereo Debug Tinting", Float) = 0
  11. [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  12. [Toggle(USE_YPCBCR)] _UseYpCbCr("Use YpCbCr", Float) = 0
  13. }
  14. SubShader
  15. {
  16. Tags { "RenderType"="Transparent" "IgnoreProjector"="True" "Queue"="Transparent" }
  17. LOD 100
  18. ZWrite Off
  19. Blend SrcAlpha OneMinusSrcAlpha
  20. Lighting Off
  21. Cull Off
  22. Pass
  23. {
  24. CGPROGRAM
  25. #pragma vertex vert
  26. #pragma fragment frag
  27. #pragma multi_compile_fog
  28. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  29. #pragma multi_compile MONOSCOPIC STEREO_TOP_BOTTOM STEREO_LEFT_RIGHT STEREO_CUSTOM_UV
  30. #pragma multi_compile ALPHAPACK_NONE ALPHAPACK_TOP_BOTTOM ALPHAPACK_LEFT_RIGHT
  31. #pragma multi_compile __ STEREO_DEBUG
  32. #pragma multi_compile __ APPLY_GAMMA
  33. #pragma multi_compile __ USE_YPCBCR
  34. #include "UnityCG.cginc"
  35. #include "AVProVideo.cginc"
  36. struct appdata
  37. {
  38. float4 vertex : POSITION;
  39. float2 uv : TEXCOORD0;
  40. #if STEREO_CUSTOM_UV
  41. float2 uv2 : TEXCOORD1; // Custom uv set for right eye (left eye is in TEXCOORD0)
  42. #endif
  43. #ifdef UNITY_STEREO_INSTANCING_ENABLED
  44. UNITY_VERTEX_INPUT_INSTANCE_ID
  45. #endif
  46. };
  47. struct v2f
  48. {
  49. float4 vertex : SV_POSITION;
  50. float4 uv : TEXCOORD0;
  51. #if STEREO_DEBUG
  52. float4 tint : COLOR;
  53. #endif
  54. UNITY_FOG_COORDS(1)
  55. #ifdef UNITY_STEREO_INSTANCING_ENABLED
  56. UNITY_VERTEX_OUTPUT_STEREO
  57. #endif
  58. };
  59. uniform sampler2D _MainTex;
  60. #if USE_YPCBCR
  61. uniform sampler2D _ChromaTex;
  62. uniform float4x4 _YpCbCrTransform;
  63. #endif
  64. uniform float4 _MainTex_ST;
  65. uniform float4 _MainTex_TexelSize;
  66. uniform fixed4 _Color;
  67. v2f vert (appdata v)
  68. {
  69. v2f o;
  70. #ifdef UNITY_STEREO_INSTANCING_ENABLED
  71. UNITY_SETUP_INSTANCE_ID(v); // calculates and sets the built-n unity_StereoEyeIndex and unity_InstanceID Unity shader variables to the correct values based on which eye the GPU is currently rendering
  72. UNITY_INITIALIZE_OUTPUT(v2f, o); // initializes all v2f values to 0
  73. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); // tells the GPU which eye in the texture array it should render to
  74. #endif
  75. o.vertex = XFormObjectToClip(v.vertex);
  76. o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
  77. // Horrible hack to undo the scale transform to fit into our UV packing layout logic...
  78. if (_MainTex_ST.y < 0.0)
  79. {
  80. o.uv.y = 1.0 - o.uv.y;
  81. }
  82. #if STEREO_TOP_BOTTOM | STEREO_LEFT_RIGHT
  83. float4 scaleOffset = GetStereoScaleOffset(IsStereoEyeLeft(), _MainTex_ST.y < 0.0);
  84. o.uv.xy *= scaleOffset.xy;
  85. o.uv.xy += scaleOffset.zw;
  86. #elif STEREO_CUSTOM_UV
  87. if (!IsStereoEyeLeft())
  88. {
  89. o.uv.xy = TRANSFORM_TEX(v.uv2, _MainTex);
  90. }
  91. #endif
  92. #if STEREO_DEBUG
  93. o.tint = GetStereoDebugTint(IsStereoEyeLeft());
  94. #endif
  95. o.uv = OffsetAlphaPackingUV(_MainTex_TexelSize.xy, o.uv.xy, _MainTex_ST.y < 0.0);
  96. UNITY_TRANSFER_FOG(o, o.vertex);
  97. return o;
  98. }
  99. fixed4 frag (v2f i) : SV_Target
  100. {
  101. fixed4 col;
  102. #if USE_YPCBCR
  103. col = SampleYpCbCr(_MainTex, _ChromaTex, i.uv.xy, _YpCbCrTransform);
  104. #else
  105. col = SampleRGBA(_MainTex, i.uv.xy);
  106. #endif
  107. #if ALPHAPACK_TOP_BOTTOM | ALPHAPACK_LEFT_RIGHT
  108. col.a = SamplePackedAlpha(_MainTex, i.uv.zw);
  109. #endif
  110. col *= _Color;
  111. #if STEREO_DEBUG
  112. col *= i.tint;
  113. #endif
  114. UNITY_APPLY_FOG(i.fogCoord, col);
  115. return col;
  116. }
  117. ENDCG
  118. }
  119. }
  120. }