From 5bb8b0a7eeb4ad4cfbc2757d63054a8e4553a82b Mon Sep 17 00:00:00 2001 From: "A.Olokhtonov" Date: Sun, 24 Nov 2024 14:05:55 +0300 Subject: [PATCH] Further tune LOD levels to optimize triangle counts. Removed LOD level 7 --- client/config.js | 1 + client/wasm/lod.c | 23 +++++++++++++++++++---- client/wasm/lod.wasm | Bin 3166 -> 3207 bytes client/webgl_draw.js | 15 +++++++++++++-- client/webgl_shaders.js | 3 ++- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/client/config.js b/client/config.js index 298f146..37986f3 100644 --- a/client/config.js +++ b/client/config.js @@ -33,6 +33,7 @@ const config = { offset: { x: 654, y: 372 }, frames: 500, }, + debug_force_lod: null, /* * points of interest (desk/zoomlevel/x/y diff --git a/client/wasm/lod.c b/client/wasm/lod.c index 727b989..4978b38 100644 --- a/client/wasm/lod.c +++ b/client/wasm/lod.c @@ -323,10 +323,25 @@ do_lod(int *clipped_indices, int clipped_count, float zoom, int segment_count = to - from; // Compute recommended LOD level, add to current batch or start new batch - float sqrt_width = __builtin_sqrtf(width[stroke_index]); - int lod = __builtin_roundeven(sqrt_zoom * sqrt_width); // NOTE: there is no regular round, but is shouldn't matt:er - - if (lod > 7) lod = 7; + int lod; + // The LOD levels have been picked manually based on "COM" (Careful Observation Method) + float perceptual_width = width[stroke_index] * zoom; + // The LOD levels have been picked manually based on "COM" (Careful Observation Method) + if (perceptual_width < 1.9f) { + lod = 0; + } else if (perceptual_width < 4.56f) { + lod = 1; + } else if (perceptual_width < 6.12f) { + lod = 2; + } else if (perceptual_width < 25.08f) { + lod = 3; + } else if (perceptual_width < 122.74f) { + lod = 4; + } else if (perceptual_width < 1710.0f) { + lod = 5; + } else { + lod = 6; + } if (batch_size > 0 && lod != last_lod) { // Start new batch diff --git a/client/wasm/lod.wasm b/client/wasm/lod.wasm index 17701b12b9f2369032fe198cda57f1f52997169c..269a030ff7498c0b8435c12ab34065068edfd938 100755 GIT binary patch delta 1883 zcmZ8i%W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9G3R(3AsHMujRE@a z`1!c)x}$Nr+G%(E#*ilFCvcKoQ8eBmRB*#4KTv2gNwUmKsTAS)!U1)+l`*!3?)p@pe^= zvwn@nkUVPjA6oLfr`~gn4*Ug@|=D=IXkxDbK%CjA2PM@MXYpDh_`Tti}aDjCxVQCWm~*MP$Kps z>PRqG@G&PCU0figPTURlBMPJp&gOb+_QG+3Qx`7IP{(Vvuu%ivEQrO0A9*wBA~VGn zGz69w7gLrj6soo5$RZ|W?#2gpN#Zvdq3xmpJ0jUFOPWe1r9*B|gJvq(v`iz8G@4{a zX+R%aJxmlkTxB|TR_;xtz0}mv^s?8ow;My-`{b)wl?KHmxWl%8;@|8JQh2F%m}4i%X76g}5vTFRJ7a>10>V zdD%^tP;6Iadw@;;-ogfdZ)fqpul<=_?3r|1_>ANML7BjArc1|1imPp|j*d7VMhmY3 z)8~BWZ=9djOfjo=0< z8NtWx?01#@p|Fo~zQ0xMvzIFSRnVLC*#|+8eWkMRRrZ&%TR0F8+O}}BSc&gTv20Vf zoxN$dviHn3u!CL5a+eQIRbJGx2zhX%I_wO8yV6?RVU+?DOTC;N&g 0) { stat_total_vertices += batch_size * level.data.indices.size; gl.uniform1i(pr.locations['u_circle_points'], level.data.points.size / 2 - 4); + gl.uniform3f(pr.locations['u_debug_color'], + (lod_level * 785892 + 125127) % 8 / 7, + (lod_level * 901824 + 985835) % 8 / 7, + (lod_level * 232181 + 838533) % 8 / 7, + ); // Points (a, b) and stroke ids are stored in separate cpu buffers so that points can be reused (look at stride and offset values) gl.vertexAttribPointer(pr.locations['a_a'], 2, gl.FLOAT, false, 2 * 4, batch_from * 2 * 4); diff --git a/client/webgl_shaders.js b/client/webgl_shaders.js index 27ff5dc..acddca3 100644 --- a/client/webgl_shaders.js +++ b/client/webgl_shaders.js @@ -76,6 +76,7 @@ const sdf_fs_src = `#version 300 es precision highp float; uniform int u_debug_mode; + uniform vec3 u_debug_color; in vec3 v_color; @@ -86,7 +87,7 @@ const sdf_fs_src = `#version 300 es float alpha = 0.75; FragColor = vec4(v_color * alpha, alpha); } else { - FragColor = vec4(0.2, 0.0, 0.0, 0.2); + FragColor = vec4(u_debug_color, 0.8); } } `;