From dd00c4e04d41cfee638ab0ad0268ca5ac74851b2 Mon Sep 17 00:00:00 2001 From: vangel76 Date: Sun, 22 Nov 2026 23:22:02 +0100 Subject: [PATCH] Blend the hover tint with the blurred scattering light and fix the export tree test query --- crates/render/src/shaders/mesh.wgsl | 5 +++++ crates/render/tests/headless.rs | 25 ++++++++++++++++++++++ crates/ui-egui/tests/it/export_progress.rs | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/crates/render/src/shaders/mesh.wgsl b/crates/render/src/shaders/mesh.wgsl index a98e58f7..f780c4fc 100644 --- a/crates/render/src/shaders/mesh.wgsl +++ b/crates/render/src/shaders/mesh.wgsl @@ -388,6 +388,11 @@ fn fs_gbuf(i: VOut, @builtin(front_facing) front: bool) -> @location(0) vec4(0.0); if (g.scatter.w > 0.5) { sss = shade_mesh(i, front).sss; + if (i.hover == 1u) { + // fs_mesh mixes the hover tint into the color without this light; the blur pass adds it + // back unblended, so scale it by the share of the color that stays + sss = sss * (1.0 - g.set_hover.a); + } } else if (textureSample(t_base, samp, i.uv).a < hash12(i.clip.xy)) { discard; } diff --git a/crates/render/tests/headless.rs b/crates/render/tests/headless.rs index e4ddad39..dcaeefb2 100644 --- a/crates/render/tests/headless.rs +++ b/crates/render/tests/headless.rs @@ -1072,6 +1072,31 @@ fn subsurface_blur_spreads_only_scattering_light() { assert!((m1 - m0).abs() < 2.0, "the blur moves light, it adds none: {m0} -> {m1}"); } +#[test] +fn the_hover_tint_covers_the_blurred_scattering_light_too() { + let Some((mut h, frame)) = setup() else { return }; + let lit = shaded(&frame, |s| s.light = LIGHT); + let mask = mesh_mask(&mut h, &lit, &[0]); + fill(&mut h, &[0, 1], DisplayKind::BaseColor, &[150, 150, 150, 255]); + fill(&mut h, &[0, 1], DisplayKind::Emissive, &[0, 0, 0, 255]); + let blur = shaded(&lit, |s| s.sss_blur = Some([0.06, 0.024, 0.015])); + let hover = |f: &Frame| shaded(f, |s| s.set_hover = Some(texturecraft_render::SetHighlight { set: 0, color: [1.0, 0.5, 0.0] })); + let mean = |img: &Img| region_mean(&mask, |x, y| img.luma(x, y)); + let plain = mean(&render(&mut h, &lit, "hover_sss_plain")); + let blurred = mean(&render(&mut h, &blur, "hover_sss_blur")); + let hovered_plain = mean(&render(&mut h, &hover(&lit), "hover_sss_plain_hovered")); + let hovered_blur = mean(&render(&mut h, &hover(&blur), "hover_sss_blur_hovered")); + assert!(hovered_plain != plain, "the hover tint changes the set"); + // The blur only moves light around, so it must change a hovered set as little as a plain one + // (the scattering light restored by the blur pass is blended with the tint as well) + assert!( + ((hovered_blur - hovered_plain) - (blurred - plain)).abs() < 3.0, + "the blur changes the plain set by {} and the hovered set by {}", + blurred - plain, + hovered_blur - hovered_plain + ); +} + /// An environment that is bright only around `dir` (world space, rotation 0). fn spot_environment(dir: texturecraft_geom::glam::Vec3) -> ImageRes { let (w, hh) = (256u32, 128u32); diff --git a/crates/ui-egui/tests/it/export_progress.rs b/crates/ui-egui/tests/it/export_progress.rs index 84015102..8f929ca7 100644 --- a/crates/ui-egui/tests/it/export_progress.rs +++ b/crates/ui-egui/tests/it/export_progress.rs @@ -124,7 +124,7 @@ fn the_list_is_a_tree_per_texture_set_with_the_console_beside_it() { h.state_mut().ui.export.tab = 2; h.run_steps(4); let set = h.state().session.doc.project.texture_sets[0].name.clone(); - assert!(h.query_by_label(&set).is_some()); + assert!(h.query_by_role_and_label(egui::Role::DisclosureTriangle, &set).is_some(), "the export tree has a node for the set (the dock list row carries the same name)"); assert!(h.query_all_by_label("256x256 (Texture Set size)").next().is_some()); assert!(h.query_all_by_label("png").next().is_some() && h.query_all_by_label("16 bits").next().is_some()); assert!(h.query_by_label("Include all").is_none() && h.query_by_label("Reset all").is_none());