0 votes

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?

in Engine by (166 points)

1 Answer

+2 votes
Best answer

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!

by (1,847 points)
selected by

Works perfectly! Thanks!

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.