From 0a13426b6d168345d678941b119ba2d8b14dbd3d Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 07:45:24 +0700 Subject: [PATCH 1/3] Color picker: keep the popup in place while the color changes The picker's R, G and B values were its widest row, so the popup grew and shrank as they gained or lost digits; anchored at the right edge of the Properties panel, the whole picker slid sideways under the cursor. The square and hue slider are now wider than that row at any value. Fixes #93. --- crates/ui-egui/src/widgets.rs | 2 ++ crates/ui-egui/tests/color_picker.rs | 35 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 crates/ui-egui/tests/color_picker.rs diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index ae9f5981..eb9469e8 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -208,6 +208,8 @@ pub fn color_swatch(ui: &mut Ui, id: &str, linear: &mut [f32; 3], width: f32) -> let mut changed = false; // Open state lives in memory (`toggle_id` above); `from_response` alone shows it always. egui::Popup::from_response(&resp).id(popup).open_memory(None).close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside).show(|ui| { + // Wider than the R, G, B row at any value, so the popup keeps one size and place. + ui.spacing_mut().slider_width = 275.0; if egui::color_picker::color_picker_color32(ui, &mut c, egui::color_picker::Alpha::Opaque) { let lin = [c.r(), c.g(), c.b()].map(|v| texturecraft_engine::texel::srgb_to_linear(v as f32 / 255.0)); *linear = lin; diff --git a/crates/ui-egui/tests/color_picker.rs b/crates/ui-egui/tests/color_picker.rs new file mode 100644 index 00000000..dd9bbf53 --- /dev/null +++ b/crates/ui-egui/tests/color_picker.rs @@ -0,0 +1,35 @@ +//! The color picker popup keeps its place while the color changes. + +use egui::accesskit::Role; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use texturecraft_ui_egui::{theme, widgets}; + +/// The left edge of the picker's R value. +fn r_left(h: &Harness<'_, [f32; 3]>) -> f32 { + h.get_all_by_role(Role::SpinButton).next().unwrap().rect().left() +} + +#[test] +fn the_popup_stays_put_while_the_color_changes() { + // A swatch at the right edge of the window, like the Properties panel's. + // The picker's copy button is an emoji the bundled fonts do not draw. + let mut h = Harness::builder().with_size(egui::vec2(800.0, 600.0)).allow_missing_glyphs().build_ui_state( + |ui, color: &mut [f32; 3]| { + ui.with_layout(egui::Layout::right_to_left(egui::Align::Min), |ui| { + widgets::color_swatch(ui, "color", color, 120.0); + }); + }, + [1.0; 3], + ); + theme::apply(&h.ctx, theme::Brightness::default(), theme::Accent::default()); + h.run_steps(2); + let swatch = egui::pos2(800.0 - 60.0, 9.0); + h.drag_at(swatch); + h.drop_at(swatch); + h.run_steps(3); + let bright = r_left(&h); + *h.state_mut() = [0.001; 3]; + h.run_steps(3); + assert_eq!(r_left(&h), bright, "the picker does not move when R, G and B lose digits"); +} From 3fea0f6c620424c2651b261973fa4bcec13aef17 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 07:53:46 +0700 Subject: [PATCH 2/3] Materials: twill for denim and carbon fiber, a pile for velvet Carbon Fiber, Fabric Cotton, Denim and Velvet were all the same plain weave in different colours. A new Twill weave pattern (2/2: diagonal ribs, the weft darker than the warp) now gives Denim its diagonal and Carbon Fiber its light and dark tows under a clear coat; Velvet is a soft pile with no weave under its sheen; Fabric Cotton keeps the plain weave. Twill weave is also a fill pattern, translated into all nine other UI languages. Fixes #97. --- crates/compose/src/pattern.rs | 30 +++++++++++++++++++++++++----- crates/core/src/layer.rs | 6 +++++- crates/engine/src/materials.rs | 19 +++++++++++++------ crates/ui-egui/src/i18n/ar.rs | 1 + crates/ui-egui/src/i18n/de.rs | 1 + crates/ui-egui/src/i18n/es.rs | 1 + crates/ui-egui/src/i18n/fr.rs | 1 + crates/ui-egui/src/i18n/it.rs | 1 + crates/ui-egui/src/i18n/ja.rs | 1 + crates/ui-egui/src/i18n/ko.rs | 1 + crates/ui-egui/src/i18n/pt_br.rs | 1 + crates/ui-egui/src/i18n/zh_hans.rs | 1 + docs/features.md | 2 +- 13 files changed, 53 insertions(+), 13 deletions(-) diff --git a/crates/compose/src/pattern.rs b/crates/compose/src/pattern.rs index e03685b7..9ca2a3da 100644 --- a/crates/compose/src/pattern.rs +++ b/crates/compose/src/pattern.rs @@ -67,17 +67,22 @@ fn raw(kind: ProceduralKind, p: Vec3, seed: u32) -> f32 { let d = f.x.min(1.0 - f.x).min(f.y.min(1.0 - f.y)); smoothstep(0.015, 0.035, d) * (0.9 + 0.1 * noise::cell_hash(c.x as i32, c.y as i32, 0, seed)) } - ProceduralKind::Weave => { - // Plain weave: in each cell the thread on top alternates (warp along X, weft along Y); - // the top thread shows its round cross-section, bulging mid-span. + ProceduralKind::Weave | ProceduralKind::Twill => { + // Warp along X, weft along Y: in each cell the thread on top shows its round + // cross-section, bulging mid-span. A plain weave alternates every cell; a 2/2 twill + // floats over two cells and steps one cell per row, so the floats line up in diagonal + // ribs, the weft darker than the warp. let c = (p * 2.0).floor(); let f = p * 2.0 - c; let pi = std::f32::consts::PI; - let warp_on_top = (c.x as i32 + c.y as i32).rem_euclid(2) == 0; + let twill = kind == ProceduralKind::Twill; + let (period, warp_cells) = if twill { (4, 2) } else { (2, 1) }; + let warp_on_top = (c.x as i32).wrapping_add(c.y as i32).rem_euclid(period) < warp_cells; let (across, along) = if warp_on_top { (f.y, f.x) } else { (f.x, f.y) }; let thread = (pi * across).sin().max(0.0).sqrt() * (0.8 + 0.2 * (pi * along).sin()); + let tone = if twill && !warp_on_top { 0.55 } else { 1.0 }; let fiber = noise::value([p.x * 40.0, p.y * 40.0, p.z], seed); - (thread * (0.88 + 0.12 * fiber)).clamp(0.0, 1.0) + (thread * tone * (0.88 + 0.12 * fiber)).clamp(0.0, 1.0) } ProceduralKind::Leather => { let w = noise::perlin((p * 0.7).to_array(), seed ^ 0x2D) - 0.5; @@ -351,6 +356,21 @@ mod tests { assert!(decal_uv(&Decal { size: [f32::NAN; 2], ..d }, Vec3::ZERO, z).is_none()); } + #[test] + fn twill_floats_run_in_diagonal_ribs() { + // The value at the centre of cell (x, y); cells are half a unit. + let at = |k, x: i32, y: i32| raw(k, Vec3::new(x as f32 * 0.5 + 0.25, y as f32 * 0.5 + 0.25, 0.0), 3); + for y in 1..8 { + let warp: Vec = (0..8).map(|x| at(ProceduralKind::Twill, x, y) > 0.7).collect(); + assert_eq!(warp.iter().filter(|w| **w).count(), 4, "row {y}: half the floats are warp"); + for x in 0..7 { + assert_eq!(warp[x as usize], at(ProceduralKind::Twill, x + 1, y - 1) > 0.7, "the rib continues diagonally at ({x}, {y})"); + } + } + // A plain weave shows every top thread alike. + assert!((0..8).all(|x| at(ProceduralKind::Weave, x, 0) > 0.7)); + } + #[test] fn every_pattern_varies() { for k in ProceduralKind::ALL { diff --git a/crates/core/src/layer.rs b/crates/core/src/layer.rs index ca558a8d..12671b85 100644 --- a/crates/core/src/layer.rs +++ b/crates/core/src/layer.rs @@ -228,6 +228,8 @@ pub enum ProceduralKind { Tiles, /// Plain fabric weave. Weave, + /// 2/2 twill: diagonal ribs, the warp brighter than the weft (denim, carbon fiber). + Twill, /// Leather grain: pebbled cells with creases. Leather, /// Hammered metal dimples. @@ -249,7 +251,7 @@ pub enum ProceduralKind { } impl ProceduralKind { - pub const ALL: [ProceduralKind; 22] = [ + pub const ALL: [ProceduralKind; 23] = [ ProceduralKind::Clouds, ProceduralKind::Perlin, ProceduralKind::Noise, @@ -263,6 +265,7 @@ impl ProceduralKind { ProceduralKind::Bricks, ProceduralKind::Tiles, ProceduralKind::Weave, + ProceduralKind::Twill, ProceduralKind::Leather, ProceduralKind::Hammered, ProceduralKind::Brushed, @@ -288,6 +291,7 @@ impl ProceduralKind { ProceduralKind::Bricks => "Bricks", ProceduralKind::Tiles => "Tiles", ProceduralKind::Weave => "Fabric weave", + ProceduralKind::Twill => "Twill weave", ProceduralKind::Leather => "Leather grain", ProceduralKind::Hammered => "Hammered", ProceduralKind::Brushed => "Brushed lines", diff --git a/crates/engine/src/materials.rs b/crates/engine/src/materials.rs index 0863dbcc..18c54577 100644 --- a/crates/engine/src/materials.rs +++ b/crates/engine/src/materials.rs @@ -357,15 +357,21 @@ pub(crate) fn build(b: &mut Builder, id: &str) -> Result> { "plastic_glossy" | "plastic_matte" | "ceramic" => one(b, dielectric(rgb(m.base), clouds_rough(9))), "plastic_textured" => one(b, plus(dielectric(rgb(m.base), gray(P::Leather, 40.0, 5, 0.66, 0.5)), height(gray(P::Leather, 40.0, 5, -0.01, 0.0)))), "rubber" => one(b, dielectric(pat(P::Noise, 0.5, 3, 1.0, [0.025; 3], [0.035; 3]), gray(P::Noise, 0.5, 3, 0.84, 0.94))), - "carbon_fiber" => { - one(b, plus(dielectric(pat(P::Weave, 24.0, 1, 1.0, [0.01, 0.01, 0.012], [0.06, 0.06, 0.065]), u(r)), height(gray(P::Weave, 24.0, 1, 0.0, 0.006)))) - } + // Twill-woven tows under a clear coat: the warp catches the light, the weft stays dark. + "carbon_fiber" => one( + b, + plus( + dielectric(pat(P::Twill, 12.0, 1, 1.0, [0.004, 0.004, 0.005], [0.08, 0.08, 0.085]), gray(P::Twill, 12.0, 1, 0.5, 0.28)), + [(CoatWeight, u(1.0)), (CoatRoughness, u(r * 0.2)), (Height, gray(P::Twill, 12.0, 1, 0.0, 0.002))], + ), + ), // ---- Fabric and leather ------------------------------------------------------------- "fabric" => { one(b, plus(dielectric(pat(P::Weave, 18.0, 2, 1.0, [0.27, 0.29, 0.34], [0.6, 0.62, 0.7]), u(r)), height(gray(P::Weave, 18.0, 2, -0.01, 0.0)))) } + // Indigo twill: diagonal ribs. "denim" => { - one(b, plus(dielectric(pat(P::Weave, 22.0, 5, 1.0, [0.02, 0.03, 0.08], [0.12, 0.16, 0.3]), u(r)), height(gray(P::Weave, 22.0, 5, -0.01, 0.0)))) + one(b, plus(dielectric(pat(P::Twill, 22.0, 5, 1.0, [0.015, 0.025, 0.07], [0.15, 0.2, 0.38]), u(r)), height(gray(P::Twill, 22.0, 5, -0.01, 0.0)))) } "leather" => one( b, @@ -384,8 +390,9 @@ pub(crate) fn build(b: &mut Builder, id: &str) -> Result> { "velvet" => one( b, plus( - dielectric(pat(P::Weave, 30.0, 3, 1.0, [0.07, 0.008, 0.05], m.base), u(r)), - [(SheenWeight, u(1.0)), (SheenColor, rgb([0.95, 0.55, 0.85])), (SheenRoughness, u(0.35)), (Height, gray(P::Weave, 30.0, 3, -0.004, 0.0))], + // A pile, not a weave: soft crushed patches under a bright sheen. + dielectric(pat(P::Clouds, 3.0, 3, 1.0, [0.06, 0.006, 0.045], m.base), u(r)), + [(SheenWeight, u(1.0)), (SheenColor, rgb([0.95, 0.55, 0.85])), (SheenRoughness, u(0.35)), (Height, gray(P::Noise, 1.0, 3, -0.002, 0.0))], ), ), // ---- Coated and translucent --------------------------------------------------------- diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rs index 5fb79fb2..d2955ba2 100644 --- a/crates/ui-egui/src/i18n/ar.rs +++ b/crates/ui-egui/src/i18n/ar.rs @@ -944,4 +944,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Invert show/hide", "عكس الإظهار/الإخفاء"), ("Show or hide texture sets", "إظهار مجموعات الخامات أو إخفاؤها"), ("Focus: show only the active texture set", "تركيز: إظهار مجموعة الخامات النشطة فقط"), + ("Twill weave", "نسيج مائل"), ]; diff --git a/crates/ui-egui/src/i18n/de.rs b/crates/ui-egui/src/i18n/de.rs index e2d9ed89..e6be33c2 100644 --- a/crates/ui-egui/src/i18n/de.rs +++ b/crates/ui-egui/src/i18n/de.rs @@ -999,4 +999,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Invert show/hide", "Ein-/Ausblenden umkehren"), ("Show or hide texture sets", "Texturesets ein- oder ausblenden"), ("Focus: show only the active texture set", "Fokus: nur das aktive Textureset zeigen"), + ("Twill weave", "Köperbindung"), ]; diff --git a/crates/ui-egui/src/i18n/es.rs b/crates/ui-egui/src/i18n/es.rs index e9927174..2e5cebf6 100644 --- a/crates/ui-egui/src/i18n/es.rs +++ b/crates/ui-egui/src/i18n/es.rs @@ -984,4 +984,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Invert show/hide", "Invertir mostrar/ocultar"), ("Show or hide texture sets", "Mostrar u ocultar conjuntos de texturas"), ("Focus: show only the active texture set", "Enfoque: mostrar solo el conjunto de texturas activo"), + ("Twill weave", "Tejido de sarga"), ]; diff --git a/crates/ui-egui/src/i18n/fr.rs b/crates/ui-egui/src/i18n/fr.rs index 92f25811..1de8d2bc 100644 --- a/crates/ui-egui/src/i18n/fr.rs +++ b/crates/ui-egui/src/i18n/fr.rs @@ -999,4 +999,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Invert show/hide", "Inverser afficher/masquer"), ("Show or hide texture sets", "Afficher ou masquer les ensembles de textures"), ("Focus: show only the active texture set", "Focus : n'afficher que l'ensemble de textures actif"), + ("Twill weave", "Armure sergé"), ]; diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rs index 9c71748f..5199e099 100644 --- a/crates/ui-egui/src/i18n/it.rs +++ b/crates/ui-egui/src/i18n/it.rs @@ -993,4 +993,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Invert show/hide", "Inverti mostra/nascondi"), ("Show or hide texture sets", "Mostra o nascondi i set di texture"), ("Focus: show only the active texture set", "Focus: mostra solo il set di texture attivo"), + ("Twill weave", "Tessuto a saia"), ]; diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rs index c3d9ccad..1ba0636f 100644 --- a/crates/ui-egui/src/i18n/ja.rs +++ b/crates/ui-egui/src/i18n/ja.rs @@ -966,4 +966,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Invert show/hide", "表示/非表示を反転"), ("Show or hide texture sets", "テクスチャセットの表示/非表示"), ("Focus: show only the active texture set", "フォーカス: アクティブなテクスチャセットのみ表示"), + ("Twill weave", "綾織り"), ]; diff --git a/crates/ui-egui/src/i18n/ko.rs b/crates/ui-egui/src/i18n/ko.rs index 6182b57a..7ad33529 100644 --- a/crates/ui-egui/src/i18n/ko.rs +++ b/crates/ui-egui/src/i18n/ko.rs @@ -951,4 +951,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Invert show/hide", "표시/숨기기 반전"), ("Show or hide texture sets", "텍스처 세트 표시 또는 숨기기"), ("Focus: show only the active texture set", "포커스: 활성 텍스처 세트만 표시"), + ("Twill weave", "능직"), ]; diff --git a/crates/ui-egui/src/i18n/pt_br.rs b/crates/ui-egui/src/i18n/pt_br.rs index a430655c..3aba606d 100644 --- a/crates/ui-egui/src/i18n/pt_br.rs +++ b/crates/ui-egui/src/i18n/pt_br.rs @@ -981,4 +981,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Invert show/hide", "Inverter mostrar/ocultar"), ("Show or hide texture sets", "Mostrar ou ocultar conjuntos de texturas"), ("Focus: show only the active texture set", "Foco: mostrar só o conjunto de texturas ativo"), + ("Twill weave", "Tecido sarja"), ]; diff --git a/crates/ui-egui/src/i18n/zh_hans.rs b/crates/ui-egui/src/i18n/zh_hans.rs index e1fc3780..7e076f1d 100644 --- a/crates/ui-egui/src/i18n/zh_hans.rs +++ b/crates/ui-egui/src/i18n/zh_hans.rs @@ -897,4 +897,5 @@ pub const TABLE: &[(&str, &str)] = &[ ("Invert show/hide", "反转显示/隐藏"), ("Show or hide texture sets", "显示或隐藏纹理集"), ("Focus: show only the active texture set", "聚焦:仅显示当前纹理集"), + ("Twill weave", "斜纹织物"), ]; diff --git a/docs/features.md b/docs/features.md index 76289221..5e7c4d27 100644 --- a/docs/features.md +++ b/docs/features.md @@ -43,7 +43,7 @@ Everything TextureCraft does today, by area. What's still missing is in [`ROADMA gradients, all with world-space noise), filters, ID color selection and compare. Alt+click a mask to view it alone. - **Fill layers** take uniform values, **22 procedurals** (clouds, cells, grunge, scratches, wood - grain, bricks, fabric weave, leather grain, marble veins, Voronoi, paint chips…) or your own + grain, bricks, fabric weave, twill, leather grain, marble veins, Voronoi, paint chips…) or your own **images**, through UV, tri-planar, planar, spherical, cylindrical or decal projection. Alt+click a material channel (of a fill or the brush) to keep that channel alone. - **54 materials** (metals from measured reflectance, car paint, brushed anisotropic steel, From 8efd62aeaae5e689c42c8d4d83fc04c876e4f738 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 07:59:35 +0700 Subject: [PATCH 3/3] Viewport: no ghost edges in the subsurface blur Skin and other scattering materials showed copies of the silhouette running parallel to it: the blur's taps sit pixels apart when the mean free path is wide on screen, and a tap that left the mesh dropped out of the sum, so the light stepped at every tap spacing from the edge. Taps are now shifted per pixel and per accumulated frame, and a tap across a depth discontinuity takes the centre's light instead of dropping out. Fixes #86. --- crates/render/src/renderer.rs | 2 +- crates/render/src/shaders/fx.wgsl | 16 +++++++++++----- crates/render/src/shaders/post.wgsl | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/render/src/renderer.rs b/crates/render/src/renderer.rs index 60a8c39c..b09036e4 100644 --- a/crates/render/src/renderer.rs +++ b/crates/render/src/renderer.rs @@ -1584,7 +1584,7 @@ impl Renderer { b: [fx(s.vignette), fx(s.sharpen), fx(s.grain), BLOOM_THRESHOLD], c: dof_c, d: sss_d, - e: [flag(cam.ortho), 0.0, 0.0, 0.0], + e: [flag(cam.ortho), sample as f32, 0.0, 0.0], }; let Some(v) = self.targets(device, frame.view_id, frame.size, bloom, fx_on, refraction) else { return }; queue.write_buffer(&v.globals, 0, bytemuck::bytes_of(&raw)); diff --git a/crates/render/src/shaders/fx.wgsl b/crates/render/src/shaders/fx.wgsl index cdd3963c..333664ce 100644 --- a/crates/render/src/shaders/fx.wgsl +++ b/crates/render/src/shaders/fx.wgsl @@ -22,7 +22,8 @@ fn texel_at(t: texture_2d, p: vec2) -> vec4 { // ---- Subsurface scattering: a separable bilateral blur (Jimenez et al., "Separable Subsurface // Scattering", 2015) of the scattering diffuse light, a Gaussian per color channel as wide as -// its mean free path, cut off across depth discontinuities. +// its mean free path. A tap across a depth discontinuity (or off the mesh) takes the centre's +// light instead, so no tap drops out of the sum as it crosses a silhouette. const SSS_TAPS: i32 = 8; @@ -41,17 +42,22 @@ fn sss_blur(p: vec2, dir: vec2) -> vec4 { let stride = dir * (smax * 3.0 / f32(SSS_TAPS)); let depth_range = 3.0 * max(post.d.x, max(post.d.y, post.d.z)); let inv = 1.0 / (2.0 * sigma * sigma + vec3(1e-4)); + // Wide blurs space their taps pixels apart: shifting them per pixel (interleaved gradient + // noise) and per accumulated frame turns what would show as copies of edges into fine grain. + let ign = fract(52.9829189 * fract(dot(p, vec2(0.06711056, 0.00583715)))); + let jitter = fract(ign + post.e.y * 0.618034) - 0.5; var sum = c.rgb; var wsum = vec3(1.0); for (var k = -SSS_TAPS; k <= SSS_TAPS; k++) { if (k == 0) { continue; } - let t = texel_at(src, p + stride * f32(k)); - let x = f32(k) * smax * 3.0 / f32(SSS_TAPS); + let o = f32(k) + jitter; + let t = texel_at(src, p + stride * o); + let x = o * smax * 3.0 / f32(SSS_TAPS); let wd = select(0.0, max(1.0 - abs(t.a - c.a) / depth_range, 0.0), t.a > 0.0); - let w = exp(-x * x * inv) * wd; - sum += t.rgb * w; + let w = exp(-x * x * inv); + sum += mix(c.rgb, t.rgb, wd) * w; wsum += w; } return vec4(sum / wsum, c.a); diff --git a/crates/render/src/shaders/post.wgsl b/crates/render/src/shaders/post.wgsl index 7a0c7d62..6eb30868 100644 --- a/crates/render/src/shaders/post.wgsl +++ b/crates/render/src/shaders/post.wgsl @@ -7,7 +7,7 @@ struct Post { b: vec4, // x vignette, y sharpen, z grain, w bloom threshold c: vec4, // depth of field (fx.wgsl): x circle of confusion at infinity (pixels), y focus depth, z largest circle radius (pixels), w accumulation sample d: vec4, // subsurface blur (fx.wgsl): xyz mean free path per channel (world units), w pixels per world unit at depth 1 - e: vec4, // x orthographic camera (1: pixels per world unit don't fall off with depth), yzw - + e: vec4, // x orthographic camera (1: pixels per world unit don't fall off with depth), y accumulation sample, zw - }; @group(0) @binding(3) var post: Post;