This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Is it possible to scroll a texture on an isometric tile in a direction (say, Vector(1.0,-1.0) and have the cell look correct? I've tried it with this basic shader applied to a tile:

shader_type canvas_item;

uniform vec2 direction = vec2(0.0,0.0); uniform float speed = 1;

void fragment() { COLOR = texture(TEXTURE, UV + (direction * TIME * speed)); }

But it just causes the entire tile to warp in square shaped blocks, rather than just the isometric shape of the tile. Any way of doing this properly?
enter image description here

Without shader: https://imgur.com/U3DQhAW
With shader: https://imgur.com/YqbJ2eU

Godot version 3.2
in Engine by (42 points)
edited by

1 Answer

+1 vote

Thanks so much to @kleonc for the help, here's the working shader!

shader_type canvas_item;

uniform vec2 direction = vec2(0.0, 0.0);
uniform float speed = 1.0;

vec2 toIsoUV(vec2 uv)
{
    return vec2(uv.x + uv.y - 0.5, -uv.x + uv.y + 0.5);
}

vec2 fromIsoUV(vec2 uv)
{
    return vec2(0.5 * (uv.x - uv.y + 1.0), 0.5 * (uv.x + uv.y));
}

void fragment()
{
    vec2 uv = UV;
    uv -= direction * speed * TIME;
    uv = toIsoUV(uv);
    uv -= floor(uv); // make it into [0, 1) x [0, 1)
    uv = fromIsoUV(uv);
    COLOR = vec4(texture(TEXTURE, uv).rgb, texture(TEXTURE, UV).a);
}
by (42 points)
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 Frequently asked questions and 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 [email protected] with your username.