How to make shaders work properly with animation settings

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

I’m following Nolkaloid’s shockwave shader tutorial and using the Kenney Simplified Platformer player spritesheet. I’ve set the Hframe and Vframe properties on the spritesheet to 4 and 2, respectively. My shader code looks like this:

shader_type canvas_item;

uniform vec2 center;
uniform float force;

void fragment() {
    vec2 disp = normalize(UV - center) * force;
    COLOR = texture(TEXTURE, UV - disp);
}

When setting the center to 0.5 and the force to anything above 0, the other sprites in the spritesheet end up coming into the image. How do I fix this?

:bust_in_silhouette: Reply From: magicalogic

That is happening because the UV’s are going beyond the range of 0 - 1.
The easy fix is dividing the (UV - disp) by a number. How big this number is depends on the force.