chromakeying in godot 3.1

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bluemage

I found a similar question that seemed like it was answered for an older version.

If I have a video that has a green screen effect how do I chromakey out the green?

the old post in reference
https://forum.godotengine.org/35619/how-to-key-out-any-color-using-a-shader-in-godot-3

if anyone can help me. I’d greatly appreciate it.

That answer is still valid in Godot 3.1 AFAIK.

Zylann | 2019-05-31 13:01

:bust_in_silhouette: Reply From: TimurKady

Set “color” to Color(0, 0, 0, 0) for transparency and try pick up the value of “key_distance” (0.2 - 0.4)

shader_type canvas_item;
render_mode blend_mix;

uniform bool use_mult;
uniform float key_distance : hint_range(0, 1);
uniform vec4 chroma_key : hint_color;
uniform vec4 color : hint_color;

void fragment() {
  COLOR = texture(TEXTURE, UV);
  
  if (distance(COLOR, chroma_key) < key_distance) {
    if (use_mult) {
      COLOR =  COLOR * color;      
     }
    else {
      COLOR = color;
     }
   }
}