Browse Source

A simple (and bad) LOD determination scheme

sdf
A.Olokhtonov 8 hours ago
parent
commit
d2adce838b
  1. 19
      client/webgl_draw.js
  2. 9
      client/webgl_shaders.js

19
client/webgl_draw.js

@ -273,23 +273,8 @@ async function draw(state, context, animate, ts) {
} }
} }
if (false) { // TODO: what do we do with this
// TODO: @speed maybe we can get this while clipping "for free"? const circle_lod = Math.ceil(Math.min(7, 1 + Math.sqrt(state.canvas.zoom)));
let largest_width = 0;
for (let i = 0; i < context.clipped_indices.size; ++i) {
const stroke_id = context.clipped_indices.data[i];
const stroke = state.events[stroke_id];
if (stroke.width > largest_width) {
largest_width = stroke.width;
}
}
largest_width *= state.canvas.zoom;
}
// Largest distance from N-th circle LOD to a real circle should be less than 1 unit (pixel)
const circle_lod = 4; // largest_width > 0 ? Math.ceil(Math.PI / Math.acos(1 - 1 / largest_width)) : 0;
const circle_data = geometry_good_circle_and_dummy(circle_lod); const circle_data = geometry_good_circle_and_dummy(circle_lod);
// "Static" data upload // "Static" data upload

9
client/webgl_shaders.js

@ -12,7 +12,6 @@ const sdf_vs_src = `#version 300 es
uniform int u_stroke_count; uniform int u_stroke_count;
uniform int u_stroke_texture_size; uniform int u_stroke_texture_size;
uniform highp usampler2D u_stroke_data; uniform highp usampler2D u_stroke_data;
uniform float u_fixed_pixel_width;
uniform int u_circle_points; uniform int u_circle_points;
out vec3 v_color; out vec3 v_color;
@ -34,10 +33,6 @@ const sdf_vs_src = `#version 300 es
uvec4 stroke_data = texelFetch(u_stroke_data, ivec2(stroke_data_x, stroke_data_y), 0); uvec4 stroke_data = texelFetch(u_stroke_data, ivec2(stroke_data_x, stroke_data_y), 0);
float radius = float(stroke_data.w); float radius = float(stroke_data.w);
if (u_fixed_pixel_width > 0.0) {
radius = u_fixed_pixel_width / u_scale.x;
}
vec2 pos; vec2 pos;
if (vertex_index < u_circle_points) { if (vertex_index < u_circle_points) {
@ -88,7 +83,7 @@ const sdf_fs_src = `#version 300 es
void main() { void main() {
if (u_debug_mode == 0) { if (u_debug_mode == 0) {
float alpha = 0.5; float alpha = 0.75;
FragColor = vec4(v_color * alpha, alpha); FragColor = vec4(v_color * alpha, alpha);
} else { } else {
FragColor = vec4(0.2, 0.0, 0.0, 0.2); FragColor = vec4(0.2, 0.0, 0.0, 0.2);
@ -327,10 +322,8 @@ function init_webgl(state, context) {
gl.enable(gl.BLEND); gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
/*
gl.enable(gl.DEPTH_TEST); gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.NOTEQUAL); gl.depthFunc(gl.NOTEQUAL);
*/
context.gpu_timer_ext = gl.getExtension('EXT_disjoint_timer_query_webgl2'); context.gpu_timer_ext = gl.getExtension('EXT_disjoint_timer_query_webgl2');
if (context.gpu_timer_ext === null) { if (context.gpu_timer_ext === null) {

Loading…
Cancel
Save