Skip to content

Commit

Permalink
fixup! [gldemo] allow tile position data to be animated
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorbin committed Oct 14, 2023
1 parent 2734145 commit 75d92b9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions gltiles.vert
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ uniform LayerParams {
in uint layerID;

in vec4 pos;
in vec4 pos_to;
in vec3 anim; // x=start_time, y=duration, z=mode

out float sheetLayer;
out mat3 tileTransform;
Expand All @@ -54,6 +56,32 @@ const mat3 spinOffset = mat3(
);

void main(void) {
vec4 pos_at = pos;

if (anim_enabled && anim.y > 0.0) {
float a = (anim_time - anim.x) / anim.y;
if (a > 0.0) {
switch (int(anim.z)) {

case 1: // loop
a = fract(a);
break;

case 2: // loop-back
if (int(floor(a)) % 2 == 1) {
a = 1.0 - fract(a);
} else {
a = fract(a);
}
break;

default:
a = max(0.0, min(1.0, a));
}
pos_at = mix(pos_at, pos_to, /*a*/ 0.0);
}
}

vec2 offset = pos.xy;
float spin = pos.z;
float scale = pos.w;
Expand Down

0 comments on commit 75d92b9

Please sign in to comment.