1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-01-09 02:43:25 +08:00
Godot-Shader-Lib/addons/ShaderLib/UV/FlipbookUV.gdshaderinc
Digvijaysinh Gohil 93f6927a1f #4 resolved
2024-02-22 16:21:09 +05:30

16 lines
779 B
Plaintext

vec2 flipbook_uv(vec2 uv, int rows, int columns, float anim_speed){
int start_frame = 1;
int end_frame = rows * columns;
start_frame += int(fract(TIME * anim_speed) * float(end_frame));
float _frame = float(clamp(start_frame, 0, end_frame));
vec2 _off_per_frame = vec2((1.0 / float(columns)), (1.0 / float(rows)));
vec2 _sprite_size = vec2(uv.x / float(columns), uv.y / float(rows));
vec2 _current_sprite = vec2(0.0, 1.0 - _off_per_frame.y);
_current_sprite.x += _frame * _off_per_frame.x;
float _row_index;
float _mod = modf(_frame / float(columns), _row_index);
_current_sprite.y -= 1.0 - (_row_index * _off_per_frame.y);
_current_sprite.x -= _row_index * float(columns) * _off_per_frame.x;
vec2 _sprite_uv = (_sprite_size + _current_sprite);
return _sprite_uv;
}