|
|
@ -106,16 +106,21 @@ async function draw(state, context) { |
|
|
|
gl.useProgram(context.programs['pattern'].dots); |
|
|
|
gl.useProgram(context.programs['pattern'].dots); |
|
|
|
buffers = context.buffers['pattern']; |
|
|
|
buffers = context.buffers['pattern']; |
|
|
|
locations = context.locations['pattern'].dots; |
|
|
|
locations = context.locations['pattern'].dots; |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
if (state.canvas.zoom >= config.pattern_fadeout_min) { |
|
|
|
// Reused data
|
|
|
|
// Reused data
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_dot']); |
|
|
|
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.enableVertexAttribArray(locations['a_xy']); |
|
|
|
gl.vertexAttribPointer(locations['a_xy'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
gl.vertexAttribPointer(locations['a_xy'], 2, gl.FLOAT, false, 2 * 4, 0); |
|
|
|
|
|
|
|
|
|
|
|
// Per-instance data
|
|
|
|
// Per-instance data
|
|
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers['b_instance']); |
|
|
|
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.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); |
|
|
@ -123,10 +128,18 @@ async function draw(state, context) { |
|
|
|
gl.uniform2f(locations['u_res'], context.canvas.width, context.canvas.height); |
|
|
|
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_scale'], state.canvas.zoom, state.canvas.zoom); |
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
gl.uniform2f(locations['u_translation'], state.canvas.offset.x, state.canvas.offset.y); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, 3, 4); |
|
|
|
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); |
|
|
|
gl.useProgram(context.programs['sdf'].main); |
|
|
|
buffers = context.buffers['sdf']; |
|
|
|
buffers = context.buffers['sdf']; |
|
|
|
locations = context.locations['sdf'].main; |
|
|
|
locations = context.locations['sdf'].main; |
|
|
|