From c2365d3668183d30cd4aec273ebb4c8e9faebb1b Mon Sep 17 00:00:00 2001 From: ajuvercr Date: Sun, 19 Apr 2020 19:59:40 +0200 Subject: [PATCH] do voronoi dance, once more? --- frontend/www/src/index.ts | 3 ++- frontend/www/src/voronoi/voronoi.ts | 25 ++++++++++++++--------- frontend/www/static/shaders/frag/vor.glsl | 2 +- frontend/www/static/shaders/vert/vor.glsl | 7 ++++--- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/frontend/www/src/index.ts b/frontend/www/src/index.ts index 4c97d17..188fa3d 100644 --- a/frontend/www/src/index.ts +++ b/frontend/www/src/index.ts @@ -129,7 +129,7 @@ class GameInstance { const planet_points = []; for(let i = 0; i < planets.length; i += 3) { - planet_points.push({'x': planets[i], 'y': planets[i+1]}); + planet_points.push({'x': -planets[i], 'y': -planets[i+1]}); } const _bbox = this.resizer.get_viewbox(); const bbox = { @@ -307,6 +307,7 @@ class GameInstance { GL.viewport(0, 0, GL.canvas.width, GL.canvas.height); GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); + this.vor_shader.uniform(GL, "u_time", new Uniform1f((time - this.last_time) / ms_per_frame)); this.vor_shader.uniform(GL, "u_viewbox", new Uniform4f(this.resizer.get_viewbox())); this.vor_shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION)); this.vor_shader.uniform(GL, "u_vor", new UniformBool(this.use_vor)); diff --git a/frontend/www/src/voronoi/voronoi.ts b/frontend/www/src/voronoi/voronoi.ts index 51c88a0..c94959f 100644 --- a/frontend/www/src/voronoi/voronoi.ts +++ b/frontend/www/src/voronoi/voronoi.ts @@ -39,24 +39,29 @@ export class VoronoiBuilder { a_own.push(planetId); for (let edge of cell.halfedges) { - ids.push(centerId); - const start = edge.getStartpoint(); - ids.push(vertCount++); - - a_pos.push(start.x, start.y); - a_own.push(planetId); - const end = edge.getEndpoint(); - ids.push(vertCount++); + const center = {'x': (start.x + end.x) / 2, 'y': (start.y + end.y) / 2}; + ids.push(centerId); + ids.push(vertCount++); + a_pos.push(start.x, start.y); + a_own.push(-1); + + // ids.push(vertCount++); + // a_pos.push(center.x, center.y); + // a_own.push(planetId); + + // ids.push(centerId); + // ids.push(vertCount-1); + ids.push(vertCount++); a_pos.push(end.x, end.y); - a_own.push(planetId); + a_own.push(-1); } } const ib = new IndexBuffer(gl, ids); - const vb_pos = new VertexBuffer(gl, a_pos.map((x) => -1 * x)); + const vb_pos = new VertexBuffer(gl, a_pos); const vb_own = new VertexBuffer(gl, a_own); const layout_pos = new VertexBufferLayout(); diff --git a/frontend/www/static/shaders/frag/vor.glsl b/frontend/www/static/shaders/frag/vor.glsl index 85ea4da..bcbfb3c 100644 --- a/frontend/www/static/shaders/frag/vor.glsl +++ b/frontend/www/static/shaders/frag/vor.glsl @@ -12,5 +12,5 @@ varying vec3 v_color; varying vec2 v_pos; void main() { - gl_FragColor = vec4(v_color, 0.3); + gl_FragColor = vec4(v_color, 0.6); } diff --git a/frontend/www/static/shaders/vert/vor.glsl b/frontend/www/static/shaders/vert/vor.glsl index 07f9ede..55aa590 100644 --- a/frontend/www/static/shaders/vert/vor.glsl +++ b/frontend/www/static/shaders/vert/vor.glsl @@ -8,6 +8,7 @@ attribute float a_own; uniform vec3 u_planet_colours[$PLANETS * 2]; uniform vec4 u_viewbox; // [x, y, width, height] uniform vec2 u_resolution; +uniform float u_time; varying vec2 v_pos; varying vec3 v_color; @@ -21,14 +22,14 @@ void main() { // So translate and scale the viewbox** uv -= u_viewbox.xy + (u_viewbox.zw * 0.5); uv /= u_viewbox.zw * 0.5; + v_pos = uv.xy; - - v_pos = (uv.xy + 1.0) * 0.5; + // v_pos = (uv.xy + 1.0) * 0.5; if (own < 0) { v_color = vec3(0., 0., 0.); } else { - v_color = u_planet_colours[own * 2]; + v_color = mix(u_planet_colours[own * 2], u_planet_colours[own * 2 + 1], u_time); } gl_Position = vec4(uv.xy, 0.0, 1.0);