|
|
@ -270,6 +270,63 @@ const dots_fs_src = `#version 300 es |
|
|
|
} |
|
|
|
} |
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
const iquad_vs_src = `#version 300 es
|
|
|
|
|
|
|
|
in vec2 a_topleft; // per-instance
|
|
|
|
|
|
|
|
in vec2 a_bottomright; // per-instance
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uniform vec2 u_scale; |
|
|
|
|
|
|
|
uniform vec2 u_res; |
|
|
|
|
|
|
|
uniform vec2 u_translation; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out vec3 v_color; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void main() { |
|
|
|
|
|
|
|
vec2 pos; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int vertex_index = gl_VertexID % 6; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (vertex_index == 0) { |
|
|
|
|
|
|
|
// top left
|
|
|
|
|
|
|
|
pos = a_topleft; |
|
|
|
|
|
|
|
} else if (vertex_index == 1 || vertex_index == 5) { |
|
|
|
|
|
|
|
// top right
|
|
|
|
|
|
|
|
pos = vec2(a_bottomright.x, a_topleft.y); |
|
|
|
|
|
|
|
} else if (vertex_index == 2 || vertex_index == 4) { |
|
|
|
|
|
|
|
// bottom left
|
|
|
|
|
|
|
|
pos = vec2(a_topleft.x, a_bottomright.y); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// bottom right
|
|
|
|
|
|
|
|
pos = a_bottomright; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v_color = vec3( |
|
|
|
|
|
|
|
float(int(a_topleft.x) * 908125 % 255) / 255.0, |
|
|
|
|
|
|
|
float(int(a_topleft.y) * 257722 % 255) / 255.0, |
|
|
|
|
|
|
|
float(int(a_bottomright.y) * 826586 % 255) / 255.0 |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vec2 screen01 = (pos * u_scale + u_translation) / u_res; |
|
|
|
|
|
|
|
vec2 screen02 = screen01 * 2.0; |
|
|
|
|
|
|
|
screen02.y = 2.0 - screen02.y; |
|
|
|
|
|
|
|
vec2 screen11 = screen02 - 1.0; |
|
|
|
|
|
|
|
gl_Position = vec4(screen11, 0.0, 1.0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const iquad_fs_src = `#version 300 es
|
|
|
|
|
|
|
|
precision highp float; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
layout(location = 0) out vec4 FragColor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
in vec3 v_color; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void main() { |
|
|
|
|
|
|
|
FragColor = vec4(v_color, 0.5); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
function init_webgl(state, context) { |
|
|
|
function init_webgl(state, context) { |
|
|
|
context.canvas = document.querySelector('#c'); |
|
|
|
context.canvas = document.querySelector('#c'); |
|
|
|
context.gl = context.canvas.getContext('webgl2', { |
|
|
|
context.gl = context.canvas.getContext('webgl2', { |
|
|
@ -303,11 +360,15 @@ function init_webgl(state, context) { |
|
|
|
|
|
|
|
|
|
|
|
const grid_vs = create_shader(gl, gl.VERTEX_SHADER, grid_vs_src); |
|
|
|
const grid_vs = create_shader(gl, gl.VERTEX_SHADER, grid_vs_src); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const iquad_vs = create_shader(gl, gl.VERTEX_SHADER, iquad_vs_src); |
|
|
|
|
|
|
|
const iquad_fs = create_shader(gl, gl.FRAGMENT_SHADER, iquad_fs_src); |
|
|
|
|
|
|
|
|
|
|
|
context.programs = { |
|
|
|
context.programs = { |
|
|
|
'image': create_program(gl, quad_vs, quad_fs), |
|
|
|
'image': create_program(gl, quad_vs, quad_fs), |
|
|
|
'main': create_program(gl, sdf_vs, sdf_fs), |
|
|
|
'main': create_program(gl, sdf_vs, sdf_fs), |
|
|
|
'dots': create_program(gl, dots_vs, dots_fs), |
|
|
|
'dots': create_program(gl, dots_vs, dots_fs), |
|
|
|
'grid': create_program(gl, grid_vs, dots_fs), |
|
|
|
'grid': create_program(gl, grid_vs, dots_fs), |
|
|
|
|
|
|
|
'iquad': create_program(gl, iquad_vs, iquad_fs), |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
context.buffers = { |
|
|
|
context.buffers = { |
|
|
@ -318,6 +379,7 @@ function init_webgl(state, context) { |
|
|
|
'b_instance_grid': gl.createBuffer(), |
|
|
|
'b_instance_grid': gl.createBuffer(), |
|
|
|
'b_dot': gl.createBuffer(), |
|
|
|
'b_dot': gl.createBuffer(), |
|
|
|
'b_hud': gl.createBuffer(), |
|
|
|
'b_hud': gl.createBuffer(), |
|
|
|
|
|
|
|
'b_iquads': gl.createBuffer(), |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
context.textures = { |
|
|
|
context.textures = { |
|
|
|