How to make a black sprite flashing white

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

Note: doing a 2D project. in Godot 3.0.6

I noticed that the Modulate property can only brighten the sprite even if I set the color value higher than 1.0.

It doesn’t help me since I have sprites with black(#000000) parts in them and they have to flash between white silhouette.

I tried:

Does anyone have a solution for this?

it’s ridiculous to draw multiple white textures for each sprite animation frame.

Why you don’t use animatedSprite?

I don’t see how you could avoid creating white texture variants for most things. As pallet swaps are no longer supported in modern hardware.

coffeeDragon | 2018-10-04 07:36

You can use shaders to do palette swaps fairly easily.

Diet Estus | 2018-10-05 03:04

:bust_in_silhouette: Reply From: Mastermori

For anyone who was still searching for a solution to this (like me) as there is no easy way to do this exact thing yet, here is my solution:

  1. Add a new ShaderMaterial to the Sprite you want to flash (if it
    already has a shader attached you can just add the code below to
    it).
  2. Add a new Shader (not VisualShader) to the material.
  3. Open the shader and add the following code:

.

shader_type canvas_item;

uniform float white_progress : hint_range(0,1) = 0;

vec3 interpolate_vec3(vec3 start, vec3 end, float delta){
	return start + (end - start) * delta;
}

void fragment(){
	vec4 origin = texture(TEXTURE, UV);
	COLOR.rgb = interpolate_vec3(origin.rgb, vec3(1,1,1), white_progress);
	COLOR.a = origin.a;
}

Now you can use an AnimationPlayer to change the “white_progress” in “Shader Param” to create a flashing sprite.