Scrolling Texture Rotation With Fragment And Vertex Shader Gets Faster

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

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;

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

Omicron | 2020-12-24 22:15

:bust_in_silhouette: Reply From: avencherus

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));