mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-26 01:10:48 +01:00
Merge pull request #107 from storytold/fix/fabric-materials
Materials: twill for denim and carbon fiber, a pile for velvet
This commit is contained in:
13 files changed
+53
-13
No files matched your search
@@ -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<bool> = (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 {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -357,15 +357,21 @@ pub(crate) fn build(b: &mut Builder, id: &str) -> Result<Vec<Layer>> {
|
||||
"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<Vec<Layer>> {
|
||||
"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 ---------------------------------------------------------
|
||||
|
||||
@@ -947,4 +947,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
("Unsaved changes", "تغييرات غير محفوظة"),
|
||||
("Don't save", "عدم الحفظ"),
|
||||
("Save the changes to {name} before closing?", "هل تريد حفظ التغييرات في {name} قبل الإغلاق؟"),
|
||||
("Twill weave", "نسيج مائل"),
|
||||
];
|
||||
@@ -1002,4 +1002,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
("Unsaved changes", "Ungespeicherte Änderungen"),
|
||||
("Don't save", "Nicht speichern"),
|
||||
("Save the changes to {name} before closing?", "Änderungen an {name} vor dem Schließen speichern?"),
|
||||
("Twill weave", "Köperbindung"),
|
||||
];
|
||||
@@ -987,4 +987,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
("Unsaved changes", "Cambios sin guardar"),
|
||||
("Don't save", "No guardar"),
|
||||
("Save the changes to {name} before closing?", "¿Guardar los cambios de {name} antes de cerrar?"),
|
||||
("Twill weave", "Tejido de sarga"),
|
||||
];
|
||||
@@ -1002,4 +1002,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
("Unsaved changes", "Modifications non enregistrées"),
|
||||
("Don't save", "Ne pas enregistrer"),
|
||||
("Save the changes to {name} before closing?", "Enregistrer les modifications de {name} avant de fermer ?"),
|
||||
("Twill weave", "Armure sergé"),
|
||||
];
|
||||
@@ -996,4 +996,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
("Unsaved changes", "Modifiche non salvate"),
|
||||
("Don't save", "Non salvare"),
|
||||
("Save the changes to {name} before closing?", "Salvare le modifiche a {name} prima di chiudere?"),
|
||||
("Twill weave", "Tessuto a saia"),
|
||||
];
|
||||
@@ -969,4 +969,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
("Unsaved changes", "未保存の変更"),
|
||||
("Don't save", "保存しない"),
|
||||
("Save the changes to {name} before closing?", "閉じる前に {name} の変更を保存しますか?"),
|
||||
("Twill weave", "綾織り"),
|
||||
];
|
||||
@@ -954,4 +954,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
("Unsaved changes", "저장되지 않은 변경 사항"),
|
||||
("Don't save", "저장 안 함"),
|
||||
("Save the changes to {name} before closing?", "닫기 전에 {name}의 변경 사항을 저장할까요?"),
|
||||
("Twill weave", "능직"),
|
||||
];
|
||||
@@ -984,4 +984,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
("Unsaved changes", "Alterações não salvas"),
|
||||
("Don't save", "Não salvar"),
|
||||
("Save the changes to {name} before closing?", "Salvar as alterações em {name} antes de fechar?"),
|
||||
("Twill weave", "Tecido sarja"),
|
||||
];
|
||||
@@ -900,4 +900,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
("Unsaved changes", "未保存的更改"),
|
||||
("Don't save", "不保存"),
|
||||
("Save the changes to {name} before closing?", "关闭前是否保存对 {name} 的更改?"),
|
||||
("Twill weave", "斜纹织物"),
|
||||
];
|
||||
+1
-1
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user