|
|
|
@ -106,16 +106,21 @@ async function draw(state, context) {
@@ -106,16 +106,21 @@ async function draw(state, context) {
|
|
|
|
|
gl.useProgram(context.programs['pattern'].dots); |
|
|
|
|
buffers = context.buffers['pattern']; |
|
|
|
|
locations = context.locations['pattern'].dots; |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
if (state.canvas.zoom >= config.pattern_fadeout_min) { |
|
|
|
|
// Reused data
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_dot']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([10, 0, 20, 0, 10, 10]), gl.STREAM_DRAW); |
|
|
|
|
|
|
|
|
|
const one_dot = new Float32Array(geometry_gen_circle(0, 0, 1, 32)); |
|
|
|
|
const dot_instances = new Float32Array(geometry_gen_fullscreen_grid(state, context, 32, 32, 50, 50)); |
|
|
|
|
|
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, one_dot, gl.STREAM_DRAW); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_xy']); |
|
|
|
|
gl.vertexAttribPointer(locations['a_xy'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
|
|
|
|
|
// Per-instance data
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([100, 100, 150, 150, 10, 10, 200, 10]), gl.STREAM_DRAW); |
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, dot_instances, gl.STREAM_DRAW); |
|
|
|
|
gl.enableVertexAttribArray(locations['a_center']); |
|
|
|
|
gl.vertexAttribPointer(locations['a_center'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
gl.vertexAttribDivisor(locations['a_center'], 1); |
|
|
|
@ -124,9 +129,17 @@ async function draw(state, context) {
@@ -124,9 +129,17 @@ async function draw(state, context) {
|
|
|
|
|
gl.uniform2f(locations['u_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 3, 4); |
|
|
|
|
if (config.pattern_fadeout_min <= state.canvas.zoom && state.canvas.zoom <= config.pattern_fadeout_max) { |
|
|
|
|
const t = (state.canvas.zoom - config.pattern_fadeout_min) / (config.pattern_fadeout_max - config.pattern_fadeout_min); |
|
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
|
} else { |
|
|
|
|
gl.uniform1f(locations['u_fadeout'], 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, one_dot.length / 2, dot_instances.length / 2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); |
|
|
|
|
gl.useProgram(context.programs['sdf'].main); |
|
|
|
|
buffers = context.buffers['sdf']; |
|
|
|
|
locations = context.locations['sdf'].main; |
|
|
|
|