+1 vote

Hey everyone,

I want to implement a star rating in my game. If its a natural number its no problem, I can modulate the corresponding stars with set_modulate() etc.

But if I have a decimal rating like 3.4 I have to modulate the 4th star only for 40%.

e.g. my white star texture should look like this:
enter image description here
I guess this can be done with shaders, but I have no idea how.

Hope anyone can help me.
I am using godot 3.0 stable.

in Engine by (196 points)

1 Answer

+2 votes

This should work for you:

shader_type canvas_item;

uniform vec4  cover_colour = vec4(1.0, 1.0, 0.0, 1.0);
uniform float percent_covered = 0.0;

void fragment()
{
    vec4 texture_colour = texture(TEXTURE, UV);

    if (texture_colour.a == 1.0 && UV.x < percent_covered)
    {
        texture_colour = cover_colour;
    }

    COLOR = texture_colour;
}
by (52 points)
edited by
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 Frequently asked questions and 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 [email protected] with your username.