+1 vote

I have the following canvas item shader code. The problem with it is that rotation seems to speed up over time. I suspect this is caused by me also offsetting the UV over time. Im looking for way around this. Here is my code:

shader_type canvas_item;

uniform float rotation;
uniform float speed_scale;

vec2 rotateUV(vec2 uv, vec2 pivot, float rot) {
    float cosa = cos(rot);
    float sina = sin(rot);
    uv -= pivot;
    return vec2(
        cosa * uv.x - sina * uv.y,
        cosa * uv.y + sina * uv.x 
    ) + pivot;

void vertex() {
    UV.y += time * speed_scale;


void fragment(){
    vec4 color;
    color = texture(TEXTURE, rotateUV(UV, vec2(0.5), rotation ));
    COLOR = color;
in Engine by (20 points)
edited by

you are creating some kind of spiral function
what are you trying to achieve?

1 Answer

+1 vote
Best answer

This doesn't build, because of time. I'm only able to assume you were using TIME.

The first possible issue is in the way you're using TIME. TIME doesn't return a delta, it accumulates itself. It's total time elapsed. TIME


x += 10 * scale
x += 20 * scale
x += 30 * scale

Another possible problem is that you'll usually need to wrap the results for UVs when using TIME, otherwise it'll keep growing.

Simple example using mod:

COLOR = texture(TEXTURE, UV + vec2(0.0, mod(TIME, 2.0) - 1.0));
by (5,219 points)
selected 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 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.