From 3fea0f6c620424c2651b261973fa4bcec13aef17 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Mon, 2 Nov 2026 07:53:46 +0700 Subject: [PATCH] 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,