YUVTransRGB.shader 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Shader "Unlit/YUVTransRGB"
  2. {
  3. Properties
  4. {
  5. _MainTex("Texture", 2D) = "black" {}
  6. _UTex("U", 2D) = "black" {}
  7. _VTex("V", 2D) = "black" {}
  8. }
  9. SubShader
  10. {
  11. Tags { "RenderType" = "Opaque" }
  12. LOD 100
  13. Pass
  14. {
  15. CGPROGRAM
  16. #pragma vertex vert
  17. #pragma fragment frag
  18. #include "UnityCG.cginc"
  19. struct appdata
  20. {
  21. float4 vertex : POSITION;
  22. float2 uv : TEXCOORD0;
  23. };
  24. struct v2f
  25. {
  26. float2 uv : TEXCOORD0;
  27. UNITY_FOG_COORDS(1)
  28. float4 vertex : SV_POSITION;
  29. };
  30. sampler2D _MainTex;
  31. sampler2D _UTex;
  32. sampler2D _VTex;
  33. float4 _MainTex_ST;
  34. v2f vert(appdata v)
  35. {
  36. v2f o;
  37. o.vertex = UnityObjectToClipPos(v.vertex);
  38. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  39. return o;
  40. }
  41. fixed4 frag(v2f i) : SV_Target
  42. {
  43. fixed2 uv = fixed2(i.uv.x, 1 - i.uv.y);
  44. fixed4 ycol = tex2D(_MainTex, uv);
  45. fixed4 ucol = tex2D(_UTex, uv);
  46. fixed4 vcol = tex2D(_VTex, uv);
  47. float r = ycol.a + 1.4022 * vcol.a - 0.7011;
  48. float g = ycol.a - 0.3456 * ucol.a - 0.7145 * vcol.a + 0.53005;
  49. float b = ycol.a + 1.771 * ucol.a - 0.8855;
  50. fixed4 col = fixed4(b, g, r, 1);
  51. col.rgb = GammaToLinearSpace(col.rgb);
  52. return col;
  53. }
  54. ENDCG
  55. }
  56. }
  57. }