diff --git a/crates/core/src/channel.rs b/crates/core/src/channel.rs index 7fea2d38..e6e823e8 100644 --- a/crates/core/src/channel.rs +++ b/crates/core/src/channel.rs @@ -39,6 +39,77 @@ pub enum Channel { Transmission, /// Tangent-space normal of the clear coat (relative to the mesh normal). CoatNormal, + /// How much of the base layer shows (stored and exported: our shader does not read it) + BaseWeight, + /// Roughness of the diffuse base (stored and exported: our shader does not read it) + BaseDiffuseRoughness, + /// Strength of the specular lobe (stored and exported: our shader does not read it) + SpecularWeight, + /// Tint of the specular lobe (stored and exported: our shader does not read it) + SpecularColor, + /// Tint of transmitted light (stored and exported: our shader does not read it) + TransmissionColor, + /// Subsurface scattering color (stored and exported: our shader does not read it) + SubsurfaceColor, + /// Scattering distance per color (stored and exported: our shader does not read it) + SubsurfaceRadiusScale, + /// Clear coat tint (stored and exported: our shader does not read it) + CoatColor, + /// Clear coat anisotropy (stored and exported: our shader does not read it) + CoatAnisotropy, + /// Clear coat reflectance (stored and exported: our shader does not read it) + CoatSpecularLevel, + /// Tangent-space direction of the clear coat anisotropy, packed like a normal (stored and exported: our shader does not read it) + CoatTangent, + /// Thin-film iridescence weight (stored and exported: our shader does not read it) + ThinFilmWeight, + /// Tangent-space anisotropy direction, packed like a normal (stored and exported: our shader does not read it) + Tangent, + /// Mask for blending materials in an engine (stored and exported only) + BlendingMask, + /// Diffuse color of older shaders (stored and exported only) + Diffuse, + /// Signed displacement for render engines (stored and exported only) + Displacement, + /// Index of refraction, 0..1 as the target shader maps it (stored and exported only) + Ior, + /// Reflection amount of older shaders (stored and exported only) + Reflection, + /// Transmissive color of older shaders (stored and exported only) + Transmissive, + /// Free channels for anything a target shader needs (grey, stored and exported) + User0, + User1, + User2, + User3, + User4, + User5, + User6, + User7, + User8, + User9, + User10, + User11, + User12, + User13, + User14, + User15, + User16, + User17, + User18, + User19, + User20, + User21, + User22, + User23, + User24, + User25, + User26, + User27, + User28, + User29, + User30, + User31, } /// How a channel's values are stored and interpreted. @@ -55,7 +126,7 @@ pub enum ChannelKind { } impl Channel { - pub const ALL: [Channel; 21] = [ + pub const ALL: [Channel; 72] = [ Channel::BaseColor, Channel::Metallic, Channel::Roughness, @@ -77,8 +148,62 @@ impl Channel { Channel::ScatterWeight, Channel::Transmission, Channel::CoatNormal, + Channel::BaseWeight, + Channel::BaseDiffuseRoughness, + Channel::SpecularWeight, + Channel::SpecularColor, + Channel::TransmissionColor, + Channel::SubsurfaceColor, + Channel::SubsurfaceRadiusScale, + Channel::CoatColor, + Channel::CoatAnisotropy, + Channel::CoatSpecularLevel, + Channel::CoatTangent, + Channel::ThinFilmWeight, + Channel::Tangent, + Channel::BlendingMask, + Channel::Diffuse, + Channel::Displacement, + Channel::Ior, + Channel::Reflection, + Channel::Transmissive, + Channel::User0, + Channel::User1, + Channel::User2, + Channel::User3, + Channel::User4, + Channel::User5, + Channel::User6, + Channel::User7, + Channel::User8, + Channel::User9, + Channel::User10, + Channel::User11, + Channel::User12, + Channel::User13, + Channel::User14, + Channel::User15, + Channel::User16, + Channel::User17, + Channel::User18, + Channel::User19, + Channel::User20, + Channel::User21, + Channel::User22, + Channel::User23, + Channel::User24, + Channel::User25, + Channel::User26, + Channel::User27, + Channel::User28, + Channel::User29, + Channel::User30, + Channel::User31, ]; + /// How many channels, from the start of [`Channel::ALL`], our shader reads + pub const SHADED_COUNT: usize = 21; + /// The extra shading lobes (clear coat, sheen, anisotropy, subsurface scattering, /// transmission). Their defaults switch the lobes off, so a set without them shades exactly /// as before. @@ -101,8 +226,15 @@ impl Channel { pub fn kind(self) -> ChannelKind { match self { Channel::BaseColor | Channel::Emissive | Channel::Specular | Channel::SheenColor => ChannelKind::Color, - Channel::Normal | Channel::CoatNormal => ChannelKind::NormalMap, - Channel::Height => ChannelKind::Signed, + Channel::SpecularColor + | Channel::TransmissionColor + | Channel::SubsurfaceColor + | Channel::SubsurfaceRadiusScale + | Channel::CoatColor + | Channel::Diffuse + | Channel::Transmissive => ChannelKind::Color, + Channel::Normal | Channel::CoatNormal | Channel::Tangent | Channel::CoatTangent => ChannelKind::NormalMap, + Channel::Height | Channel::Displacement => ChannelKind::Signed, _ => ChannelKind::Scalar, } } @@ -133,8 +265,52 @@ impl Channel { Channel::Normal | Channel::CoatNormal => [0.5, 0.5, 1.0], Channel::Opacity | Channel::AmbientOcclusion => [1.0; 3], Channel::SpecularLevel | Channel::Glossiness => [0.5; 3], - // F0 of a common dielectric (4 %). + // F0 of a common dielectric (4 %) Channel::Specular => [0.04; 3], + Channel::BaseWeight | Channel::SpecularWeight | Channel::SpecularColor | Channel::TransmissionColor | Channel::CoatColor => [1.0; 3], + Channel::BaseDiffuseRoughness + | Channel::CoatAnisotropy + | Channel::ThinFilmWeight + | Channel::BlendingMask + | Channel::Displacement + | Channel::Reflection + | Channel::Transmissive => [0.0; 3], + Channel::SubsurfaceColor => [0.8; 3], + Channel::SubsurfaceRadiusScale => [1.0, 0.5, 0.25], + Channel::CoatSpecularLevel | Channel::Diffuse | Channel::Ior => [0.5; 3], + Channel::CoatTangent | Channel::Tangent => [1.0, 0.5, 0.5], + Channel::User0 + | Channel::User1 + | Channel::User2 + | Channel::User3 + | Channel::User4 + | Channel::User5 + | Channel::User6 + | Channel::User7 + | Channel::User8 + | Channel::User9 + | Channel::User10 + | Channel::User11 + | Channel::User12 + | Channel::User13 + | Channel::User14 + | Channel::User15 + | Channel::User16 + | Channel::User17 + | Channel::User18 + | Channel::User19 + | Channel::User20 + | Channel::User21 + | Channel::User22 + | Channel::User23 + | Channel::User24 + | Channel::User25 + | Channel::User26 + | Channel::User27 + | Channel::User28 + | Channel::User29 + | Channel::User30 + | Channel::User31 => [0.0; 3], } } @@ -161,6 +337,57 @@ impl Channel { Channel::ScatterWeight => "Scattering weight", Channel::Transmission => "Transmission", Channel::CoatNormal => "Coat normal", + Channel::BaseWeight => "Base weight", + Channel::BaseDiffuseRoughness => "Base diffuse roughness", + Channel::SpecularWeight => "Specular weight", + Channel::SpecularColor => "Specular color", + Channel::TransmissionColor => "Transmission color", + Channel::SubsurfaceColor => "Subsurface color", + Channel::SubsurfaceRadiusScale => "Subsurface radius scale", + Channel::CoatColor => "Coat color", + Channel::CoatAnisotropy => "Coat anisotropy", + Channel::CoatSpecularLevel => "Coat specular level", + Channel::CoatTangent => "Coat tangent", + Channel::ThinFilmWeight => "Thin-film weight", + Channel::Tangent => "Tangent", + Channel::BlendingMask => "Blending mask", + Channel::Diffuse => "Diffuse", + Channel::Displacement => "Displacement", + Channel::Ior => "Ior", + Channel::Reflection => "Reflection", + Channel::Transmissive => "Transmissive", + Channel::User0 => "User0", + Channel::User1 => "User1", + Channel::User2 => "User2", + Channel::User3 => "User3", + Channel::User4 => "User4", + Channel::User5 => "User5", + Channel::User6 => "User6", + Channel::User7 => "User7", + Channel::User8 => "User8", + Channel::User9 => "User9", + Channel::User10 => "User10", + Channel::User11 => "User11", + Channel::User12 => "User12", + Channel::User13 => "User13", + Channel::User14 => "User14", + Channel::User15 => "User15", + Channel::User16 => "User16", + Channel::User17 => "User17", + Channel::User18 => "User18", + Channel::User19 => "User19", + Channel::User20 => "User20", + Channel::User21 => "User21", + Channel::User22 => "User22", + Channel::User23 => "User23", + Channel::User24 => "User24", + Channel::User25 => "User25", + Channel::User26 => "User26", + Channel::User27 => "User27", + Channel::User28 => "User28", + Channel::User29 => "User29", + Channel::User30 => "User30", + Channel::User31 => "User31", } } @@ -188,6 +415,57 @@ impl Channel { Channel::ScatterWeight => "scatter", Channel::Transmission => "transm", Channel::CoatNormal => "coat nrm", + Channel::BaseWeight => "base weight", + Channel::BaseDiffuseRoughness => "diffuse rough", + Channel::SpecularWeight => "spec weight", + Channel::SpecularColor => "spec color", + Channel::TransmissionColor => "transm color", + Channel::SubsurfaceColor => "sss color", + Channel::SubsurfaceRadiusScale => "sss radius", + Channel::CoatColor => "coat color", + Channel::CoatAnisotropy => "coat aniso", + Channel::CoatSpecularLevel => "coat spec", + Channel::CoatTangent => "coat tangent", + Channel::ThinFilmWeight => "thin film", + Channel::Tangent => "tangent", + Channel::BlendingMask => "blend mask", + Channel::Diffuse => "diffuse", + Channel::Displacement => "displace", + Channel::Ior => "ior", + Channel::Reflection => "reflection", + Channel::Transmissive => "transmissive", + Channel::User0 => "user0", + Channel::User1 => "user1", + Channel::User2 => "user2", + Channel::User3 => "user3", + Channel::User4 => "user4", + Channel::User5 => "user5", + Channel::User6 => "user6", + Channel::User7 => "user7", + Channel::User8 => "user8", + Channel::User9 => "user9", + Channel::User10 => "user10", + Channel::User11 => "user11", + Channel::User12 => "user12", + Channel::User13 => "user13", + Channel::User14 => "user14", + Channel::User15 => "user15", + Channel::User16 => "user16", + Channel::User17 => "user17", + Channel::User18 => "user18", + Channel::User19 => "user19", + Channel::User20 => "user20", + Channel::User21 => "user21", + Channel::User22 => "user22", + Channel::User23 => "user23", + Channel::User24 => "user24", + Channel::User25 => "user25", + Channel::User26 => "user26", + Channel::User27 => "user27", + Channel::User28 => "user28", + Channel::User29 => "user29", + Channel::User30 => "user30", + Channel::User31 => "user31", } } @@ -215,6 +493,57 @@ impl Channel { Channel::ScatterWeight => "scatterWeight", Channel::Transmission => "transmission", Channel::CoatNormal => "coatNormal", + Channel::BaseWeight => "baseWeight", + Channel::BaseDiffuseRoughness => "baseDiffuseRoughness", + Channel::SpecularWeight => "specularWeight", + Channel::SpecularColor => "specularColor", + Channel::TransmissionColor => "transmissionColor", + Channel::SubsurfaceColor => "subsurfaceColor", + Channel::SubsurfaceRadiusScale => "subsurfaceRadiusScale", + Channel::CoatColor => "coatColor", + Channel::CoatAnisotropy => "coatAnisotropy", + Channel::CoatSpecularLevel => "coatSpecularLevel", + Channel::CoatTangent => "coatTangent", + Channel::ThinFilmWeight => "thinFilmWeight", + Channel::Tangent => "tangent", + Channel::BlendingMask => "blendingMask", + Channel::Diffuse => "diffuse", + Channel::Displacement => "displacement", + Channel::Ior => "ior", + Channel::Reflection => "reflection", + Channel::Transmissive => "transmissive", + Channel::User0 => "user0", + Channel::User1 => "user1", + Channel::User2 => "user2", + Channel::User3 => "user3", + Channel::User4 => "user4", + Channel::User5 => "user5", + Channel::User6 => "user6", + Channel::User7 => "user7", + Channel::User8 => "user8", + Channel::User9 => "user9", + Channel::User10 => "user10", + Channel::User11 => "user11", + Channel::User12 => "user12", + Channel::User13 => "user13", + Channel::User14 => "user14", + Channel::User15 => "user15", + Channel::User16 => "user16", + Channel::User17 => "user17", + Channel::User18 => "user18", + Channel::User19 => "user19", + Channel::User20 => "user20", + Channel::User21 => "user21", + Channel::User22 => "user22", + Channel::User23 => "user23", + Channel::User24 => "user24", + Channel::User25 => "user25", + Channel::User26 => "user26", + Channel::User27 => "user27", + Channel::User28 => "user28", + Channel::User29 => "user29", + Channel::User30 => "user30", + Channel::User31 => "user31", } } @@ -225,8 +554,14 @@ impl Channel { Channel::ALL.into_iter().find(|c| norm(c.id()) == want || norm(c.label()) == want || norm(c.short()) == want || norm(&format!("{c:?}")) == want) } + /// Position in [`Channel::ALL`] (the declaration order) pub fn index(self) -> usize { - Channel::ALL.iter().position(|c| *c == self).unwrap_or(0) + self as usize + } + + /// Whether our shader reads the channel; the others are stored and exported for other shaders + pub fn is_shaded(self) -> bool { + self.index() < Channel::SHADED_COUNT } } @@ -253,6 +588,7 @@ impl ChannelFormat { ChannelKind::Signed => ChannelFormat::L16F, } } + /// Every format, in the order the channel settings list them pub const ALL: [ChannelFormat; 9] = [ ChannelFormat::Srgb8, @@ -267,8 +603,8 @@ impl ChannelFormat { ]; /// A format by its label, ignoring case ("srgb8", "L16F") - pub fn parse(s: &str) -> Option { - ChannelFormat::ALL.into_iter().find(|f| f.label().eq_ignore_ascii_case(s.trim())) + pub fn parse(label: &str) -> Option { + ChannelFormat::ALL.into_iter().find(|format| format.label().eq_ignore_ascii_case(label.trim())) } /// Grey formats keep one value per texel: a colour channel stored in one turns grey @@ -345,6 +681,19 @@ mod tests { assert_eq!(ChannelFormat::parse("RGB4"), None); } + #[test] + fn unshaded_channels_round_trip_through_ids() { + // Project files and commands name channels by id: every added channel must come back as itself + for c in Channel::ALL.into_iter().filter(|c| !c.is_shaded()) { + assert_eq!(Channel::parse(c.id()), Some(c)); + let json = serde_json::to_string(&c).unwrap_or_default(); + assert_eq!(serde_json::from_str::(&json).ok(), Some(c)); + } + assert!(Channel::LOBES.iter().chain(&Channel::DEFAULT_SET).all(|c| c.is_shaded())); + assert_eq!(Channel::parse("User31"), Some(Channel::User31)); + assert_eq!(Channel::parse("thin-film weight"), Some(Channel::ThinFilmWeight)); + } + #[test] fn index_matches_all_order() { for (i, c) in Channel::ALL.iter().enumerate() { diff --git a/crates/engine/src/inspect.rs b/crates/engine/src/inspect.rs index 18732cf9..1c5f9c7e 100644 --- a/crates/engine/src/inspect.rs +++ b/crates/engine/src/inspect.rs @@ -270,7 +270,7 @@ pub fn texture_set(session: &Session, index: usize) -> Value { "blockResolution": texture_set.block_resolution(), "uvTiles": texture_set.uv_tiles, "tiles": tiles, - "channels": texture_set.formats().iter().map(|(channel, format)| json!({ "channel": channel.id(), "format": format.label() })).collect::>(), + "channels": texture_set.formats().iter().map(|(channel, format)| json!({ "channel": channel.id(), "format": format.label(), "shaded": channel.is_shaded() })).collect::>(), "layers": session.doc.project.walk(index).len(), "parts": crate::set_cmds::parts(session, index), "baked": crate::project_cmds::baked_json(session.doc.baked.get(&index)), diff --git a/crates/engine/src/set_cmds.rs b/crates/engine/src/set_cmds.rs index bdf4be87..3fe920c9 100644 --- a/crates/engine/src/set_cmds.rs +++ b/crates/engine/src/set_cmds.rs @@ -498,4 +498,28 @@ mod tests { assert_eq!(crate::inspect::texture_set(&s, 0)["aoMixing"], json!("multiply")); assert!(!s.take_uploads(0).is_empty(), "undo resends the set too"); } + + #[test] + fn channels_our_shader_ignores_are_added_marked_and_exported() { + let mut s = Session::new_project("t", texturecraft_geom::primitives::material_ball(), "builtin:material_ball", None, 128).unwrap(); + for channel in ["user3", "Displacement", "coat tangent"] { + crate::execute(&mut s, "textureSet.channel.add", &json!({"ts": 0, "channel": channel})).unwrap(); + } + let channels = crate::inspect::texture_set(&s, 0)["channels"].clone(); + let shaded = |id: &str| channels.as_array().and_then(|list| list.iter().find(|c| c["channel"] == id)).map(|c| c["shaded"].clone()); + assert_eq!((shaded("user3"), shaded("displacement"), shaded("coatTangent")), (Some(json!(false)), Some(json!(false)), Some(json!(false)))); + assert_eq!(shaded("baseColor"), Some(json!(true))); + + let plan = crate::execute(&mut s, "export.plan", &json!({"preset": "Separate maps"})).unwrap(); + let files: Vec<(Value, String)> = + plan.as_array().into_iter().flatten().map(|f| (f["ts"].clone(), f["file"].as_str().unwrap_or_default().to_ascii_lowercase())).collect(); + for map in ["user3", "displacement", "coattangent"] { + let from = |ts: usize| files.iter().any(|(t, file)| *t == json!(ts) && file.contains(map)); + assert!(from(0) && !from(1), "{map} exported only from the set that has it: {files:?}"); + } + + s.update(); + let composite = &s.caches[0].composite; + assert!(composite.channels.contains_key(&Channel::User3) && composite.channels.contains_key(&Channel::CoatTangent)); + } } diff --git a/crates/formats/src/export/mod.rs b/crates/formats/src/export/mod.rs index ed79cb96..454ab930 100644 --- a/crates/formats/src/export/mod.rs +++ b/crates/formats/src/export/mod.rs @@ -36,8 +36,8 @@ const HEIGHT_SPAN: f32 = 16.0; const JPEG_QUALITY: u8 = 95; const PSD_MAX_SIDE_PIXELS: u32 = 30_000; const PSD_MAX_FILE_BYTES: u64 = 2 * 1024 * 1024 * 1024; -/// Preset limits (user presets are untrusted JSON). -const MAX_MAPS: usize = 64; +/// Preset limits (user presets are untrusted JSON); maps leave room for one per channel plus packed maps +const MAX_MAPS: usize = 128; const MAX_TEMPLATE: usize = 256; const MAX_STEM: usize = 200; /// Longest preset name. @@ -490,7 +490,7 @@ pub struct ExportInput<'a> { pub composite: &'a Composite, pub baked: &'a BakedMaps, pub coverage: &'a [bool], - /// The set's UV seams, which 3D Space Neighbor padding crosses + /// The set's UV seams, which padding across seams (3D) crosses pub seams: &'a [UvSeam], pub mesh_name: &'a str, } @@ -769,8 +769,7 @@ struct Sampler<'a> { coverage: &'a [bool], /// Composite width. res: u32, - /// Texels across and down an atlas block (the composite for a classic set): the height - /// slope and the slope window follow the block. + /// Texels across and down an atlas block (the composite for a classic set), which the height slope follows block: (u32, u32), /// The share of its block each tile fills: a smaller tile's height slope shrinks with it. scales: BlockScales, @@ -811,22 +810,24 @@ impl Sampler<'_> { self.coverage.get((y as usize) * self.res as usize + x as usize).copied().unwrap_or(false) } - /// Normal from the height channel (the set's height to normal method; uncovered neighbours repeat the centre). + /// Normal from the height channel (the set's height to normal method; uncovered neighbours repeat the centre) fn height_normal(&self, x: u32, y: u32) -> Vec3 { let center = self.channel(Channel::Height, At::Texel(x, y))[0]; - // Clamped to the texel's UV tile. - let (tw, th) = (self.block.0.max(1), self.block.1.max(1)); - let (x0, y0) = ((x / tw * tw) as i64, (y / th * th) as i64); + // Clamped to the texel's UV tile + let (block_width, block_height) = (self.block.0.max(1), self.block.1.max(1)); + let (x0, y0) = ((x / block_width * block_width) as i64, (y / block_height * block_height) as i64); let h = |dx: i32, dy: i32| { - let (sx, sy) = ((x as i64 + dx as i64).clamp(x0, x0 + tw as i64 - 1) as u32, (y as i64 + dy as i64).clamp(y0, y0 + th as i64 - 1) as u32); + let sx = (x as i64 + dx as i64).clamp(x0, x0 + block_width as i64 - 1) as u32; + let sy = (y as i64 + dy as i64).clamp(y0, y0 + block_height as i64 - 1) as u32; if self.covered(sx, sy) { self.channel(Channel::Height, At::Texel(sx, sy))[0] } else { center } }; let [gx, gy] = self.set.height_to_normal.slope(h); + // Slopes per texel become slopes across the tile along each side - let s = self.set.height_strength * self.scales.at(x, y) / HEIGHT_SPAN; - let (sx, sy) = (s * tw as f32, s * th as f32); - // Image y points down; OpenGL normals have +Y up the image. - Vec3::new(-gx * sx, gy * sy, 1.0).try_normalize().unwrap_or(Vec3::Z) + let strength = self.set.height_strength * self.scales.at(x, y) / HEIGHT_SPAN; + let (scale_x, scale_y) = (strength * block_width as f32, strength * block_height as f32); + // Image y points down; OpenGL normals have +Y up the image + Vec3::new(-gx * scale_x, gy * scale_y, 1.0).try_normalize().unwrap_or(Vec3::Z) } /// The final tangent-space normal (OpenGL): baked normal ⊕ (height ⊕ normal channel). @@ -1059,22 +1060,24 @@ pub fn scale_export_side(source_side: u32, block_resolution: u32, export_size: O u32::try_from(scaled).unwrap_or(u32::MAX).max(u32::from(source_side > 0)) } -fn diffuse_blocks(data: &mut Vec, (width, height): (usize, usize), channels: usize, known: &[bool], (block_w, block_h): (usize, usize)) { +fn diffuse_blocks(data: &mut Vec, (width, height): (usize, usize), channels: usize, known: &[bool], block_size: (usize, usize)) { + let (block_width, block_height) = block_size; + // A whole image or a separately exported tile already occupies a contiguous buffer - if block_w >= width && block_h >= height { + if block_width >= width && block_height >= height { diffuse_fill(data, (width, height), channels, known); return; } - for block_y in (0..height).step_by(block_h.max(1)) { - for block_x in (0..width).step_by(block_w.max(1)) { - let (block_width, block_height) = (block_w.min(width - block_x), block_h.min(height - block_y)); - let rows = || (block_y..block_y + block_height).map(|y| (y * width + block_x)..(y * width + block_x + block_width)); + for block_y in (0..height).step_by(block_height.max(1)) { + for block_x in (0..width).step_by(block_width.max(1)) { + let (clipped_width, clipped_height) = (block_width.min(width - block_x), block_height.min(height - block_y)); + let rows = || (block_y..block_y + clipped_height).map(|y| (y * width + block_x)..(y * width + block_x + clipped_width)); let mut block_data: Vec = rows().flat_map(|row| data.get(row.start * channels..row.end * channels).unwrap_or_default().iter().copied()).collect(); let block_known: Vec = rows().flat_map(|row| known.get(row).unwrap_or_default().iter().copied()).collect(); - diffuse_fill(&mut block_data, (block_width, block_height), channels, &block_known); - for (row, chunk) in rows().zip(block_data.chunks(block_width * channels)) { + diffuse_fill(&mut block_data, (clipped_width, clipped_height), channels, &block_known); + for (row, chunk) in rows().zip(block_data.chunks(clipped_width * channels)) { if let Some(destination) = data.get_mut(row.start * channels..row.end * channels) { destination.copy_from_slice(chunk); } diff --git a/crates/formats/src/presets.rs b/crates/formats/src/presets.rs index 2f2879a4..13beff9e 100644 --- a/crates/formats/src/presets.rs +++ b/crates/formats/src/presets.rs @@ -87,9 +87,11 @@ pub fn builtin_presets() -> Vec { vec![ preset(DEFAULT_PRESET, { let mut maps: Vec = - Channel::ALL.into_iter().filter(|c| !matches!(c, Channel::Normal | Channel::AmbientOcclusion)).map(channel_map).collect(); + Channel::ALL.into_iter().filter(|c| c.is_shaded() && !matches!(c, Channel::Normal | Channel::AmbientOcclusion)).map(channel_map).collect(); maps.push(map("normal", 8, rgb(|k| ch(Channel::Normal, k)))); maps.push(map("ambientOcclusion", 8, gray(virt(VirtualMap::AoMixed, 0)))); + // Later channels come last, so the maps automation addresses by index keep their place + maps.extend(Channel::ALL.into_iter().filter(|c| !c.is_shaded()).map(channel_map)); maps }), // Spec: https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#metallic-roughness-material diff --git a/crates/ui-egui/src/export_templates/map_lists.rs b/crates/ui-egui/src/export_templates/map_lists.rs index f190370c..7fd30b1d 100644 --- a/crates/ui-egui/src/export_templates/map_lists.rs +++ b/crates/ui-egui/src/export_templates/map_lists.rs @@ -28,40 +28,56 @@ fn missing(name: &'static str) -> MapEntry { /// Input maps in the OpenPBR parameter groups, then TextureCraft's channels outside OpenPBR pub static INPUT_MAPS: LazyLock> = LazyLock::new(|| { vec![ - (n_("Base"), vec![missing(n_("Base weight")), channel(Channel::BaseColor), channel(Channel::Metallic), missing(n_("Base diffuse roughness"))]), + (n_("Base"), vec![channel(Channel::BaseWeight), channel(Channel::BaseColor), channel(Channel::Metallic), channel(Channel::BaseDiffuseRoughness)]), ( n_("Specular"), vec![ - missing(n_("Specular weight")), - missing(n_("Specular color")), + channel(Channel::SpecularWeight), + channel(Channel::SpecularColor), channel(Channel::Roughness), channel(Channel::SpecularLevel), channel(Channel::AnisotropyLevel), channel(Channel::AnisotropyAngle), ], ), - (n_("Transmission"), vec![channel(Channel::Transmission), missing(n_("Transmission color"))]), - (n_("Subsurface"), vec![channel(Channel::ScatterWeight), missing(n_("Subsurface color")), missing(n_("Subsurface radius"))]), + (n_("Transmission"), vec![channel(Channel::Transmission), channel(Channel::TransmissionColor)]), + (n_("Subsurface"), vec![channel(Channel::ScatterWeight), channel(Channel::SubsurfaceColor), channel(Channel::SubsurfaceRadiusScale)]), ( n_("Coat"), vec![ channel(Channel::CoatWeight), - missing(n_("Coat color")), + channel(Channel::CoatColor), channel(Channel::CoatRoughness), - missing(n_("Coat roughness anisotropy")), + channel(Channel::CoatAnisotropy), missing(n_("Coat IOR")), + channel(Channel::CoatSpecularLevel), channel(Channel::CoatNormal), - missing(n_("Coat tangent")), + channel(Channel::CoatTangent), ], ), (n_("Sheen"), vec![channel(Channel::SheenWeight), channel(Channel::SheenColor), channel(Channel::SheenRoughness)]), (n_("Emission"), vec![channel(Channel::Emissive)]), - (n_("Thin film"), vec![missing(n_("Thin film weight")), missing(n_("Thin film thickness"))]), + (n_("Thin film"), vec![channel(Channel::ThinFilmWeight), missing(n_("Thin film thickness"))]), ( n_("Geometry"), - vec![channel(Channel::Opacity), channel(Channel::Height), channel(Channel::Normal), missing(n_("Tangent")), channel(Channel::AmbientOcclusion)], + vec![channel(Channel::Opacity), channel(Channel::Height), channel(Channel::Normal), channel(Channel::Tangent), channel(Channel::AmbientOcclusion)], ), - (n_("Other"), vec![channel(Channel::Glossiness), channel(Channel::Specular)]), + ( + n_("Other"), + [ + Channel::BlendingMask, + Channel::Diffuse, + Channel::Displacement, + Channel::Glossiness, + Channel::Ior, + Channel::Reflection, + Channel::Specular, + Channel::Transmissive, + ] + .map(channel) + .to_vec(), + ), + (n_("User"), Channel::ALL.into_iter().filter(|c| c.id().starts_with("user")).map(channel).collect()), ] }); diff --git a/crates/ui-egui/tests/it/output_templates.rs b/crates/ui-egui/tests/it/output_templates.rs index d8033152..ff6f91f7 100644 --- a/crates/ui-egui/tests/it/output_templates.rs +++ b/crates/ui-egui/tests/it/output_templates.rs @@ -432,15 +432,28 @@ fn the_map_lists_stand_in_three_panes_with_their_groups_and_names() { assert!(mesh.left() > input.right(), "Mesh maps stand in a column right of Input maps"); assert!(converted.top() > mesh.bottom() && (converted.left() - mesh.left()).abs() < 2.0, "Converted maps stand below Mesh maps"); - for group in ["Transmission", "Subsurface", "Sheen", "Thin film", "Other"] { + for group in ["Transmission", "Subsurface", "Sheen", "Thin film", "Other", "User"] { assert!(h.query_all_by_label(group).next().is_some(), "group {group}"); } - for name in ["Specular level", "Sheen weight", "Coat normal", "Emissive", "World Space Normal", "Bent Normals", "Normal DirectX", "F0 from specular level"] - { + for name in [ + "Specular level", + "Sheen weight", + "Coat normal", + "Emissive", + "World Space Normal", + "Bent Normals", + "Normal DirectX", + "F0 from specular level", + "Base weight", + "Coat tangent", + "Thin-film weight", + "Subsurface radius scale", + "User31", + ] { let entry = h.query_all_by_label(name).next().unwrap_or_else(|| panic!("{name}")); assert!(!entry.accesskit_node().is_disabled(), "{name} can be dragged"); } - for name in ["Base weight", "Coat tangent", "Thin film weight", "Subsurface radius"] { + for name in ["Coat IOR", "Thin film thickness"] { let entry = h.query_all_by_label(name).next().unwrap_or_else(|| panic!("{name}")); assert!(entry.accesskit_node().is_disabled(), "{name} is listed greyed"); }