From da4c7b84b79be54fac18588d4903ac070eb76541 Mon Sep 17 00:00:00 2001 From: ajuvercr Date: Mon, 20 Apr 2020 10:31:20 +0200 Subject: [PATCH] best I can --- frontend/www/src/voronoi/voronoi.ts | 23 ++++++++++++++--------- frontend/www/static/shaders/frag/vor.glsl | 3 ++- frontend/www/static/shaders/vert/vor.glsl | 3 +++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/frontend/www/src/voronoi/voronoi.ts b/frontend/www/src/voronoi/voronoi.ts index 796e151..2d31a81 100644 --- a/frontend/www/src/voronoi/voronoi.ts +++ b/frontend/www/src/voronoi/voronoi.ts @@ -13,7 +13,6 @@ function to_key(p: Point): string { function round_point(center: Point, point: Point, amount_fn = (b: number) => 0.7): Point { const d = dist(center, point, true); - console.log("f:", amount_fn(d)); const x = center.x + amount_fn(d) * (point.x - center.x); const y = center.y + amount_fn(d) * (point.y - center.y); return { 'x': x, 'y': y }; @@ -46,10 +45,7 @@ function build_point_map(es: Voronoi.HalfEdge[]): (point: Point) => Point { } function get_round_fn(dist_mean: number, amount = 0.7): (d: number) => number { - return (d) => { - console.log(arcctg(d - dist_mean)); - return arcctg((d - dist_mean) * 3) / Math.PI / 2 + 0.5 - } + return (d) => arcctg((d - dist_mean) / dist_mean) / Math.PI + 0.6; } function dist(a: Point, b: Point, norm = false): number { @@ -89,8 +85,13 @@ export class VoronoiBuilder { a_pos.push(cell.site.x, cell.site.y); a_own.push(planetId); + a_own.push(1); - const dist_mean = cell.halfedges.map(e => dist(cell.site, e.getStartpoint(), true)).reduce((a, b) => a + b, 0) / cell.halfedges.length; + const dist_mean = cell.halfedges.map(e => { + const start = e.getStartpoint(); + const end = e.getEndpoint(); + return dist(cell.site, start, true) + dist(cell.site, {'x': (start.x + end.x) / 2, 'y': (start.y + end.y) / 2}, true) + }).reduce((a, b) => a + b, 0) / cell.halfedges.length / 2; const round_fn = get_round_fn(dist_mean); for (let edge of cell.halfedges) { @@ -107,18 +108,21 @@ export class VoronoiBuilder { ids.push(centerId); ids.push(vertCount++); a_pos.push(start.x, start.y); - a_own.push(-1); + a_own.push(planetId); + a_own.push(0); ids.push(vertCount++); a_pos.push(center.x, center.y); - a_own.push(-1); + a_own.push(planetId); + a_own.push(0); ids.push(centerId); ids.push(vertCount - 1); ids.push(vertCount++); a_pos.push(end.x, end.y); - a_own.push(-1); + a_own.push(planetId); + a_own.push(0); } } @@ -131,6 +135,7 @@ export class VoronoiBuilder { const layout_own = new VertexBufferLayout(); layout_own.push(gl.FLOAT, 1, 4, "a_own"); + layout_own.push(gl.FLOAT, 1, 4, "a_intensity"); const vao = new VertexArray(); vao.addBuffer(vb_pos, layout_pos); diff --git a/frontend/www/static/shaders/frag/vor.glsl b/frontend/www/static/shaders/frag/vor.glsl index bcbfb3c..44a8ecd 100644 --- a/frontend/www/static/shaders/frag/vor.glsl +++ b/frontend/www/static/shaders/frag/vor.glsl @@ -8,9 +8,10 @@ uniform float u_step_interval; uniform float u_time; uniform bool u_vor; +varying float v_intensity; varying vec3 v_color; varying vec2 v_pos; void main() { - gl_FragColor = vec4(v_color, 0.6); + gl_FragColor = vec4(v_color, v_intensity * 0.7); } diff --git a/frontend/www/static/shaders/vert/vor.glsl b/frontend/www/static/shaders/vert/vor.glsl index 55aa590..b61d4e4 100644 --- a/frontend/www/static/shaders/vert/vor.glsl +++ b/frontend/www/static/shaders/vert/vor.glsl @@ -4,16 +4,19 @@ precision mediump float; attribute vec2 a_pos; attribute float a_own; +attribute float a_intensity; uniform vec3 u_planet_colours[$PLANETS * 2]; uniform vec4 u_viewbox; // [x, y, width, height] uniform vec2 u_resolution; uniform float u_time; +varying float v_intensity; varying vec2 v_pos; varying vec3 v_color; void main() { + v_intensity = a_intensity; int own = int(a_own); vec2 uv = a_pos;