diff --git a/crates/formats/README.md b/crates/formats/README.md index 8cd9e1cd..89482c00 100644 --- a/crates/formats/README.md +++ b/crates/formats/README.md @@ -141,6 +141,7 @@ Built-in presets (each one lists the public specification its packing follows in | 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` | +| Sketchfab Metalness (separate maps) | `BaseColor` (no alpha), `Metalness`, `Roughness`, `Normal` (DirectX), `AmbientOcclusion`, `Emission` | | 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 30b8f6ec..e9eb5a63 100644 --- a/crates/formats/src/export/tests.rs +++ b/crates/formats/src/export/tests.rs @@ -1835,3 +1835,20 @@ fn the_roblox_template_writes_opacity_in_the_colour_alpha_and_opengl_normals() { let green = pixel(find(&files, "_Normal.png"))[1]; assert!((green - open_gl_green).abs() <= 1, "OpenGL normal: green {green}"); } + +#[test] +fn the_sketchfab_template_writes_directx_normals_and_one_map_per_channel() { + let mut fx = packing_fixture(); + let open_gl_green = tilt_normals(&mut fx); + + let files = fx.render_preset("Sketchfab Metalness (separate maps)"); + + assert_eq!(decode(find(&files, "_BaseColor.png")).color(), image::ColorType::Rgb8, "no alpha on the base color"); + for (input, expected) in [("Metalness", 0.8), ("Roughness", 0.4), ("AmbientOcclusion", 0.6)] { + let file = find(&files, &format!("_{input}.png")); + assert_eq!(decode(file).color(), image::ColorType::L8, "{input} is linear grayscale"); + assert_close(pixel(file), [byte(expected), byte(expected), byte(expected), 255], input); + } + let green = pixel(find(&files, "_Normal.png"))[1]; + assert!((green - (255 - open_gl_green)).abs() <= 1, "DirectX normal: green {green}"); +} diff --git a/crates/formats/src/presets.rs b/crates/formats/src/presets.rs index e510a7c1..e41c4094 100644 --- a/crates/formats/src/presets.rs +++ b/crates/formats/src/presets.rs @@ -276,6 +276,20 @@ pub fn builtin_presets() -> Vec { map("Roughness", 8, gray(ch(Channel::Roughness, 0))), ], ), + // Spec: https://help.sketchfab.com/en/articles/16152630-pbr-maps (sRGB base color, linear grayscale metalness; no alpha, the docs don't say opacity reads it) + // Spec: https://help.sketchfab.com/en/articles/16152634-materials-pbr (roughness, AO and emission channels) + // Spec: https://help.sketchfab.com/en/articles/16152621-normal-map-bump-map (DirectX normals by default) + preset( + "Sketchfab Metalness (separate maps)", + vec![ + map("BaseColor", 8, rgb(|k| ch(Channel::BaseColor, k))), + map("Metalness", 8, gray(ch(Channel::Metallic, 0))), + map("Roughness", 8, gray(ch(Channel::Roughness, 0))), + map("Normal", 8, normal(VirtualMap::NormalDirectX)), + map("AmbientOcclusion", 8, gray(virt(VirtualMap::AoMixed, 0))), + map("Emission", 8, rgb(|k| ch(Channel::Emissive, k))), + ], + ), 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 212894c6..edc6c265 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, Roblox SurfaceAppearance, 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, Sketchfab (metalness), 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.