This is a shader script for Godot Engine that implements a chroma key effect. Chroma keying is a technique used to remove a specific color (usually green or blue) from an image or video, making it transparent and allowing other content to show through.
The shader provides RGB Comparison options for the chroma key effect.
- Create a
Sprite
node or aVideoStreamPlayer
on which you want to apply the effect. - Create a new
ShaderMaterial
from the material properties of the node. - Attach the shader script
control.gdshader
to the ShaderMaterial. - Adjust the shader's properties to control the chroma key effect:
transparent_color
: The target color to be replaced with transparency (in RGB format).pickup_range
: The distance allowed from the chroma key color in RBG space (0.0 to 1.0).fade_amount
: The amount of fading effect applied to the color and nearest pixels (0.0 to 1.0).
- The RGB Comparison option gives sharper results, but the code is more straightforward and shorter.
- The HSL Comparison option provides smoother shading but involves a slightly larger code due to the custom HSL conversion function implemented in the shader.
The original video I used is provided by pexels (https://www.pexels.com/video/a-man-with-a-green-background-9488367/)
The original shader script was inspired by Reddit user's post.