fix(render): match model lineweight preview curve

This commit is contained in:
Hakan Seven committed 2026-09-02 23:28:34 +03:00
1 parent 76bdab1e5b
commit 2cd1d36661
7 files changed
+74 -16

No files matched your search

+16 -5
View File
@@ -23,6 +23,9 @@ struct Uniforms {
}
@group(0) @binding(0) var<uniform> u: Uniforms;
const MODEL_LINEWEIGHT_BOOST: f32 = 2.0;
const MODEL_LINEWEIGHT_MAX_PX: f32 = 10.0;
// ── Group 1: per-hatch data ────────────────────────────────────────────────
struct HatchUniforms {
@@ -117,6 +120,18 @@ struct VOut {
// `ddx_xz`/`ddy_xz` are screen-space derivatives of `xz`, taken once in
// fs_main: derivative builtins must run in uniform control flow, and the
// per-family loop's early return makes later iterations non-uniform.
fn display_lineweight(width: f32) -> f32 {
if u.lineweight_scale < 0.0 {
let base = select(
min(width * MODEL_LINEWEIGHT_BOOST, MODEL_LINEWEIGHT_MAX_PX),
1.0,
width <= 1.0,
);
return max(base * -u.lineweight_scale, 1.0);
}
return max(width * u.lineweight_scale, 1.0);
}
fn check_family(
xz: vec2<f32>,
ddx_xz: vec2<f32>,
@@ -147,11 +162,7 @@ fn check_family(
-ddx_xz.x * sin_a + ddx_xz.y * cos_a,
-ddy_xz.x * sin_a + ddy_xz.y * cos_a,
)) * 0.5;
let width_px = select(
1.0,
max(fam.line_width * u.lineweight_scale, 1.0),
u.lwdisplay_enable > 0.5,
);
let width_px = select(1.0, display_lineweight(fam.line_width), u.lwdisplay_enable > 0.5);
let half_line = half_px * width_px;
let wpx = length(vec2<f32>(ddx_xz.x, ddy_xz.x));