Chromakey2.shader 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2. //Shader "Unlit/Chromakey2"
  3. Shader "Unlit/ChromaKey2" {
  4. Properties {
  5. _MainTex ("Base (RGB)", 2D) = "white" {}
  6. _thresh ("Threshold", Range (0, 16)) = 0.8
  7. _slope ("Slope", Range (0, 1)) = 0.2
  8. _keyingColor ("Key Colour", Color) = (1,1,1,1)
  9. }
  10. SubShader {
  11. Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
  12. LOD 100
  13. Lighting Off
  14. ZWrite Off
  15. AlphaTest Off
  16. Blend SrcAlpha OneMinusSrcAlpha
  17. Pass {
  18. CGPROGRAM
  19. #pragma vertex vert
  20. #pragma fragment frag
  21. #pragma fragmentoption ARB_precision_hint_fastest
  22. sampler2D _MainTex;
  23. float4 _MainTex_ST;
  24. float3 _keyingColor;
  25. float _thresh; // 0.8
  26. float _slope; // 0.2
  27. #include "UnityCG.cginc"
  28. struct appdata
  29. {
  30. float4 vertex : POSITION;
  31. float2 uv : TEXCOORD0;
  32. };
  33. struct v2f
  34. {
  35. float2 uv : TEXCOORD0;
  36. UNITY_FOG_COORDS(1)
  37. float4 vertex : SV_POSITION;
  38. };
  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. float4 frag(v2f i) : SV_Target{
  49. float3 input_color = tex2D(_MainTex, i.uv).rgb;
  50. float d = abs(length(abs(_keyingColor.rgb - input_color.rgb)));
  51. float edge0 = _thresh * (1.0 - _slope);
  52. float alpha = smoothstep(edge0, _thresh, d);
  53. return float4(input_color, alpha);
  54. }
  55. ENDCG
  56. }
  57. }
  58. FallBack "Unlit"
  59. }