Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(pipeline): imported skin and hair carry no scattering or second highlight a glTF does not state

yhhc7d4566842b8
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d68fe685c..9173aaf68 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,7 @@ published separately; it ships inside the editor.
### Fixed
+- **Character materials shade like the source.** A model imported with Character Materials now shades like the Principled shader it was authored against: a glTF carries no subsurface scattering and no second strand highlight, so the Skin shader's scattering, wrap and fuzz and the Hair shader's second highlight, translucency and root darkening are written as off, and a hair material's specular factor is scaled to the strand highlight's own units. Measured against Blender's render of the same frame, a character's hair comes out about 15 percent brighter than the reference where it was two to three times too bright, and the skin no longer glows in the shadows.
- **AgX view transform.** A new post-process effect, agx, applies the AgX view transform Blender renders with, taken from the data Blender ships: scene-linear colour goes in and display-linear comes out, so put it last and leave the project's output transform at none. Its contrast setting is the look (1 is AgX Base, 1.2 is Medium High Contrast), it carries its own table, and against Blender's own render of the same frame the colours of a character come out within about two percent.
- **Opaque textures under a cutout material.** A texture whose alpha is fully opaque, used by a cutout material (a hair material or any alpha-cutoff one), no longer vanishes once it is minified. Coverage-preserving mip levels were scaling its alpha down onto the cutoff, so every level past the first was discarded; a level that already reaches the share it must keep is now left alone.
- **Shadow program for a normal-mapped mesh with tangents.** A model with tangents and a normal map no longer stops its shadow program from linking when the sun casts shadows. The depth pass wrote no tangent varying while the fragment stage still read one, so the shader failed on WebGL2 and the logged error named no material; the depth variant now leaves the tangent frame out.
diff --git a/pipeline/src/assets/modelImport.ts b/pipeline/src/assets/modelImport.ts
index 03c85f958..f13c618fd 100644
--- a/pipeline/src/assets/modelImport.ts
+++ b/pipeline/src/assets/modelImport.ts
@@ -703,7 +703,18 @@ function hasProduct(material: ImportedMaterial, refs: ProductRefs): boolean {
return needsMaterial(material) || (!!refs.characters && characterShading(material) !== undefined);
}
-/** What the character shaders read, from what the source says: the maps they share, and the cutout hair needs. */
+/**
+ * How much of the Hair shader's `u_specular` one unit of a glTF specular factor is. The factor scales a Fresnel reflectance of 0.04; the engine's
+ * strand highlight is an authored lobe with a peak of about half the light, so the same factor is far too bright without this. Measured against
+ * Blender's Principled at roughness 0.43 and a specular level of 0.3 (tools/render-align in the star-neighbors game).
+ */
+const HAIR_SPECULAR_PER_GLTF = 0.07;
+
+/**
+ * What the character shaders read, from what the source says: the maps they share, and the cutout hair needs. What a glTF does not say it
+ * does not have: it carries no subsurface scattering and no second strand highlight, so those are written as off (they stay on the shader
+ * for a hand-made material), and the import shades like the Principled shader the model was authored against.
+ */
function characterProperties(shading: CharacterShading, material: ImportedMaterial, properties: Record<string, unknown>,
bind: (name: string, image?: ImportedImageRef) => void): void {
// Skin and hair read the glTF packing (occlusion, roughness, metalness) as their `u_ormMap`; their roughness is a SCALE on it,
@@ -714,7 +725,13 @@ function characterProperties(shading: CharacterShading, material: ImportedMateri
bind('u_ormMap', material.metallicRoughnessTexture);
if (rough !== undefined && !material.metallicRoughnessTexture) properties.u_roughness = rough;
}
+ if (shading === 'skin') {
+ properties.u_sssWrap = 0; properties.u_translucency = 0; properties.u_lobe2 = 0; properties.u_fuzz = 0;
+ }
if (shading === 'hair') {
+ properties.u_translucency = 0; properties.u_shiftAmount = 0; properties.u_rootDark = 0;
+ properties.u_secondaryTint = { r: 0, g: 0, b: 0, a: 1 };
+ properties.u_specular = (material.specular ?? 1) * HAIR_SPECULAR_PER_GLTF;
properties.u_alphaCutoff = material.alphaCutoff ?? 0.5;
bind('u_flowMap', material.flowTexture);
bind('u_shiftMap', material.shiftTexture);
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 30d794d44..32f6a14c8 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -46,6 +46,8 @@ export const NOTED = {
{"note":"A texture whose alpha is fully opaque, used by a cutout material (a hair material or any alpha-cutoff one), no longer vanishes once it is minified. Coverage-preserving mip levels were scaling its alpha down onto the cutoff, so every level past the first was discarded; a level that already reaches the share it must keep is now left alone."},
'feat(postprocess): an agx effect applies the AgX view transform Blender uses, from the table Blender ships':
{"note":"A new post-process effect, agx, applies the AgX view transform Blender renders with, taken from the data Blender ships: scene-linear colour goes in and display-linear comes out, so put it last and leave the project's output transform at none. Its contrast setting is the look (1 is AgX Base, 1.2 is Medium High Contrast), it carries its own table, and against Blender's own render of the same frame the colours of a character come out within about two percent."},
+ 'feat(pipeline): imported skin and hair carry no scattering or second highlight a glTF does not state':
+ {"note":"A model imported with Character Materials now shades like the Principled shader it was authored against: a glTF carries no subsurface scattering and no second strand highlight, so the Skin shader's scattering, wrap and fuzz and the Hair shader's second highlight, translucency and root darkening are written as off, and a hair material's specular factor is scaled to the strand highlight's own units. Measured against Blender's render of the same frame, a character's hair comes out about 15 percent brighter than the reference where it was two to three times too bright, and the skin no longer glows in the shadows."},
'fix: serialize binaryen optimization on windows': { internal: 'Uses one optimizer worker after wider builds reproduced heap corruption with four; release optimization flags stay unchanged.' },
'feat: add budgeted 2d and 3d particle scene collisions': { note: 'Budgeted particle scene collisions.' },
'feat(editor): add particle collision authoring and diagnostics': { note: 'Budgeted particle scene collisions.' },