• Godot HelpShaders
  • Scrolling Texture Rotation With Fragment And Vertex Shader Gets Faster

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

I'm not sure you want to use sine waves(sin & cos) if what you are looking for is linear interpolation. Sine waves are essentially bell curves so the "acceleration" you see is part of the curve.

Hm, well depending on how you use it a sine wave can also give you a linear cycle. For a rotation it might work out that way, for translation it can easily end up a speed up to peak to slow down sort of non-linear interpolation. It's been a while since I've toyed with shaders and sinewaves tho.

2 years later