Chromakey.shader 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. Shader "Chromakey/Mask" {
  2. Properties {
  3. _MainTex ("Base (RGB)", 2D) = "white" {}
  4. //_MaskCol ("Mask Color", Color) = (1.0, 0.0, 0.0, 1.0)
  5. }
  6. SubShader {
  7. Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
  8. LOD 100
  9. ZWrite Off
  10. Blend SrcAlpha OneMinusSrcAlpha
  11. CGINCLUDE
  12. #include "UnityCG.cginc"
  13. half3 NormalizeColor (half3 color) {
  14. //return color / max(dot(color, half3(1.0f/3.0f)), 0.0001);
  15. return color / dot(color, fixed3(0.5,0.5,0.01));
  16. }
  17. half4 MaskColor (half3 mCol, half3 cCol) {
  18. //half4 d = distance(NormalizeColor(mCol.rgb), NormalizeColor(cCol.rgb));
  19. return ((mCol.g - (mCol.r + mCol.b)) > 0.10 ) ? half4(mCol.rgb,0.0) : half4(mCol.rgb,1.0);
  20. }
  21. ENDCG
  22. Pass {
  23. Lighting Off
  24. //Cull Off ZWrite On Lighting Off Fog { Mode off }
  25. //Blend SrcAlpha OneMinusSrcAlpha
  26. CGPROGRAM
  27. #pragma vertex vert_img
  28. #pragma fragment frag
  29. #pragma fragmentoption ARB_precision_hint_fastest
  30. uniform sampler2D _MainTex;
  31. uniform float4 _MaskCol;
  32. half4 frag (v2f_img i) : COLOR {
  33. half4 col = tex2D(_MainTex, i.uv);
  34. half4 mask = MaskColor(col.rgb, _MaskCol.rgb);
  35. //return col * mask;
  36. return mask;
  37. }
  38. ENDCG
  39. }
  40. }
  41. Fallback off
  42. }