[Solved] UV Shaders and SpriteFrames/AnimatedSprite2D don't seem to work together well

Godot Version

A simple shader that changes/multiplies the UV of a texture applied to an AnimatedSprite2D with any SpriteFrames. I’m attempting to make an animated beam whose UV.x scales along with the scale of the AnimatedSprite, but UV won’t work on the AnimatedSprite for some reason.

Question

How can I apply a UV shader on an AnimatedSprite2D? The usual solutions didn’t work (searching docs, searching for answers on this forum, etc.)

Something tells me it’s the SpriteFrames blocking the UV from the actual texture, but I’m not sure.

uniform float scale_x = 2.0;

void fragment() {
	vec2 uv = UV;
	uv.x *= scale_x;
// Does not change anything at all with the texture. Using a hard-coded value doesn't work either.

You are not writing to anything, is this all your code? Just creating a new variable uv doesn’t make anything happen in the rest of the shader, you need to assign it back to UV

UV is a constant in fragment() though, so you have to modify it in vertex().
Or you manually read COLOR from TEXTURE in fragment().

That is true indeed, you need to replace the texture sampling code here instead

oh yeesh
tysm for that, i did something like that by just making a modified version of uv and using it in texture() and that seems to do the job :smiley:

shader_type canvas_item;

uniform float scale_x = 1.0;

void fragment() {
	COLOR = texture(TEXTURE, vec2(UV.x * scale_x, UV.y));
}