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.

fix(pipeline): an imported eye shades as the Principled shader it was authored against

yhh0e42a2f274d3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ebf12763b..2022b3d49 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -54,6 +54,9 @@ published separately; it ships inside the editor.
### Fixed
+- **Cut-out chains of coverage.** A cut-out's mip chain holds, as alpha, the share of texels its cut keeps, and its colour is the colour of what the cut keeps. The minified alpha is what a cut-out is drawn with, and a plain average of a soft mask (a painted band of eyelashes fading out) averaged to more than the cut keeps: the probe's lash card drew a pink veil over the iris where Blender draws a few lashes. The chain no longer rescales alpha to keep a cutoff's coverage, and an imported cut-out's clear texels take the colour of the solid ones nearest them, so even a mip the GPU makes does not average in what the painter left under alpha 0.
+- **Cut-out shadows.** A cut-out's shadow keeps the share of light it lets through, and is the same shape on both backends. The shadow pass read a card's alpha at level 0 on WebGPU (mips on WebGL2), and cut at the cutoff on both; where the card is smaller than a texel from the light it now cuts against a per-texel threshold through the mip chain, so a fringe of hair throws a shadow as deep as it is dense.
+- **Imported eyes.** An imported eye shades as the Principled shader it was authored against: the Eye shader's tinted white, its warm wrap of light past the terminator (which reddened a painted iris) and its lid darkening are written as off, and both its glossy layers take the source's roughness instead of a near-mirror cornea.
- **Energy in lit materials, and soft sun shadows as wide as the sun.** Lit materials keep the light a rough surface reflects and pass on what it does not. The environment's specular came from Karis' analytic fit, 21% low for a metal at roughness 0.5 and up to 80% off at a grazing view; it is now a fit to the integral itself (tools/gen-dfg-fit.py, worst 3%). The light a rough metal loses to bounces between its microfacets is returned (Fdez-Aguera's multiple-scattering term, and the same ratio on a lamp's highlight), where a metal at roughness 0.9 under a white sky came out at half of Blender's brightness. The diffuse under a dielectric's specular is reduced by what the specular reflects, as in the Principled shader. And a lamp's highlight takes Smith's height-correlated masking at alpha = roughness squared in place of the Schlick k = (r + 1)^2 / 8 remap, which left a rough metal's rim a quarter dark. In the render lab six spheres under a white sky now match Blender within 0.5% at every roughness, and flat cards of five albedos within 0.002, on both backends. A sun with a size casts a penumbra as wide as Blender's. The disc a penumbra was averaged over stopped at 8 texels of the map, which held a sun's soft edge to sixteen texels: with a fine cascade that is less than the sun throws, and the render lab measured an edge 60% as wide as Blender's. The disc now reaches 24 texels, its spiral of taps is turned point by point so the wider disc grains rather than bands, and each blocker tap forgives only as far as it stands from the point, so a box standing on a floor stays shadowed to its foot.
- **Mip chains on WebGPU.** On the WebGPU backend, a mesh without a material, a sprite and a particle are sampled through their texture's mip chain, as they always were on WebGL2: their WGSL read level 0 alone, so anything drawn smaller than its texture shimmered into stripes and moire there and not on the other backend. A compressed (KTX2) texture also keeps every level of its chain on WebGPU: the upload stopped at the first level whose side is not a multiple of four, which left a 1240x1268 hair atlas with level 0 alone. In the render lab a card of fine strands seen small now reads the same on both backends.
- **Cut-outs at a distance.** A cut-out seen from far enough away that its texture is smaller than a texel a pixel lets through as much as its texture covers. Its alpha was sharpened to a texel around the cutoff at every distance, and once the mips had averaged fine strands and the gaps between them to one value above the cutoff, the whole card turned solid: a hair card at arm's length drew as a plate. Where the texture is minified the mip-averaged alpha is now the coverage under multisampling, and the cutoff moves to a per-pixel threshold without it. In the render lab a card of fine cut-out strands lets through within 3% of what Blender does, where it let through nothing; the shader helper is cutoutCoverage, and u_time.w carries the scene's multisampling.
diff --git a/pipeline/src/assets/modelImport.ts b/pipeline/src/assets/modelImport.ts
index e051a6672..84511761e 100644
--- a/pipeline/src/assets/modelImport.ts
+++ b/pipeline/src/assets/modelImport.ts
@@ -761,7 +761,20 @@ function characterProperties(shading: CharacterShading, material: ImportedMateri
bind('u_shiftMap', material.shiftTexture);
if (material.tipSoftness !== undefined) properties.u_tipSoftness = material.tipSoftness;
} else delete properties.u_alphaCutoff;
- if (shading === 'eye') delete properties.u_normalMap;
+ if (shading === 'eye') {
+ delete properties.u_normalMap;
+ // What a glTF says of an eye is a painted texture and a roughness: the Principled shader it was authored against. So the Eye shader's
+ // own additions are written as off (a tinted white, light wrapping past the terminator in a warm colour, which turned a painted iris
+ // red, and lids darkening it), and both its glossy layers take the source's roughness instead of a near-mirror cornea. An eye given
+ // a depth map and an iris normal map by hand gets them back by setting these.
+ properties.u_scleraColor = { r: 1, g: 1, b: 1, a: 1 };
+ properties.u_scleraWrap = 0;
+ properties.u_lidShadow = 0;
+ const eyeRough = rough ?? 0.5;
+ properties.u_corneaRoughness = Math.max(eyeRough, 0.01);
+ properties.u_scleraRoughness = Math.max(eyeRough, 0.1);
+ properties.u_specular = material.specular ?? 1;
+ }
}
/** `<stem>_m<source material index>` — the product a material becomes. */
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index b86d7030f..74b5a562a 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -74,6 +74,12 @@ export const NOTED = {
{"note":"Lit materials keep the light a rough surface reflects and pass on what it does not. The environment's specular came from Karis' analytic fit, 21% low for a metal at roughness 0.5 and up to 80% off at a grazing view; it is now a fit to the integral itself (tools/gen-dfg-fit.py, worst 3%). The light a rough metal loses to bounces between its microfacets is returned (Fdez-Aguera's multiple-scattering term, and the same ratio on a lamp's highlight), where a metal at roughness 0.9 under a white sky came out at half of Blender's brightness. The diffuse under a dielectric's specular is reduced by what the specular reflects, as in the Principled shader. And a lamp's highlight takes Smith's height-correlated masking at alpha = roughness squared in place of the Schlick k = (r + 1)^2 / 8 remap, which left a rough metal's rim a quarter dark. In the render lab six spheres under a white sky now match Blender within 0.5% at every roughness, and flat cards of five albedos within 0.002, on both backends. A sun with a size casts a penumbra as wide as Blender's. The disc a penumbra was averaged over stopped at 8 texels of the map, which held a sun's soft edge to sixteen texels: with a fine cascade that is less than the sun throws, and the render lab measured an edge 60% as wide as Blender's. The disc now reaches 24 texels, its spiral of taps is turned point by point so the wider disc grains rather than bands, and each blocker tap forgives only as far as it stands from the point, so a box standing on a floor stays shadowed to its foot."},
'feat(character): hair takes the Principled highlight when it has an anisotropy, and an imported card with one is set to it':
{"note":"The Hair shader takes the Principled shader's highlight when u_anisotropy is above zero: GGX stretched along the strand as Blender stretches it, with u_specular as the specular factor. A hair card imported with an anisotropy (KHR_materials_anisotropy, which Blender exports from its Principled anisotropy) is set to it, so the broad sheen across a fringe that Blender draws is drawn in the same place."},
+ 'fix(pipeline): a cut-out chain holds the share its cut keeps, and a cut-out takes its colour into its clear texels':
+ {"note":"A cut-out's mip chain holds, as alpha, the share of texels its cut keeps, and its colour is the colour of what the cut keeps. The minified alpha is what a cut-out is drawn with, and a plain average of a soft mask (a painted band of eyelashes fading out) averaged to more than the cut keeps: the probe's lash card drew a pink veil over the iris where Blender draws a few lashes. The chain no longer rescales alpha to keep a cutoff's coverage, and an imported cut-out's clear texels take the colour of the solid ones nearest them, so even a mip the GPU makes does not average in what the painter left under alpha 0."},
+ 'fix(render): a cut-out shadow keeps the share of light it lets through, the same on both backends':
+ {"note":"A cut-out's shadow keeps the share of light it lets through, and is the same shape on both backends. The shadow pass read a card's alpha at level 0 on WebGPU (mips on WebGL2), and cut at the cutoff on both; where the card is smaller than a texel from the light it now cuts against a per-texel threshold through the mip chain, so a fringe of hair throws a shadow as deep as it is dense."},
+ 'fix(pipeline): an imported eye shades as the Principled shader it was authored against':
+ {"note":"An imported eye shades as the Principled shader it was authored against: the Eye shader's tinted white, its warm wrap of light past the terminator (which reddened a painted iris) and its lid darkening are written as off, and both its glossy layers take the source's roughness instead of a near-mirror cornea."},
'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.' },