+1 vote

Hello,
I've a map for my game and i want a specific color to flick from one color to another to give the game a little life, is there a way to do it in shaders?

in Engine by (1,193 points)

You may want to search for a ChromaKey shader

3 Answers

+1 vote
Best answer

Check : http://docs.godotengine.org/en/stable/learning/features/shading/shading_language.html#examples

Make a fragmentShader, then all you need is to test color value, then change it how you like (or return it unchanged).

by (336 points)
selected by

The link is broken...

0 votes

At least on Godot 2, you can work over COLOR in fragment (on 3 I think is only output).
Using operations to modify the color (some square wave maybe) can be used for flicker effect.

Look at the demos and docs for better reference on the language and how to affect outputs.

by (7,874 points)
+2 votes

This should change all opaque black colors to opaque red in Godot 3.0.2

shader_type canvas_item;

void fragment() {
    vec4 curr_color = texture(TEXTURE,UV); // Get current color of pixel

    if (curr_color == vec4(0,0,0,1)){
        COLOR = vec4(1,0,0,1);
    }else{
        COLOR = curr_color;
    }
}
by (678 points)

thanks, you really saved me.

When using a uniform to set the colors, I was getting float error. Using this approx_equal function worked, but there may be a better way:
bool approx_eq(vec4 c1, vec4 c2) { return all( lessThan( abs( c1 - c2 ), vec4( 0.001, 0.001, 0.001, 0.001) ) ); }

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.