Files
hotdesking/shaders/globe.gdshader
2025-07-09 03:44:11 -04:00

35 lines
841 B
Plaintext

shader_type canvas_item;
uniform float scroll_x = 0.0;
uniform float scroll_y = 0.0;
uniform float globe_magnitude : hint_range(0.0, 1.0) = 1.0;
void fragment()
{
// Original UVs from 0 to 1
vec2 uv = UV;
//uv.x = mod(uv.x + x_scroll, 1.0);
//uv.y = mod(uv.y + y_scroll, 1.0);
// Remaps UV to -1, 1, i.e. centers on the sprite
vec2 centered_uv = uv * 2.0 - 1.0;
// Radius r of length of the centered UV
float r = length(centered_uv);
if (r > 1.0)
{
discard; // clips anything past the radius of the circle
}
float z = sqrt(1.0 - r * r);
vec2 sphere_uv = centered_uv / (1.0 + z);
sphere_uv.x = mod(sphere_uv.x + scroll_x, 1.0);
sphere_uv.y = mod(sphere_uv.y + scroll_y, 1.0);
sphere_uv = sphere_uv * 0.5 + 0.5;
vec2 final_uv = mix(uv, sphere_uv, globe_magnitude);
COLOR = texture(TEXTURE, final_uv);
}