This commit is contained in:
ajuvercr 2020-04-20 15:03:59 +02:00
parent 20a2a9c79e
commit 9325b289c4
3 changed files with 13 additions and 4 deletions

View file

@ -34,7 +34,7 @@ function build_point_map(es: Voronoi.HalfEdge[]): (point: Point) => Point {
const start = edge.getStartpoint(); const start = edge.getStartpoint();
const end = edge.getEndpoint(); const end = edge.getEndpoint();
if (dist(start, end) < 0.1 * mean) { // These points have to be merged if (dist(start, end) < 0.03 * mean) { // These points have to be merged
const middle = { 'x': (start.x + end.x) / 2, 'y': (start.y + end.y) / 2 }; const middle = { 'x': (start.x + end.x) / 2, 'y': (start.y + end.y) / 2 };
map[to_key(start)] = middle; map[to_key(start)] = middle;
map[to_key(end)] = middle; map[to_key(end)] = middle;
@ -71,6 +71,7 @@ export class VoronoiBuilder {
const layout = new VertexBufferLayout(); const layout = new VertexBufferLayout();
layout.push(gl.FLOAT, 2, 4, "a_pos"); layout.push(gl.FLOAT, 2, 4, "a_pos");
layout.push(gl.FLOAT, 2, 4, "a_center");
layout.push(gl.FLOAT, 1, 4, "a_own"); layout.push(gl.FLOAT, 1, 4, "a_own");
layout.push(gl.FLOAT, 1, 4, "a_intensity"); layout.push(gl.FLOAT, 1, 4, "a_intensity");
@ -107,6 +108,7 @@ export class VoronoiBuilder {
const centerId = vertCount++; const centerId = vertCount++;
attrs.push(cell.site.x, cell.site.y);
attrs.push(cell.site.x, cell.site.y); attrs.push(cell.site.x, cell.site.y);
attrs.push(planetId); attrs.push(planetId);
attrs.push(1); attrs.push(1);
@ -132,11 +134,13 @@ export class VoronoiBuilder {
ids.push(centerId); ids.push(centerId);
ids.push(vertCount++); ids.push(vertCount++);
attrs.push(start.x, start.y); attrs.push(start.x, start.y);
attrs.push(cell.site.x, cell.site.y);
attrs.push(planetId); attrs.push(planetId);
attrs.push(0); attrs.push(0);
ids.push(vertCount++); ids.push(vertCount++);
attrs.push(center.x, center.y); attrs.push(center.x, center.y);
attrs.push(cell.site.x, cell.site.y);
attrs.push(planetId); attrs.push(planetId);
attrs.push(0); attrs.push(0);
@ -145,6 +149,7 @@ export class VoronoiBuilder {
ids.push(vertCount++); ids.push(vertCount++);
attrs.push(end.x, end.y); attrs.push(end.x, end.y);
attrs.push(cell.site.x, cell.site.y);
attrs.push(planetId); attrs.push(planetId);
attrs.push(0); attrs.push(0);
} }
@ -152,7 +157,6 @@ export class VoronoiBuilder {
this.inner.updateIndexBuffer(gl, ids); this.inner.updateIndexBuffer(gl, ids);
this.inner.updateVAOBuffer(gl, 0, attrs); this.inner.updateVAOBuffer(gl, 0, attrs);
// this.inner.updateVAOBuffer(gl, 1, attrs);
console.log(`Vor things took ${new Date().getTime() - start} ms!`) console.log(`Vor things took ${new Date().getTime() - start} ms!`)
} }

View file

@ -2,16 +2,17 @@
precision mediump float; precision mediump float;
#endif #endif
uniform vec3 u_planet_colours[$PLANETS * 2]; #define PI 3.141592
uniform float u_step_interval; uniform float u_step_interval;
uniform float u_time; uniform float u_time;
uniform bool u_vor; uniform bool u_vor;
varying float v_intensity; varying float v_intensity;
varying float v_dist;
varying vec3 v_color; varying vec3 v_color;
varying vec2 v_pos; varying vec2 v_pos;
void main() { void main() {
gl_FragColor = vec4(v_color, v_intensity * 0.7); gl_FragColor = vec4(v_color, (1.0 - pow(1.0 - v_intensity, 1.23)) * 0.7);
} }

View file

@ -3,6 +3,7 @@ precision mediump float;
#endif #endif
attribute vec2 a_pos; attribute vec2 a_pos;
attribute vec2 a_center;
attribute float a_own; attribute float a_own;
attribute float a_intensity; attribute float a_intensity;
@ -12,11 +13,14 @@ uniform vec2 u_resolution;
uniform float u_time; uniform float u_time;
varying float v_intensity; varying float v_intensity;
varying float v_dist;
varying vec2 v_pos; varying vec2 v_pos;
varying vec3 v_color; varying vec3 v_color;
void main() { void main() {
v_intensity = a_intensity; v_intensity = a_intensity;
v_dist = distance(a_pos * u_resolution , a_center * u_resolution);
int own = int(a_own); int own = int(a_own);
vec2 uv = a_pos; vec2 uv = a_pos;