redef var vertex_shader_source = """
// Vertex coordinates
attribute vec4 coord;
// Vertex color tint
attribute vec4 color;
// Vertex translation
attribute vec4 translation;
// Vertex scaling
attribute float scale;
// Vertex coordinates on textures
attribute vec2 tex_coord;
// Model view projection matrix
uniform mat4 mvp;
// Current world time, in seconds
uniform float time;
// Rotation matrix
attribute vec4 rotation_row0;
attribute vec4 rotation_row1;
attribute vec4 rotation_row2;
attribute vec4 rotation_row3;
// Animation speed, frames per seconds
attribute float a_fps;
// Number of frames in the animation
attribute float a_n_frames;
// World coordinate of the animation (for aspect ratio)
attribute vec2 a_coord;
// Animation texture coordinates of the first frame
attribute vec2 a_tex_coord;
// Animation texture coordinates difference between frames
attribute vec2 a_tex_diff;
// Animation start time, in reference to `time`
attribute float a_start;
// Number of loops to play of the animation
attribute float a_loops;
mat4 rotation()
{
return mat4(rotation_row0, rotation_row1, rotation_row2, rotation_row3);
}
// Output to the fragment shader
varying vec4 v_color;
varying vec2 v_coord;
// Is there an active animation?
varying float v_animated;
void main()
{
vec3 c; // coords
float end = a_start + a_loops/a_fps*a_n_frames;
if (a_fps != 0.0 && (a_loops == -1.0 || time < end)) {
// in animation
float frame = mod(floor((time-a_start)*a_fps), a_n_frames);
v_coord = a_tex_coord + a_tex_diff*frame;
c = vec3(a_coord, coord.z);
v_animated = 1.0;
} else {
// static
v_coord = tex_coord;
c = coord.xyz;
v_animated = 0.0;
}
gl_Position = (vec4(c * scale, 1.0) * rotation() + translation)* mvp;
v_color = vec4(color.rgb*color.a, color.a);
}
""" @
lib/gamnit/flat/flat_core.nit:638,2--720,26