Shaders: modifying sprite rather than completely overwriting it

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

Hey all,

I’m trying to write a shader that will take a sprite and change some colors. It looks like the following:

shader_type canvas_item;

void fragment() {
    vec4 blend_color = get_some_color_somehow();
    
    COLOR = texture(SCREEN_TEXTURE, SCREEN_UV) * blend_color;
}

However, this is obviously taking the color of what is rendered behind the sprite at the given UV, rather than the color of the sprite itself at that UV. Is it possible for me to get the color of the sprite itself, or am I going to have to find a different solution?

:bust_in_silhouette: Reply From: johnygames

I’m no shader expert, but the problem seems to be that you are sampling SCREEN_TEXTURE instead of TEXTURE Try the following:

shader_type canvas_item;

void fragment() {

    vec4 blend_color = get_some_color_somehow();

    COLOR = texture(TEXTURE,UV) * blend_color;
}

This will modify the texture the way you expect. I hope this helps!

Works perfectly! Thanks!

Bush2Tree | 2020-08-14 01:23