How to make a sprite white

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DodoIta
:warning: Old Version Published before Godot 3 was released.

Yeah, so… I want to set the Modulate property of a sprite to make it white for a second, but it does not seem possible.
How can I do that?

:bust_in_silhouette: Reply From: Zylann

“Modulate” is a color multiplier, so there is no way to make a sprite brighter with it. It is a bit hackable though, because you can input colors higher than 1 by toggling RAW mode on (usually for HDR and bloom). This will brighten your sprite, but it won’t work if your sprite is too dark, or black for example.

If you are looking for a cleaner solution, you can use a shader to interpolate the sprite regular texture and a white color, with a uniform parameter:

shader_type canvas_item;

uniform float whitening;

void fragment() {
	vec4 texture_color = texture(TEXTURE, UV);
	COLOR = vec4(mix(texture_color.rgb, vec3(1,1,1), whitening), texture_color.a);
}

Thank you! I should dig deeper into shaders

DodoIta | 2017-11-29 10:41

:bust_in_silhouette: Reply From: Michael Paul

A couple of things you could do…

Simple way would be to load a new white texture for the sprite through your code at the desired time and then set it back to the original texture after a second.

If you want cooler effects, you could have a second sprite that is a white silhouette that overlays your normal sprite, but has an alpha value of 0. Then you could tween the alpha to 1 over a few milliseconds, leave it white for a sec and tween it back down to 0. You could expand upon it in lots of ways depending on the effect you are looking for.

Interesting solution, I’ll try it!

DodoIta | 2017-11-29 11:37