AlphaBlendYUV.shader 1.4 KB

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