AVProVideo-Unlit.shader 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. Shader "AVProVideo/Unlit/Opaque (texture+color+fog+stereo support)"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Base (RGB)", 2D) = "black" {}
  6. _ChromaTex ("Chroma", 2D) = "gray" {}
  7. _Color("Main Color", Color) = (1,1,1,1)
  8. [KeywordEnum(None, Top_Bottom, Left_Right, Custom_UV)] Stereo("Stereo Mode", Float) = 0
  9. [Toggle(STEREO_DEBUG)] _StereoDebug("Stereo Debug Tinting", Float) = 0
  10. [Toggle(APPLY_GAMMA)] _ApplyGamma("Apply Gamma", Float) = 0
  11. [Toggle(USE_YPCBCR)] _UseYpCbCr("Use YpCbCr", Float) = 0
  12. }
  13. SubShader
  14. {
  15. Tags { "RenderType"="Opaque" "IgnoreProjector"="False" "Queue"="Geometry" }
  16. LOD 100
  17. Lighting Off
  18. Cull Off
  19. Pass
  20. {
  21. CGPROGRAM
  22. #pragma vertex vert
  23. #pragma fragment frag
  24. #pragma multi_compile_fog
  25. // TODO: replace use multi_compile_local instead (Unity 2019.1 feature)
  26. #pragma multi_compile MONOSCOPIC STEREO_TOP_BOTTOM STEREO_LEFT_RIGHT STEREO_CUSTOM_UV
  27. #pragma multi_compile __ STEREO_DEBUG
  28. #pragma multi_compile __ APPLY_GAMMA
  29. #pragma multi_compile __ USE_YPCBCR
  30. #include "UnityCG.cginc"
  31. #include "AVProVideo.cginc"
  32. struct appdata
  33. {
  34. float4 vertex : POSITION;
  35. float2 uv : TEXCOORD0;
  36. #if STEREO_CUSTOM_UV
  37. float2 uv2 : TEXCOORD1; // Custom uv set for right eye (left eye is in TEXCOORD0)
  38. #endif
  39. #ifdef UNITY_STEREO_INSTANCING_ENABLED
  40. UNITY_VERTEX_INPUT_INSTANCE_ID
  41. #endif
  42. };
  43. struct v2f
  44. {
  45. float4 vertex : SV_POSITION;
  46. float2 uv : TEXCOORD0;
  47. UNITY_FOG_COORDS(1)
  48. #if STEREO_DEBUG
  49. float4 tint : COLOR;
  50. #endif
  51. #ifdef UNITY_STEREO_INSTANCING_ENABLED
  52. UNITY_VERTEX_OUTPUT_STEREO
  53. #endif
  54. };
  55. uniform sampler2D _MainTex;
  56. #if USE_YPCBCR
  57. uniform sampler2D _ChromaTex;
  58. uniform float4x4 _YpCbCrTransform;
  59. #endif
  60. uniform float4 _MainTex_ST;
  61. uniform fixed4 _Color;
  62. v2f vert (appdata v)
  63. {
  64. v2f o;
  65. #ifdef UNITY_STEREO_INSTANCING_ENABLED
  66. 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
  67. UNITY_INITIALIZE_OUTPUT(v2f, o); // initializes all v2f values to 0
  68. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); // tells the GPU which eye in the texture array it should render to
  69. #endif
  70. o.vertex = XFormObjectToClip(v.vertex);
  71. o.uv.xy = TRANSFORM_TEX(v.uv, _MainTex);
  72. #if STEREO_TOP_BOTTOM | STEREO_LEFT_RIGHT
  73. float4 scaleOffset = GetStereoScaleOffset(IsStereoEyeLeft(), _MainTex_ST.y < 0.0);
  74. o.uv.xy *= scaleOffset.xy;
  75. o.uv.xy += scaleOffset.zw;
  76. #elif STEREO_CUSTOM_UV
  77. if (!IsStereoEyeLeft())
  78. {
  79. o.uv.xy = TRANSFORM_TEX(v.uv2, _MainTex);
  80. }
  81. #endif
  82. #if STEREO_DEBUG
  83. o.tint = GetStereoDebugTint(IsStereoEyeLeft());
  84. #endif
  85. UNITY_TRANSFER_FOG(o, o.vertex);
  86. return o;
  87. }
  88. fixed4 frag (v2f i) : SV_Target
  89. {
  90. fixed4 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. col *= _Color;
  97. #if STEREO_DEBUG
  98. col *= i.tint;
  99. #endif
  100. UNITY_APPLY_FOG(i.fogCoord, col);
  101. return col;
  102. }
  103. ENDCG
  104. }
  105. }
  106. }