Browse Source

Beginning of LOD work

master
A.Olokhtonov 2 weeks ago
parent
commit
5edb5ed94e
  1. 60
      import_worker.js
  2. 8
      render.js

60
import_worker.js

@ -11,7 +11,10 @@ onmessage = (e) => { @@ -11,7 +11,10 @@ onmessage = (e) => {
} else if (msg.type === 'import') {
const text = msg.text;
if (parse(text)) {
traces['0'].geo = generate('0');
const geo = generate('0');
traces['0'].geo = geo;
traces['0'].lod1 = lod(geo, 1);
traces['0'].lod2 = lod(geo, 2);
delete traces['0'].raw;
postMessage({'type': 'trace', 'data': traces['0']});
}
@ -305,7 +308,7 @@ function pack_instruction(instruction, positions, sizes, colors, uvs, starts, y) @@ -305,7 +308,7 @@ function pack_instruction(instruction, positions, sizes, colors, uvs, starts, y)
const next_stage = instruction.lanes['0'][i + 1];
stage_cycles = next_stage.c - stage.c;
} else {
stage_cycles = instruction.retcyc - stage.c;
stage_cycles = isNaN(instruction.retcyc) ? 0 : instruction.retcyc - stage.c;
}
if (stage_cycles > max_stage_cycles) {
@ -399,3 +402,56 @@ function generate(trace_id) { @@ -399,3 +402,56 @@ function generate(trace_id) {
return result;
}
function lod(geo) {
let x11, x12, y1, x21, x22, y2;
let merged_rows = 0;
let merged_quads = 0;
let row_y;
const merge_count = 100;
const merged_vertices = [];
for (let i = 0; i < geo.pos.length; i += 2) {
const at_x = geo.pos[i + 0];
const at_y = geo.pos[i + 1];
const w = geo.size[i + 0];
const h = geo.size[i + 1];
// TODO: error metric, make sure nothing "sticks out" too much
if (merged_quads === 0) {
x11 = x21 = at_x;
y2 = row_y = at_y + h;
}
if (merged_rows === 0) {
y1 = at_y;
if (merged_quads === 0) {
x12 = x22 = at_x;
}
}
x12 = Math.max(x12, at_x + w);
x22 = Math.max(x22, at_x + w);
++merged_quads;
if (at_y != row_y) {
merged_quads = 0;
++merged_rows;
}
if (merged_rows === merge_count) {
merged_vertices.push(
x11, y1, x12, y1,
x21, y2, x22, y2
);
console.log(`(${x11}, ${y1}) - (${x12}, ${y1}) - (${x21}, ${y2}) - (${x22}, ${y2})`);
merged_rows = 0;
}
}
}

8
render.js

@ -6,7 +6,7 @@ let config = { @@ -6,7 +6,7 @@ let config = {
bytes_per_quad: 28,
w: 40,
h: 20,
padding: 4,
padding: 2,
predefined_colors: {
'Np': [75, 62, 143],
@ -75,6 +75,7 @@ const tquad_vs_src = `#version 300 es @@ -75,6 +75,7 @@ const tquad_vs_src = `#version 300 es
out vec2 v_cycle;
out vec2 v_textile;
out float v_padscale;
out float v_scale;
flat out int v_extra;
void main() {
@ -133,6 +134,7 @@ const tquad_vs_src = `#version 300 es @@ -133,6 +134,7 @@ const tquad_vs_src = `#version 300 es
v_cycle = cycle;
v_textile = u_textile;
v_padscale = u_tile.x / (u_tile.x + u_padding);
v_scale = u_scale;
if (cycles.x < 0.5 && u_extra != 0) {
gl_Position = vec4(999.9, 999.9, 1.0, 1.0);
@ -149,6 +151,7 @@ const tquad_fs_src = `#version 300 es @@ -149,6 +151,7 @@ const tquad_fs_src = `#version 300 es
in vec2 v_uv;
in vec2 v_cycle;
in vec2 v_textile;
in float v_scale;
in float v_padscale;
flat in int v_extra;
@ -173,7 +176,8 @@ const tquad_fs_src = `#version 300 es @@ -173,7 +176,8 @@ const tquad_fs_src = `#version 300 es
cuv.x /= v_padscale;
vec2 uv = (cell + cuv) * v_textile;
vec4 text = texture(u_texture, uv);
FragColor = text;
float a = min(u_fade, min(text.a, v_color.a));
FragColor = vec4(text.rgb * a, a);
//FragColor = vec4(cuv, 0.0, 1.0);
//FragColor = vec4(vec3(cell.x / float(width)), 1.0);
}

Loading…
Cancel
Save