Universal Chroma Key Shader provides you a simple shader to achieve the chroma key compositing effect on any texture, including movie textures. 

Chroma Key Shader in Action

Chroma Key Shader in Action

 

It makes the selected color of your texture (image, video or webcam capture) transparent, so you can easily remove the background. You can place any other content behind or in front, also using the shader, so you can get your desired composition.

Examples of uses:

  • Removing the background of a video to simulate another background
  • Get textures with transparency using JPG files instead of bigger PNGs with alpha
  • Create 3D parallax.

Features: 

  • You can select the color to be removed (most often used is green, but any color can be assigned). -You can control the color tolerance to remove similar colors
  • You can control the strength of the cutoff -You can change these values on runtime
  • You can use the shader multiple times in the same scene

Included in the package:

  • The shader
  • Sample scene

Tested platforms:

  • Windows and Mac Standalone
  • Android
  • WebPlayer
  • It should work in all platforms.

To change programatically on runtime the behavior of the shader, you can do it on this way:

renderer.material.SetFloat("_Sens", 0.2f);
renderer.material.SetFloat("_Cutoff", 0.4f);
renderer.material.SetColor("_Color",  new Color(0f, 1f, 0f));

review

12 Comments

  1. Haim
    Mie 4, Febrero 2015

    How can I use this on android?
    Unity wont compile with MovieTexture.

  2. Daniel
    Vie 13, Febrero 2015

    Can this be inverted? Say I JUST want the green part and to key out the rest?

  3. rodripf
    Jue 19, Marzo 2015

    The shader works perfectly on Andrid. However, as you say, if you want to play video MovieTexture is not a valid alternative. Although the shader works in android you should use another method to show movies. I recommend this one from the asset store.
    Thanks for your interest and sorry for the delayed answer.

  4. rodripf
    Jue 19, Marzo 2015

    Yes, you can accomplish that with a simple modification in the shader. You can buy it and modify it by yourself or if you want I can code it for you. Thanks for your interest.

  5. danielm
    Jue 28, Mayo 2015

    hi, i want to use this shader with the method Graphics.Blit, and i want to know if it works, because i’ve tried with other shaders and they don´t work

  6. georgem
    Jue 11, Junio 2015

    Hi
    Can I use it with vuforia (android, unity) , so to get a transparent video in front of an image target?
    Thanks

  7. David
    Mar 30, Junio 2015

    Hi! Does your shader works on iOS?

  8. Tiago
    Sab 10, Octubre 2015

    Can I use this with a real-time webcam feed in Unity where I would have a chroma set up behind the person facing the camera?

  9. rodripf
    Lun 15, Febrero 2016

    Yes it does

  10. rodripf
    Lun 15, Febrero 2016

    Yes you can!

  11. rodripf
    Lun 15, Febrero 2016

    Yes you can, I’ve used this for one of my projects!

  12. rodripf
    Lun 15, Febrero 2016

    I sincerly don’t know, never tested that.

Leave a Reply