diff --git a/crates/formats/README.md b/crates/formats/README.md index 4817d0e8..8cd9e1cd 100644 --- a/crates/formats/README.md +++ b/crates/formats/README.md @@ -140,6 +140,7 @@ Built-in presets (each one lists the public specification its packing follows in | Unreal Engine Subsurface Profile (Packed) | `BaseColor` (no alpha), `OcclusionRoughnessMetallic`, `Normal` (DirectX), `SubsurfaceMask` (scatter weight, for the Opacity input) | | glTF Specular Glossiness (archived extension) | `Diffuse` (A = opacity), `SpecularGlossiness` (RGB specular, A glossiness, from the set's own channels), `Normal` (OpenGL), `Occlusion`, `Emissive` | | Redshift Standard Material (separate maps) | one map per Standard Material input the set has: `BaseColor`, `Metalness`, `ReflectionRoughness`, `Normal` (OpenGL), `EmissionColor`, `Opacity`, `SubsurfaceWeight`, `CoatWeight`, `CoatRoughness`, `SheenWeight`, `SheenColor`, `SheenRoughness` | +| Roblox SurfaceAppearance (separate maps) | `Color` (A = opacity), `Normal` (OpenGL), `Metalness`, `Roughness` | | Separate maps | one file per channel, gray where scalar, height 16-bit | | Mesh maps | every baked map (`$channel` = map id), 16-bit | diff --git a/crates/formats/src/export/tests.rs b/crates/formats/src/export/tests.rs index 2b6e604e..30b8f6ec 100644 --- a/crates/formats/src/export/tests.rs +++ b/crates/formats/src/export/tests.rs @@ -1741,19 +1741,6 @@ fn a_map_preview_holds_the_values_its_file_stores() { assert!(MapPreview::sample(&fx.input(), &options, options.preset.maps.len(), 8).is_err(), "a map the template doesn't have is an error"); } -/// The 8-bit value of an image position as RGBA -fn pixel(file: &ExportedFile) -> [i32; 4] { - decode(file).to_rgba8().get_pixel(3, 3).0.map(i32::from) -} - -fn byte(value: f32) -> i32 { - (value * 255.0).round() as i32 -} - -fn assert_close(actual: [i32; 4], expected: [i32; 4], what: &str) { - assert!(actual.iter().zip(expected).all(|(a, e)| (a - e).abs() <= 1), "{what}: {actual:?} instead of {expected:?}"); -} - /// Tilts every normal of `fx` and returns the green byte an OpenGL normal map stores for it fn tilt_normals(fx: &mut Fx) -> i32 { let tilt = Vec3::new(0.3, 0.4, 0.0); @@ -1830,3 +1817,21 @@ fn the_redshift_template_writes_one_map_per_input_the_set_has() { assert!((green - open_gl_green).abs() <= 1, "OpenGL normal: green {green}"); assert!(!names.iter().any(|name| name.contains("Sheen") || name.contains("CoatRoughness")), "inputs the set lacks write no maps: {names:?}"); } + +#[test] +fn the_roblox_template_writes_opacity_in_the_colour_alpha_and_opengl_normals() { + let mut fx = packing_fixture(); + let open_gl_green = tilt_normals(&mut fx); + + let files = fx.render_preset("Roblox SurfaceAppearance (separate maps)"); + + let base = fx.comp.value(Channel::BaseColor, 3, 3).map(|v| byte(linear_to_srgb(v))); + assert_close(pixel(find(&files, "_Color.png")), [base[0], base[1], base[2], byte(0.9)], "sRGB colour, opacity in alpha"); + for (input, expected) in [("Metalness", 0.8), ("Roughness", 0.4)] { + let file = find(&files, &format!("_{input}.png")); + assert_eq!(decode(file).color(), image::ColorType::L8, "{input} is grayscale"); + assert_close(pixel(file), [byte(expected), byte(expected), byte(expected), 255], input); + } + let green = pixel(find(&files, "_Normal.png"))[1]; + assert!((green - open_gl_green).abs() <= 1, "OpenGL normal: green {green}"); +} diff --git a/crates/formats/src/presets.rs b/crates/formats/src/presets.rs index 5b870db3..e510a7c1 100644 --- a/crates/formats/src/presets.rs +++ b/crates/formats/src/presets.rs @@ -264,6 +264,18 @@ pub fn builtin_presets() -> Vec { gray8("SheenRoughness", Channel::SheenRoughness), ] }), + // Spec: https://create.roblox.com/docs/art/modeling/surface-appearance (ColorMap alpha is opacity) + // Spec: https://create.roblox.com/docs/art/modeling/texture-specifications (OpenGL normals only; grayscale metalness and roughness) + // Spec: https://create.roblox.com/docs/art/modeling/reimport (the file name suffix it assigns to each map) + preset( + "Roblox SurfaceAppearance (separate maps)", + vec![ + map("Color", 8, base_with_alpha()), + map("Normal", 8, normal(VirtualMap::NormalOpenGl)), + map("Metalness", 8, gray(ch(Channel::Metallic, 0))), + map("Roughness", 8, gray(ch(Channel::Roughness, 0))), + ], + ), preset("Separate maps", Channel::ALL.into_iter().map(channel_map).collect()), preset( "Mesh maps", diff --git a/docs/features.md b/docs/features.md index facc1ea0..212894c6 100644 --- a/docs/features.md +++ b/docs/features.md @@ -163,7 +163,7 @@ Everything TextureCraft does today, by area. What's still missing is in [`ROADMA finished; the bake bar follows the newest map, pins a finished one or shows the material. - **Export presets** for glTF PBR Metal Roughness, Unreal Engine (packed), Unity HDRP (mask map), Unity Standard, Unity URP Lit, USD Preview Surface, Blender (Principled BSDF), Godot 4 (ORM), OpenPBR (with the coat, fuzz, - anisotropy, transmission and subsurface maps), Unreal Engine (subsurface profile), glTF specular/glossiness (archived extension), Redshift Standard Material, separate maps, mesh maps and document channels, in + anisotropy, transmission and subsurface maps), Unreal Engine (subsurface profile), glTF specular/glossiness (archived extension), Redshift Standard Material, Roblox SurfaceAppearance, separate maps, mesh maps and document channels, in PNG, JPEG, JPEG 2000, JNG, PGM, TGA, TIFF, BMP, WEBP, PSD, EXR or HDR at 8 bits (optionally dithered), 16 bits or 32-bit float (TIFF, EXR, HDR; 16-bit half float for EXR), with UV padding (dilation, infinite, or dilation + diffusion), size override and OpenGL or DirectX normals.