|
|
@ -6,6 +6,7 @@ let config = { |
|
|
|
bytes_per_quad: 28, |
|
|
|
bytes_per_quad: 28, |
|
|
|
w: 32, |
|
|
|
w: 32, |
|
|
|
h: 32, |
|
|
|
h: 32, |
|
|
|
|
|
|
|
padding: 2, |
|
|
|
|
|
|
|
|
|
|
|
predefined_colors: { |
|
|
|
predefined_colors: { |
|
|
|
'Np': [75, 62, 143], |
|
|
|
'Np': [75, 62, 143], |
|
|
@ -69,29 +70,30 @@ const tquad_vs_src = `#version 300 es |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
vec2 cycles = a_size / u_tile; |
|
|
|
vec2 cycles = a_size / u_tile; |
|
|
|
|
|
|
|
vec2 tt = u_textile / u_tile; |
|
|
|
|
|
|
|
|
|
|
|
if (vertex_index == 0) { |
|
|
|
if (vertex_index == 0) { |
|
|
|
// "top left" aka "p1"
|
|
|
|
// "top left" aka "p1"
|
|
|
|
corner = a_pos + inset; |
|
|
|
corner = a_pos; |
|
|
|
uv = a_uv; |
|
|
|
uv = a_uv; |
|
|
|
} else if (vertex_index == 1 || vertex_index == 5) { |
|
|
|
} else if (vertex_index == 1 || vertex_index == 5) { |
|
|
|
// "top right" aka "p2"
|
|
|
|
// "top right" aka "p2"
|
|
|
|
corner = a_pos + vec2(a_size.x, 0) + vec2(-inset.x, inset.y); |
|
|
|
corner = a_pos + vec2(a_size.x, 0); |
|
|
|
uv = a_uv + vec2(u_textile.x * cycles.x, 0); |
|
|
|
uv = a_uv + vec2(u_textile.x * cycles.x, 0); |
|
|
|
} else if (vertex_index == 2 || vertex_index == 4) { |
|
|
|
} else if (vertex_index == 2 || vertex_index == 4) { |
|
|
|
// "bottom left" aka "p3"
|
|
|
|
// "bottom left" aka "p3"
|
|
|
|
corner = a_pos + vec2(0, a_size.y) + vec2(inset.x, -inset.y); |
|
|
|
corner = a_pos + vec2(0, a_size.y); |
|
|
|
uv = a_uv + vec2(0, u_textile.y * cycles.y); |
|
|
|
uv = a_uv + vec2(0, u_textile.y * cycles.y); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// "bottom right" aka "p4"
|
|
|
|
// "bottom right" aka "p4"
|
|
|
|
corner = a_pos + a_size - inset; |
|
|
|
corner = a_pos + a_size; |
|
|
|
uv = a_uv + u_textile * cycles; |
|
|
|
uv = a_uv + u_textile * cycles; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
vec2 screen02 = (corner.xy * vec2(u_scale) + u_translation) / u_res * 2.0; |
|
|
|
vec2 screen02 = (corner.xy * vec2(u_scale) + u_translation) / u_res * 2.0; |
|
|
|
screen02.y = 2.0 - screen02.y; |
|
|
|
screen02.y = 2.0 - screen02.y; |
|
|
|
v_color = a_color; |
|
|
|
v_color = a_color; |
|
|
|
v_uv = uv - u_textile * vec2(0.2); |
|
|
|
v_uv = uv; |
|
|
|
|
|
|
|
|
|
|
|
gl_Position = vec4(screen02 - 1.0, 1.0, 1.0); |
|
|
|
gl_Position = vec4(screen02 - 1.0, 1.0, 1.0); |
|
|
|
} |
|
|
|
} |
|
|
@ -104,12 +106,14 @@ const tquad_fs_src = `#version 300 es |
|
|
|
in vec2 v_uv; |
|
|
|
in vec2 v_uv; |
|
|
|
|
|
|
|
|
|
|
|
uniform sampler2D u_texture; |
|
|
|
uniform sampler2D u_texture; |
|
|
|
|
|
|
|
uniform float u_fade; |
|
|
|
|
|
|
|
|
|
|
|
layout(location = 0) out vec4 FragColor; |
|
|
|
layout(location = 0) out vec4 FragColor; |
|
|
|
|
|
|
|
|
|
|
|
void main() { |
|
|
|
void main() { |
|
|
|
vec4 text = texture(u_texture, v_uv); |
|
|
|
vec4 text = texture(u_texture, v_uv); |
|
|
|
FragColor = vec4(text.rgb * text.a + v_color.rgb * (1.0 - text.a), 1.0); |
|
|
|
text.a = min(min(text.a, v_color.a), u_fade); |
|
|
|
|
|
|
|
FragColor = vec4(text.rgb * text.a + v_color.rgb, 1.0); |
|
|
|
} |
|
|
|
} |
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
@ -147,6 +151,7 @@ function draw(ts, animation) { |
|
|
|
|
|
|
|
|
|
|
|
if (quads.count > 0) { |
|
|
|
if (quads.count > 0) { |
|
|
|
const program = programs['quad']; |
|
|
|
const program = programs['quad']; |
|
|
|
|
|
|
|
const fade = Math.max(0, Math.min(1.25 * zoom - 0.25, 1)); |
|
|
|
|
|
|
|
|
|
|
|
gl.useProgram(program.program); |
|
|
|
gl.useProgram(program.program); |
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_packed']); |
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_packed']); |
|
|
@ -162,6 +167,7 @@ function draw(ts, animation) { |
|
|
|
gl.uniform2f(program.locations['u_textile'], config.w / config.raster_texture_size, config.h / config.raster_texture_size); |
|
|
|
gl.uniform2f(program.locations['u_textile'], config.w / config.raster_texture_size, config.h / config.raster_texture_size); |
|
|
|
gl.uniform1i(program.locations['u_texture'], textures['raster']); |
|
|
|
gl.uniform1i(program.locations['u_texture'], textures['raster']); |
|
|
|
gl.uniform2f(program.locations['u_tile'], config.w, config.h); |
|
|
|
gl.uniform2f(program.locations['u_tile'], config.w, config.h); |
|
|
|
|
|
|
|
gl.uniform1f(program.locations['u_fade'], fade); |
|
|
|
|
|
|
|
|
|
|
|
gl.enableVertexAttribArray(program.locations['a_pos']); |
|
|
|
gl.enableVertexAttribArray(program.locations['a_pos']); |
|
|
|
gl.enableVertexAttribArray(program.locations['a_size']); |
|
|
|
gl.enableVertexAttribArray(program.locations['a_size']); |
|
|
|