do voronoi dance, once more?
This commit is contained in:
parent
b8fc4e1710
commit
c2365d3668
4 changed files with 22 additions and 15 deletions
|
@ -129,7 +129,7 @@ class GameInstance {
|
||||||
|
|
||||||
const planet_points = [];
|
const planet_points = [];
|
||||||
for(let i = 0; i < planets.length; i += 3) {
|
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 = this.resizer.get_viewbox();
|
||||||
const bbox = {
|
const bbox = {
|
||||||
|
@ -307,6 +307,7 @@ class GameInstance {
|
||||||
GL.viewport(0, 0, GL.canvas.width, GL.canvas.height);
|
GL.viewport(0, 0, GL.canvas.width, GL.canvas.height);
|
||||||
GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
|
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_viewbox", new Uniform4f(this.resizer.get_viewbox()));
|
||||||
this.vor_shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION));
|
this.vor_shader.uniform(GL, "u_resolution", new Uniform2f(RESOLUTION));
|
||||||
this.vor_shader.uniform(GL, "u_vor", new UniformBool(this.use_vor));
|
this.vor_shader.uniform(GL, "u_vor", new UniformBool(this.use_vor));
|
||||||
|
|
|
@ -39,24 +39,29 @@ export class VoronoiBuilder {
|
||||||
a_own.push(planetId);
|
a_own.push(planetId);
|
||||||
|
|
||||||
for (let edge of cell.halfedges) {
|
for (let edge of cell.halfedges) {
|
||||||
ids.push(centerId);
|
|
||||||
|
|
||||||
const start = edge.getStartpoint();
|
const start = edge.getStartpoint();
|
||||||
ids.push(vertCount++);
|
|
||||||
|
|
||||||
a_pos.push(start.x, start.y);
|
|
||||||
a_own.push(planetId);
|
|
||||||
|
|
||||||
const end = edge.getEndpoint();
|
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_pos.push(end.x, end.y);
|
||||||
a_own.push(planetId);
|
a_own.push(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ib = new IndexBuffer(gl, ids);
|
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 vb_own = new VertexBuffer(gl, a_own);
|
||||||
|
|
||||||
const layout_pos = new VertexBufferLayout();
|
const layout_pos = new VertexBufferLayout();
|
||||||
|
|
|
@ -12,5 +12,5 @@ varying vec3 v_color;
|
||||||
varying vec2 v_pos;
|
varying vec2 v_pos;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_FragColor = vec4(v_color, 0.3);
|
gl_FragColor = vec4(v_color, 0.6);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ attribute float a_own;
|
||||||
uniform vec3 u_planet_colours[$PLANETS * 2];
|
uniform vec3 u_planet_colours[$PLANETS * 2];
|
||||||
uniform vec4 u_viewbox; // [x, y, width, height]
|
uniform vec4 u_viewbox; // [x, y, width, height]
|
||||||
uniform vec2 u_resolution;
|
uniform vec2 u_resolution;
|
||||||
|
uniform float u_time;
|
||||||
|
|
||||||
varying vec2 v_pos;
|
varying vec2 v_pos;
|
||||||
varying vec3 v_color;
|
varying vec3 v_color;
|
||||||
|
@ -21,14 +22,14 @@ void main() {
|
||||||
// So translate and scale the viewbox**
|
// So translate and scale the viewbox**
|
||||||
uv -= u_viewbox.xy + (u_viewbox.zw * 0.5);
|
uv -= u_viewbox.xy + (u_viewbox.zw * 0.5);
|
||||||
uv /= 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) {
|
if (own < 0) {
|
||||||
v_color = vec3(0., 0., 0.);
|
v_color = vec3(0., 0., 0.);
|
||||||
} else {
|
} 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);
|
gl_Position = vec4(uv.xy, 0.0, 1.0);
|
||||||
|
|
Loading…
Reference in a new issue