Merge main into fix/uv-island-fill

This commit is contained in:
bflatastic committed 2026-11-02 08:27:04 +07:00
commit bd8299c0c7
18 files changed
+103 -20

No files matched your search

+25 -5
View File
@@ -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 {
+5 -1
View File
@@ -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",
+13 -6
View File
@@ -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 ---------------------------------------------------------
+1 -1
View File
@@ -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));
+11 -5
View File
@@ -22,7 +22,8 @@ fn texel_at(t: texture_2d<f32>, p: vec2<f32>) -> vec4<f32> {
// ---- 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<f32>, dir: vec2<f32>) -> vec4<f32> {
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<f32>(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<f32>(0.06711056, 0.00583715))));
let jitter = fract(ign + post.e.y * 0.618034) - 0.5;
var sum = c.rgb;
var wsum = vec3<f32>(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<f32>(sum / wsum, c.a);
+1 -1
View File
@@ -7,7 +7,7 @@ struct Post {
b: vec4<f32>, // x vignette, y sharpen, z grain, w bloom threshold
c: vec4<f32>, // 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<f32>, // subsurface blur (fx.wgsl): xyz mean free path per channel (world units), w pixels per world unit at depth 1
e: vec4<f32>, // x orthographic camera (1: pixels per world unit don't fall off with depth), yzw -
e: vec4<f32>, // x orthographic camera (1: pixels per world unit don't fall off with depth), y accumulation sample, zw -
};
@group(0) @binding(3) var<uniform> post: Post;
+1
View File
@@ -947,4 +947,5 @@ pub const TABLE: &[(&str, &str)] = &[
("Unsaved changes", "تغييرات غير محفوظة"),
("Don't save", "عدم الحفظ"),
("Save the changes to {name} before closing?", "هل تريد حفظ التغييرات في {name} قبل الإغلاق؟"),
("Twill weave", "نسيج مائل"),
];
+1
View File
@@ -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"),
];
+1
View File
@@ -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"),
];
+1
View File
@@ -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é"),
];
+1
View File
@@ -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"),
];
+1
View File
@@ -969,4 +969,5 @@ pub const TABLE: &[(&str, &str)] = &[
("Unsaved changes", "未保存の変更"),
("Don't save", "保存しない"),
("Save the changes to {name} before closing?", "閉じる前に {name} の変更を保存しますか?"),
("Twill weave", "綾織り"),
];
+1
View File
@@ -954,4 +954,5 @@ pub const TABLE: &[(&str, &str)] = &[
("Unsaved changes", "저장되지 않은 변경 사항"),
("Don't save", "저장 안 함"),
("Save the changes to {name} before closing?", "닫기 전에 {name}의 변경 사항을 저장할까요?"),
("Twill weave", "능직"),
];
+1
View File
@@ -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"),
];
+1
View File
@@ -900,4 +900,5 @@ pub const TABLE: &[(&str, &str)] = &[
("Unsaved changes", "未保存的更改"),
("Don't save", "不保存"),
("Save the changes to {name} before closing?", "关闭前是否保存对 {name} 的更改?"),
("Twill weave", "斜纹织物"),
];
+2
View File
@@ -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;
+35
View File
@@ -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");
}
+1 -1
View File
@@ -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,