|
|
@ -103,11 +103,12 @@ async function draw(state, context) { |
|
|
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
|
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
|
|
// Draw the background pattern
|
|
|
|
// Draw the background pattern
|
|
|
|
gl.useProgram(context.programs['pattern'].dots); |
|
|
|
if (state.background_pattern === 'dots') { |
|
|
|
buffers = context.buffers['pattern']; |
|
|
|
gl.useProgram(context.programs['pattern'].dots); |
|
|
|
locations = context.locations['pattern'].dots; |
|
|
|
buffers = context.buffers['pattern']; |
|
|
|
{ |
|
|
|
locations = context.locations['pattern'].dots; |
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_dot']); |
|
|
|
gl.enableVertexAttribArray(locations['a_center']); |
|
|
|
gl.enableVertexAttribArray(locations['a_center']); |
|
|
|
gl.vertexAttribPointer(locations['a_center'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
gl.vertexAttribPointer(locations['a_center'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
gl.vertexAttribDivisor(locations['a_center'], 1); |
|
|
|
gl.vertexAttribDivisor(locations['a_center'], 1); |
|
|
@ -129,7 +130,7 @@ async function draw(state, context) { |
|
|
|
|
|
|
|
|
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_dot']); |
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, dot_instances, gl.STREAM_DRAW); |
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, dot_instances, gl.STREAM_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, dot_instances.length / 2); |
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, dot_instances.length / 2); |
|
|
@ -142,14 +143,58 @@ async function draw(state, context) { |
|
|
|
|
|
|
|
|
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_dot']); |
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, dot_instances, gl.STREAM_DRAW); |
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, dot_instances, gl.STREAM_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, dot_instances.length / 2); |
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, dot_instances.length / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else if (state.background_pattern === 'grid') { |
|
|
|
|
|
|
|
const zoom = state.canvas.zoom; |
|
|
|
|
|
|
|
const zoom_log10 = Math.log10(zoom); |
|
|
|
|
|
|
|
const zoom_previous = Math.pow(10, Math.floor(zoom_log10)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.useProgram(context.programs['pattern'].grid); |
|
|
|
|
|
|
|
buffers = context.buffers['pattern']; |
|
|
|
|
|
|
|
locations = context.locations['pattern'].grid; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_grid']); |
|
|
|
|
|
|
|
gl.enableVertexAttribArray(locations['a_data']); |
|
|
|
|
|
|
|
gl.vertexAttribPointer(locations['a_data'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
|
|
|
gl.vertexAttribDivisor(locations['a_data'], 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
|
|
|
|
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.uniform1f(locations['u_fadeout'], 1.0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Previous level
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const grid_instances = new Float32Array(geometry_gen_fullscreen_grid_1d(state, context, 10 / zoom_previous, 10 / zoom_previous)); |
|
|
|
|
|
|
|
const t = Math.min(1.0, (zoom / zoom_previous) / 10.0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_grid']); |
|
|
|
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, grid_instances, gl.STREAM_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, grid_instances.length / 2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Next level
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const grid_instances = new Float32Array(geometry_gen_fullscreen_grid_1d(state, context, 100 / zoom_previous, 100 / zoom_previous)); |
|
|
|
|
|
|
|
const t = Math.min(1.0, 1.0 - (zoom / zoom_previous) / 10.0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.uniform1f(locations['u_fadeout'], t); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance_grid']); |
|
|
|
|
|
|
|
gl.bufferData(gl.ARRAY_BUFFER, grid_instances, gl.STREAM_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gl.drawArraysInstanced(gl.TRIANGLES, 0, 6, grid_instances.length / 2); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); |
|
|
|
gl.clear(gl.DEPTH_BUFFER_BIT); // draw strokes above the background pattern
|
|
|
|
gl.useProgram(context.programs['sdf'].main); |
|
|
|
gl.useProgram(context.programs['sdf'].main); |
|
|
|
buffers = context.buffers['sdf']; |
|
|
|
buffers = context.buffers['sdf']; |
|
|
|
locations = context.locations['sdf'].main; |
|
|
|
locations = context.locations['sdf'].main; |
|
|
|