NRBackgroundYUV.shader 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Shader "NRSDK/NRBackgroundYUV"
  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 { "Queue" = "Background-1" "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. float4 _MainTex_ST;
  32. sampler2D _UTex;
  33. sampler2D _VTex;
  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_bg = fixed4(b, g, r, 1);
  51. col_bg.rgb = GammaToLinearSpace(col_bg.rgb);
  52. return col_bg;
  53. }
  54. ENDCG
  55. }
  56. }
  57. }