Unlit_YUV.shader 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. Shader "Unlit/Unlit_YUV"
  3. {
  4. Properties
  5. {
  6. _MainTex ("Texture", 2D) = "black" {}
  7. _Y("Y", 2D) = "black" {}
  8. _U("U", 2D) = "gray" {}
  9. _V("V", 2D) = "gray" {}
  10. }
  11. SubShader
  12. {
  13. Tags { "RenderType"="Opaque" }
  14. LOD 100
  15. Pass
  16. {
  17. CGPROGRAM
  18. #pragma vertex vert
  19. #pragma fragment frag
  20. // make fog work
  21. #pragma multi_compile_fog
  22. #include "UnityCG.cginc"
  23. struct appdata
  24. {
  25. float4 vertex : POSITION;
  26. float2 uv : TEXCOORD0;
  27. };
  28. struct v2f
  29. {
  30. float2 uv : TEXCOORD0;
  31. UNITY_FOG_COORDS(1)
  32. float4 vertex : SV_POSITION;
  33. };
  34. sampler2D _MainTex;
  35. sampler2D _Y;
  36. sampler2D _U;
  37. sampler2D _V;
  38. float4 _MainTex_ST;
  39. v2f vert (appdata v)
  40. {
  41. v2f o;
  42. //o.vertex = UnityObjectToClipPos(v.vertex);
  43. o.vertex = UnityObjectToClipPos(float4(v.vertex.xyz, 1.0));
  44. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  45. UNITY_TRANSFER_FOG(o,o.vertex);
  46. return o;
  47. }
  48. fixed4 frag (v2f i) : SV_Target
  49. {
  50. float y = (tex2D(_Y, i.uv).a - 0.0625) * 1.1643;
  51. float u = tex2D(_U, i.uv).a -0.5;
  52. float v = tex2D(_V, i.uv).a -0.5;
  53. float r = clamp(y + 1.5958 * v, 0.0, 1.0);
  54. float g = clamp(y - 0.39173 * u - 0.81290 * v, 0.0, 1.0);
  55. float b = clamp(y + 2.017 * u, 0.0, 1.0);
  56. fixed4 col = fixed4(r, g, b, 1.0);
  57. return col;
  58. }
  59. ENDCG
  60. }
  61. }
  62. }