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(render): Skin and Hair shaders, and normal maps keep their shape on stretched UVs

yhh0280ab274048
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ecc68de97..01d267d9c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,8 @@ published separately; it ships inside the editor.
### Added
- **Contact shadows and screen-space bounce light.** Contact Shadows and Screen Space GI effects add small sharp shadows at contacts and one bounce of colour between surfaces, and the weather softens the sun's shadows. `contactShadows` marches a short ray toward the scene's sun in the depth buffer; `ssgi` gathers eight rays a pixel over the G-buffer's normals at half size into a float target and averages the neighbours on the same surface before laying the light, times the receiver's colour, over the picture. The Weather component raises the sun's `sourceAngle` and lowers its `shadowStrength` as the sky clouds over.
+- **Skin and hair.** Two new shaders for characters: Skin softens diffuse light by colour, warms the terminator and lets light through thin places without blurring the picture, and Hair lights strands along a flow map with two shifted highlights. Normal maps on stretched UVs (a face unwrapped into an atlas) now keep their shape. Both read a normal map and an occlusion/roughness map as data textures (import them with sRGB off); the Skin shader shades each pixel with three lighting passes, so it is for characters in view. Hair is shaded as strands but a hair model is still cards or ribbons.
+- **Anisotropic filtering.** Mipmapped textures are now sampled with up to 16x anisotropic filtering where the device has it (WebGL2 with the extension, WebGPU always), so a floor, a hair card or a sleeve seen at a slant keeps its detail instead of washing out to grey.
- **Wilds example.** Wilds is a new 3D example: a lake under mountains at dusk, made from a generated heightmap with the Terrain, Water and Foliage features and the sky's cloud shadows. Everything in it is made from numbers by `examples/wilds/tools/build.mjs`, so there is no art to credit.
- **Foliage.** A Foliage component scatters grass or a mesh across an area and over a Terrain, swaying in the wind and thinning out with distance. Each cell of the area is one mesh with all its plants in it, built twice (near, and a far version: fewer broader blades, or two crossed cards a mesh), so a field is a few hundred draws. The **Foliage** shader bends vertices by weights painted in the vertex colour, which a vertex hook of your own can read as `es_vertexColor`. Plants do not collide and do not bend away from a character.
- **Terrain.** A Terrain component makes ground from a heightmap or noise, paints it with grass, dirt, snow and rock layers, and draws it in chunks that coarsen with distance. Add a `Terrain` component to an entity: its heightmap (or a seed, for noise) sets the shape, and each chunk is built at up to four levels of detail with a skirt that hides the cracks between levels, so the engine's level-of-detail choice needs no knowledge of its neighbours. A **Terrain** material shader draws four texture layers by world position, with the rock projected from three sides. `TerrainsRes.heightAt(x, z)` answers how high the ground is. The ground is drawn, not simulated: it has no collider, and no holes or overhangs.
diff --git a/desktop b/desktop
index e5a0834e2..895c4cfd8 160000
--- a/desktop
+++ b/desktop
@@ -1 +1 @@
-Subproject commit e5a0834e23d5d38ec49d99dc8b0ef07dad9c1abf
+Subproject commit 895c4cfd87d69214336c7f86987c66769b944241
diff --git a/docs/astro/src/content/docs/graphics/materials.mdx b/docs/astro/src/content/docs/graphics/materials.mdx
index 7050033fd..be131a07e 100644
--- a/docs/astro/src/content/docs/graphics/materials.mdx
+++ b/docs/astro/src/content/docs/graphics/materials.mdx
@@ -36,6 +36,8 @@ creates a material from a built-in template — the same list ships in code as
| **Terrain** | `terrain` | Four texture layers (grass, dirt, snow, rock) weighted by the [Terrain](/docs/graphics/terrain/) component and tiled by world position. |
| **Foliage** | `foliage` | Plants that sway in the wind: a vertex bend by weights painted in the vertex colour, two-sided and translucent, with an optional cutout texture. See [Foliage](/docs/graphics/foliage/). |
+| **Skin** | `skin` | Soft diffuse by colour, a warm terminator, light through thin places, two shine lobes and a fuzz — without blurring the picture. See [Skin and hair](#skin-and-hair). |
+| **Hair** | `hair` | Strand lighting: Kajiya-Kay diffuse, two shifted highlights along a flow map, and light through the strands. See [Skin and hair](#skin-and-hair). |
| **Water** | `water` | A horizontal body of water: travelling waves and ripples, the scene behind it bent and tinted by how deep the water is, reflections, and foam. See [Water](#water). |
A new material **references** its template by id — it stores `shader: "builtin:sprite-unlit"`
@@ -63,6 +65,29 @@ Parameters are in world units: a scene in metres wants the defaults, one in cent
- The surface is taken to lie flat: a water plane that is tilted or curved will shade as if it were level.
- The waves do not move the geometry, so a wave does not break the shoreline or lift a floating object, and the silhouette against the sky is a straight line.
+## Skin and hair
+
+Two shaders for the parts of a character a metal/rough pair does not describe. Both take the base colour from the mesh's own texture, as
+the Model shader does, and take `u_normalMap` and an `u_ormMap` (occlusion in red, roughness in green) as **data** textures: import them
+with sRGB **off**, or the normal map is bent by the colour curve and the surface comes out blotched.
+
+**Skin** (`builtin:skin`) does not blur the picture. Light that goes into skin and comes out a little way off softens the lit side of a
+curve, and it does that here per colour: the diffuse light is taken from a softer normal than the surface's own, softest for red
+(`u_blurRed`, `u_blurGreen`, mip levels of the normal map), so the pores and the highlight stay sharp. The terminator is warmed (`u_sssColor`, `u_sssWrap`),
+a thin or strongly curved place lets light through (`u_translucency`, `u_thinness`: an ear, a nostril, a finger), the shine is two
+lobes (`u_specular`, `u_lobe2`, `u_lobe2Roughness`) and a faint fuzz lights the rim (`u_fuzz`). Turn `u_subsurface` on to also mark it for the
+[Subsurface Scattering](/docs/graphics/post-processing/#subsurface-scattering) effect, which spreads what is left on a larger scale at the cost of
+blurring the picture. It shades each pixel with three lighting passes, so it is for the skin of a character in view, not for a crowd.
+
+**Hair** (`builtin:hair`) lights a strand as a strand. `u_flowMap` says which way the strands run (red and green are a direction across the
+texture), the diffuse light is Kajiya-Kay (a strand is lit by how far the light is from along it), and the shine is two narrow
+highlights along the strand, shifted against each other by `u_shiftMap` (`u_shiftAmount`, `u_shiftTile`): a white one near the surface and a coloured
+one under it (`u_secondaryTint`). `u_roughness` sets how tight the lines are. Light comes through the strands from behind (`u_translucency`),
+`u_sharpen` keeps the fine strands a card is covered in from washing out at a slant, and `u_rootDark` darkens the roots by the occlusion map.
+A hair model is usually cards or ribbons, not strands; this shader gives the shading of a strand to what the geometry gives it.
+
+Both read the same lighting core as every Lit shader, so shadows, image-based light and the other effects apply.
+
## Shading layers
The **Model** shader is a metal/rough surface with layers on top. Each is off at its default, a layer at zero costs the surface nothing, and a material that says none of them is the plain surface it always was.
diff --git a/docs/astro/src/content/docs/zh-cn/graphics/materials.mdx b/docs/astro/src/content/docs/zh-cn/graphics/materials.mdx
index 8a1de2e64..0b1688a0c 100644
--- a/docs/astro/src/content/docs/zh-cn/graphics/materials.mdx
+++ b/docs/astro/src/content/docs/zh-cn/graphics/materials.mdx
@@ -32,6 +32,8 @@ std140 uniform 块,于是 CPU 能按名字设置、并安全地送到 GPU。一
| **Terrain** | `terrain` | 四个纹理图层(草、泥土、雪、岩石),由 [Terrain](/docs/zh-cn/graphics/terrain/) 组件加权并按世界位置平铺。 |
| **Foliage** | `foliage` | 在风里摆动的植物:按顶点颜色里画好的权重做顶点弯曲,双面、半透光,可选镂空纹理。见[植被](/docs/zh-cn/graphics/foliage/)。 |
+| **Skin** | `skin` | 按颜色分开的柔和漫反射、偏暖的明暗交界、薄处透光、两层高光和一层绒毛光,不模糊画面。见[皮肤与头发](#皮肤与头发)。 |
+| **Hair** | `hair` | 发丝光照:Kajiya-Kay 漫反射、沿流向图错开的两条高光,以及透过发丝的光。见[皮肤与头发](#皮肤与头发)。 |
| **Water** | `water` | 水平的水体:传播的波浪和涟漪、被折射并按水深染色的背后场景、反射与泡沫。见[水](#水)。 |
新建材质是**按 id 引用**其模板的——它存的是 `shader: "builtin:sprite-unlit"`,并**不会**在磁盘上
@@ -57,6 +59,16 @@ std140 uniform 块,于是 CPU 能按名字设置、并安全地送到 GPU。一
- 表面被当作是平的:倾斜或弯曲的水面会按水平来着色。
- 波浪不移动几何体,所以波不会冲破海岸线,也不会托起漂浮的物体,和天空交界的轮廓是一条直线。
+## 皮肤与头发
+
+两个着色器,给金属/粗糙度这一对参数描述不了的角色部位用。它们都和 Model 着色器一样,从网格自己的纹理取基础颜色,并把 `u_normalMap` 和 `u_ormMap`(红色是遮蔽,绿色是粗糙度)当作**数据**纹理:导入时要把 sRGB **关掉**,否则法线贴图会被颜色曲线扭曲,表面会出现斑块。
+
+**皮肤**(`builtin:skin`)不模糊画面。光进入皮肤又在不远处出来,会让弯曲表面的受光一侧变软,这里按颜色分开做:漫反射光取自比表面自己的法线更软的法线,红色最软(`u_blurRed`、`u_blurGreen`,是法线贴图的 mip 层级),所以毛孔和高光保持清晰。明暗交界线被染暖(`u_sssColor`、`u_sssWrap`),薄的或曲率大的地方会透光(`u_translucency`、`u_thinness`:耳朵、鼻翼、手指),高光是两层(`u_specular`、`u_lobe2`、`u_lobe2Roughness`),另有一层很淡的绒毛光照亮边缘(`u_fuzz`)。打开 `u_subsurface` 还会把它标记给[次表面散射](/docs/zh-cn/graphics/post-processing/#次表面散射)特效,在更大的尺度上扩散剩下的光,代价是会模糊画面。它对每个像素做三次光照计算,所以适合镜头里的角色皮肤,不适合一群人。
+
+**头发**(`builtin:hair`)把发丝当发丝来打光。`u_flowMap` 说明发丝朝哪个方向(红、绿是贴图上的一个方向),漫反射是 Kajiya-Kay(发丝被光照亮的程度取决于光离它的走向有多远),高光是两条沿发丝的窄高光,由 `u_shiftMap` 把它们错开(`u_shiftAmount`、`u_shiftTile`):一条白的靠近表面,一条带颜色的在下面(`u_secondaryTint`)。`u_roughness` 决定线条有多紧。光会从发丝背面透过来(`u_translucency`),`u_sharpen` 让发片上密布的细发丝在斜着看时不被冲淡,`u_rootDark` 按遮蔽图把发根压暗。头发模型通常是发片或发带而不是真正的发丝;这个着色器把发丝的明暗给了几何本身给不了的部分。
+
+两者读的是和所有 Lit 着色器相同的光照核心,所以阴影、基于图像的光照和其他特效都适用。
+
## 着色层
**Model** shader 是一个金属/粗糙度表面,上面可以叠层。每一层默认关闭,强度为零的层不消耗任何开销,一个什么都不写的材质就是它一直以来的那个普通表面。
diff --git a/sdk/src/render/builtinShaders.ts b/sdk/src/render/builtinShaders.ts
index 87e000b3b..cb43545b8 100644
--- a/sdk/src/render/builtinShaders.ts
+++ b/sdk/src/render/builtinShaders.ts
@@ -1365,6 +1365,353 @@ fn packNormal(n : vec3f) -> vec2f {
#pragma end
`;
+// Hair: lit as strands. The flow map gives the strand direction; the lighting does Kajiya-Kay diffuse and two shifted highlights along it
+// (misc.y above zero is the switch). Two-sided and translucent; the base colour is the mesh's own texture, as in the Model shader.
+const HAIR = `#pragma shader "Hair"
+#pragma version 300 es
+#pragma domain Lit
+#pragma param u_tint color default(1,1,1,1)
+#pragma param u_normalMap texture default(flatnormal) texel(data)
+#pragma param u_ormMap texture default(white) texel(data)
+#pragma param u_occlusionStrength float default(1) range(0,1) ui(slider)
+// Which way each strand runs: red and green are a direction across the texture, the way an authored flow map writes it.
+#pragma param u_flowMap texture default(white) texel(data)
+// A texture that shifts the highlight along the strand from one place to the next, and how far, and how often it repeats.
+#pragma param u_shiftMap texture default(white) texel(data)
+#pragma param u_shiftAmount float default(0.35) range(0,1) ui(slider)
+#pragma param u_shiftTile float default(6) range(0.1,64) ui(slider)
+// How tightly each highlight is drawn (roughness: lower is a narrower line), how strong they are, and how far each rides off the strand's
+// centre line. The second is the coloured one, tinted by u_secondaryTint.
+#pragma param u_roughness float default(0.3) range(0.05,1) ui(slider)
+#pragma param u_specular float default(1) range(0,2) ui(slider)
+#pragma param u_shiftPrimary float default(-0.1) range(-1,1) ui(slider)
+#pragma param u_shiftSecondary float default(0.2) range(-1,1) ui(slider)
+#pragma param u_secondaryTint color default(0.75,0.45,0.25,1)
+// Light that comes through the strands from behind.
+#pragma param u_translucency float default(0.4) range(0,1) ui(slider)
+// A negative bias on the colour's mip level keeps the fine strands a hair card is covered in from washing out at a slant, which they do at once.
+#pragma param u_sharpen float default(-0.8) range(-3,1) ui(slider)
+// How much darker the roots are than the tips: the occlusion map's red, pushed.
+#pragma param u_rootDark float default(0.5) range(0,1) ui(slider)
+
+#pragma fragment
+precision highp float;
+
+in vec4 v_color;
+in vec2 v_texCoord;
+in highp vec2 v_worldPos;
+#ifdef MESH_NORMALS
+in highp vec3 v_worldNormal;
+in highp vec3 v_worldXYZ;
+#endif
+uniform sampler2D u_textures[1];
+
+#ifdef ES_GBUFFER
+layout(location = 0) out vec4 fragColor;
+layout(location = 1) out vec4 fragSurface;
+
+vec2 packNormal(vec3 n) {
+ n /= (abs(n.x) + abs(n.y) + abs(n.z));
+ vec2 sgn = vec2(n.x >= 0.0 ? 1.0 : -1.0, n.y >= 0.0 ? 1.0 : -1.0);
+ vec2 e = n.z >= 0.0 ? n.xy : (1.0 - abs(n.yx)) * sgn;
+ return e * 0.5 + 0.5;
+}
+#else
+out vec4 fragColor;
+#endif
+
+void main() {
+#ifdef MESH_NORMALS
+ highp vec3 Ng = normalize(v_worldNormal);
+ highp vec3 P = v_worldXYZ;
+ highp vec3 N = perturbNormal(Ng, P, v_texCoord, sampleNormal(u_normalMap, v_texCoord));
+ if (!gl_FrontFacing) { N = -N; Ng = -Ng; }
+ // The strand: the flow map's direction across the texture, put onto the surface and made to lie across the normal.
+ vec2 flow = texture(u_flowMap, v_texCoord).rg * 2.0 - 1.0;
+ highp vec3 T = perturbNormal(Ng, P, v_texCoord, vec3(flow, 0.0));
+ T -= N * dot(N, T);
+ if (dot(T, T) < 1e-6) T = cross(N, abs(N.y) < 0.99 ? vec3(0.0, 1.0, 0.0) : vec3(1.0, 0.0, 0.0));
+ T = normalize(T);
+#else
+ highp vec3 P = vec3(v_worldPos, 0.0);
+ highp vec3 N = vec3(0.0, 0.0, 1.0);
+ highp vec3 T = vec3(0.0, 1.0, 0.0);
+#endif
+ vec4 base = texture(u_textures[0], v_texCoord, u_sharpen) * v_color * u_tint;
+ float root = texture(u_ormMap, v_texCoord).r;
+ float ao = mix(1.0, root, u_occlusionStrength);
+ base.rgb *= mix(1.0, 0.35 + 0.65 * root, u_rootDark);
+ float noise = (texture(u_shiftMap, v_texCoord * u_shiftTile).r - 0.5) * u_shiftAmount;
+ SurfaceExt ext = surfaceExtNone(N);
+ ext.aniso = vec4(T, 0.0);
+ ext.misc = vec4(0.046, 1.0, u_shiftPrimary + noise, u_shiftSecondary + noise);
+ ext.scatter = vec4(base.rgb * u_secondaryTint.rgb * 1.6, 0.35);
+ ext.trans = vec4(u_translucency, 0.25, 0.0, 0.0);
+ vec3 viewDir = viewDirection(P);
+ vec3 lit = applyLightingSurface(base.rgb, N, P, viewDir, 0.0, u_roughness, u_specular, ao, ext);
+ fragColor = vec4(lit, 1.0);
+#ifdef ES_GBUFFER
+ fragSurface = vec4(packNormal(normalize(N)), u_roughness, 0.75);
+#endif
+}
+#pragma end
+
+#pragma fragment wgsl
+#ifdef ES_GBUFFER
+struct FragOut {
+ @location(0) color : vec4f,
+ @location(1) surface : vec4f,
+};
+
+fn packNormal(n : vec3f) -> vec2f {
+ let a = n / (abs(n.x) + abs(n.y) + abs(n.z));
+ let sgn = vec2f(select(-1.0, 1.0, a.x >= 0.0), select(-1.0, 1.0, a.y >= 0.0));
+ var e = a.xy;
+ if (a.z < 0.0) { e = (vec2f(1.0) - abs(a.yx)) * sgn; }
+ return e * 0.5 + 0.5;
+}
+
+@fragment fn fs_main(v : VSOut, @builtin(front_facing) front : bool) -> FragOut {
+#else
+@fragment fn fs_main(v : VSOut, @builtin(front_facing) front : bool) -> @location(0) vec4f {
+#endif
+ let duvx = dpdx(v.v_texCoord);
+ let duvy = dpdy(v.v_texCoord);
+ g_probeSlot = v.v_probeSlot;
+#ifdef MESH_LIGHTMAP
+ g_lightmap = v.v_lightmap;
+#endif
+ var base = textureSampleBias(t0, s0, v.v_texCoord, mc.u_sharpen) * v.v_color * mc.u_tint;
+ let flowTex = textureSampleGrad(u_flowMap, u_flowMap_s, v.v_texCoord, duvx, duvy).rg * 2.0 - vec2f(1.0);
+ let orm = textureSampleGrad(u_ormMap, u_ormMap_s, v.v_texCoord, duvx, duvy);
+ let shiftTex = textureSampleGrad(u_shiftMap, u_shiftMap_s, v.v_texCoord * mc.u_shiftTile, duvx * mc.u_shiftTile, duvy * mc.u_shiftTile).r;
+#ifdef MESH_NORMALS
+ var Ng = normalize(v.v_worldNormal);
+ let P = v.v_worldXYZ;
+ var N = perturbNormal(Ng, P, v.v_texCoord, sampleNormalGrad(u_normalMap, u_normalMap_s, v.v_texCoord, duvx, duvy));
+ if (!front) { N = -N; Ng = -Ng; }
+ var T = perturbNormal(Ng, P, v.v_texCoord, vec3f(flowTex, 0.0));
+ T = T - N * dot(N, T);
+ if (dot(T, T) < 1e-6) {
+ var seed = vec3f(1.0, 0.0, 0.0);
+ if (abs(N.y) < 0.99) { seed = vec3f(0.0, 1.0, 0.0); }
+ T = cross(N, seed);
+ }
+ T = normalize(T);
+#else
+ let P = vec3f(v.v_worldPos.x, 0.0, v.v_worldPos.y);
+ let N = vec3f(0.0, 0.0, 1.0);
+ let T = vec3f(0.0, 1.0, 0.0);
+#endif
+ let ao = mix(1.0, orm.r, mc.u_occlusionStrength);
+ base = vec4f(base.rgb * mix(1.0, 0.35 + 0.65 * orm.r, mc.u_rootDark), base.a);
+ let noise = (shiftTex - 0.5) * mc.u_shiftAmount;
+ var ext = surfaceExtNone(N);
+ ext.aniso = vec4f(T, 0.0);
+ ext.misc = vec4f(0.046, 1.0, mc.u_shiftPrimary + noise, mc.u_shiftSecondary + noise);
+ ext.scatter = vec4f(base.rgb * mc.u_secondaryTint.rgb * 1.6, 0.35);
+ ext.trans = vec4f(mc.u_translucency, 0.25, 0.0, 0.0);
+ let viewDir = viewDirection(P);
+ let lit = applyLightingSurface(base.rgb, N, P, viewDir, 0.0, mc.u_roughness, mc.u_specular, ao, ext);
+#ifdef ES_GBUFFER
+ var frag : FragOut;
+ frag.color = vec4f(lit, 1.0);
+ frag.surface = vec4f(packNormal(normalize(N)), mc.u_roughness, 0.75);
+ return frag;
+#else
+ return vec4f(lit, 1.0);
+#endif
+}
+#pragma end
+`;
+
+// Skin: scattering without blurring the picture. Diffuse light comes from a softer normal than the surface's own (softest for red), the
+// terminator is warmed, thin curved places let light through, and the shine is two lobes and a fuzz. Base colour is the mesh's texture.
+const SKIN = `#pragma shader "Skin"
+#pragma version 300 es
+#pragma domain Lit
+#pragma param u_tint color default(1,1,1,1)
+#pragma param u_normalMap texture default(flatnormal) texel(data)
+#pragma param u_ormMap texture default(white) texel(data)
+#pragma param u_occlusionStrength float default(1) range(0,1) ui(slider)
+// How rough the surface is (a scale on the map's own roughness), how much it shines, and the second, tighter lobe.
+#pragma param u_roughness float default(1) range(0,2) ui(slider)
+#pragma param u_specular float default(1) range(0,2) ui(slider)
+#pragma param u_lobe2 float default(0.18) range(0,1) ui(slider)
+#pragma param u_lobe2Roughness float default(0.4) range(0.05,1) ui(slider)
+// How much softer than the surface's own normal the diffuse light's normal is: for red, then for green and blue (mip levels of the normal map).
+#pragma param u_blurRed float default(3.2) range(0,8) ui(slider)
+#pragma param u_blurGreen float default(1.6) range(0,8) ui(slider)
+// The colour the terminator takes and how far light wraps past it.
+#pragma param u_sssColor color default(0.95,0.4,0.3,1)
+#pragma param u_sssWrap float default(0.45) range(0,1) ui(slider)
+// Light through thin places: how much, and how much of a surface's curvature counts as thin.
+#pragma param u_translucency float default(0.5) range(0,1) ui(slider)
+#pragma param u_thinness float default(0.5) range(0,1) ui(slider)
+// The fine fuzz that lights a rim.
+#pragma param u_fuzz float default(0.1) range(0,1) ui(slider)
+// Marks the surface for the Subsurface Scattering effect, which spreads what is left of the light on a larger scale. Off by default.
+#pragma param u_subsurface float default(0) range(0,1) ui(slider)
+
+#pragma fragment
+precision highp float;
+
+in vec4 v_color;
+in vec2 v_texCoord;
+in highp vec2 v_worldPos;
+#ifdef MESH_NORMALS
+in highp vec3 v_worldNormal;
+in highp vec3 v_worldXYZ;
+#endif
+uniform sampler2D u_textures[1];
+
+#ifdef ES_GBUFFER
+layout(location = 0) out vec4 fragColor;
+layout(location = 1) out vec4 fragSurface;
+
+vec2 packNormal(vec3 n) {
+ n /= (abs(n.x) + abs(n.y) + abs(n.z));
+ vec2 sgn = vec2(n.x >= 0.0 ? 1.0 : -1.0, n.y >= 0.0 ? 1.0 : -1.0);
+ vec2 e = n.z >= 0.0 ? n.xy : (1.0 - abs(n.yx)) * sgn;
+ return e * 0.5 + 0.5;
+}
+#else
+out vec4 fragColor;
+#endif
+
+vec3 skinNormalAt(float bias) {
+ return normalize(texture(u_normalMap, v_texCoord, bias).xyz * 2.0 - 1.0);
+}
+
+void main() {
+#ifdef MESH_NORMALS
+ highp vec3 Ng = normalize(v_worldNormal);
+ highp vec3 P = v_worldXYZ;
+ if (!gl_FrontFacing) Ng = -Ng;
+ highp vec3 N = perturbNormal(Ng, P, v_texCoord, skinNormalAt(0.0));
+ highp vec3 Nmid = perturbNormal(Ng, P, v_texCoord, skinNormalAt(u_blurGreen));
+ highp vec3 Nsoft = perturbNormal(Ng, P, v_texCoord, skinNormalAt(u_blurRed));
+ // How fast the surface turns across a pixel, against how big a pixel is: the thin, strongly curved places.
+ float turn = (length(dFdx(Ng)) + length(dFdy(Ng))) / max(length(dFdx(P)) + length(dFdy(P)), 1e-5);
+ float thick = 1.0 - clamp(turn * 12.0 * u_thinness, 0.0, 1.0);
+#else
+ highp vec3 P = vec3(v_worldPos, 0.0);
+ highp vec3 N = vec3(0.0, 0.0, 1.0);
+ highp vec3 Nmid = N;
+ highp vec3 Nsoft = N;
+ float thick = 1.0;
+#endif
+ vec4 base = texture(u_textures[0], v_texCoord) * v_color * u_tint;
+ vec4 orm = texture(u_ormMap, v_texCoord);
+ float ao = mix(1.0, orm.r, u_occlusionStrength);
+ float rough = clamp(orm.g * u_roughness, 0.05, 1.0);
+ vec3 viewDir = viewDirection(P);
+
+ // The diffuse light, from two softnesses of normal, with the terminator warmed and light let through a thin place.
+ SurfaceExt wrapped = surfaceExtNone(Nsoft);
+ wrapped.scatter = vec4(u_sssColor.rgb * base.rgb * 1.4, u_sssWrap);
+ wrapped.trans = vec4(u_translucency, thick, 0.0, 0.0);
+ vec3 soft = applyLightingSurface(base.rgb, Nsoft, P, viewDir, 0.0, 1.0, 0.0, ao, wrapped);
+ SurfaceExt wrappedMid = surfaceExtNone(Nmid);
+ wrappedMid.scatter = wrapped.scatter;
+ wrappedMid.trans = wrapped.trans;
+ vec3 mid = applyLightingSurface(base.rgb, Nmid, P, viewDir, 0.0, 1.0, 0.0, ao, wrappedMid);
+ vec3 diffuse = vec3(soft.r, mid.g, mid.b);
+
+ // The shine: two lobes and a fuzz, on the surface's own normal, with no diffuse under it.
+ SurfaceExt shine = surfaceExtNone(N);
+ shine.coat = vec4(u_lobe2, u_lobe2Roughness, 0.0, 0.0);
+ shine.coatN = vec4(N, 0.0);
+ shine.sheen = vec4(vec3(u_fuzz), 0.5);
+ vec3 spec = applyLightingSurface(vec3(0.0), N, P, viewDir, 0.0, rough, u_specular, ao, shine);
+
+ float alpha = u_subsurface > 0.0 ? 0.996 : 1.0;
+ fragColor = vec4(diffuse + spec, alpha);
+#ifdef ES_GBUFFER
+ fragSurface = vec4(packNormal(normalize(N)), rough, 0.75);
+#endif
+}
+#pragma end
+
+#pragma fragment wgsl
+#ifdef ES_GBUFFER
+struct FragOut {
+ @location(0) color : vec4f,
+ @location(1) surface : vec4f,
+};
+
+fn packNormal(n : vec3f) -> vec2f {
+ let a = n / (abs(n.x) + abs(n.y) + abs(n.z));
+ let sgn = vec2f(select(-1.0, 1.0, a.x >= 0.0), select(-1.0, 1.0, a.y >= 0.0));
+ var e = a.xy;
+ if (a.z < 0.0) { e = (vec2f(1.0) - abs(a.yx)) * sgn; }
+ return e * 0.5 + 0.5;
+}
+
+@fragment fn fs_main(v : VSOut, @builtin(front_facing) front : bool) -> FragOut {
+#else
+@fragment fn fs_main(v : VSOut, @builtin(front_facing) front : bool) -> @location(0) vec4f {
+#endif
+ // Every sample is taken here, before any branch.
+ g_probeSlot = v.v_probeSlot;
+#ifdef MESH_LIGHTMAP
+ g_lightmap = v.v_lightmap;
+#endif
+ let base = textureSample(t0, s0, v.v_texCoord) * v.v_color * mc.u_tint;
+ let orm = textureSample(u_ormMap, u_ormMap_s, v.v_texCoord);
+ let tangentSharp = normalize(textureSampleBias(u_normalMap, u_normalMap_s, v.v_texCoord, 0.0).xyz * 2.0 - vec3f(1.0));
+ let tangentMid = normalize(textureSampleBias(u_normalMap, u_normalMap_s, v.v_texCoord, mc.u_blurGreen).xyz * 2.0 - vec3f(1.0));
+ let tangentSoft = normalize(textureSampleBias(u_normalMap, u_normalMap_s, v.v_texCoord, mc.u_blurRed).xyz * 2.0 - vec3f(1.0));
+#ifdef MESH_NORMALS
+ var Ng = normalize(v.v_worldNormal);
+ let P = v.v_worldXYZ;
+ if (!front) { Ng = -Ng; }
+ let N = perturbNormal(Ng, P, v.v_texCoord, tangentSharp);
+ let Nmid = perturbNormal(Ng, P, v.v_texCoord, tangentMid);
+ let Nsoft = perturbNormal(Ng, P, v.v_texCoord, tangentSoft);
+ let turn = (length(dpdx(Ng)) + length(dpdy(Ng))) / max(length(dpdx(P)) + length(dpdy(P)), 1e-5);
+ let thick = 1.0 - clamp(turn * 12.0 * mc.u_thinness, 0.0, 1.0);
+#else
+ let P = vec3f(v.v_worldPos.x, 0.0, v.v_worldPos.y);
+ let N = vec3f(0.0, 0.0, 1.0);
+ let Nmid = N;
+ let Nsoft = N;
+ let thick = 1.0;
+#endif
+ let ao = mix(1.0, orm.r, mc.u_occlusionStrength);
+ let rough = clamp(orm.g * mc.u_roughness, 0.05, 1.0);
+ let viewDir = viewDirection(P);
+
+ var wrapped = surfaceExtNone(Nsoft);
+ wrapped.scatter = vec4f(mc.u_sssColor.rgb * base.rgb * 1.4, mc.u_sssWrap);
+ wrapped.trans = vec4f(mc.u_translucency, thick, 0.0, 0.0);
+ let soft = applyLightingSurface(base.rgb, Nsoft, P, viewDir, 0.0, 1.0, 0.0, ao, wrapped);
+ var wrappedMid = surfaceExtNone(Nmid);
+ wrappedMid.scatter = wrapped.scatter;
+ wrappedMid.trans = wrapped.trans;
+ let mid = applyLightingSurface(base.rgb, Nmid, P, viewDir, 0.0, 1.0, 0.0, ao, wrappedMid);
+ let diffuse = vec3f(soft.r, mid.g, mid.b);
+
+ var shine = surfaceExtNone(N);
+ shine.coat = vec4f(mc.u_lobe2, mc.u_lobe2Roughness, 0.0, 0.0);
+ shine.coatN = vec4f(N, 0.0);
+ shine.sheen = vec4f(vec3f(mc.u_fuzz), 0.5);
+ let spec = applyLightingSurface(vec3f(0.0), N, P, viewDir, 0.0, rough, mc.u_specular, ao, shine);
+
+ var alpha = 1.0;
+ if (mc.u_subsurface > 0.0) { alpha = 0.996; }
+#ifdef ES_GBUFFER
+ var frag : FragOut;
+ frag.color = vec4f(diffuse + spec, alpha);
+ frag.surface = vec4f(packNormal(normalize(N)), rough, 0.75);
+ return frag;
+#else
+ return vec4f(diffuse + spec, alpha);
+#endif
+}
+#pragma end
+`;
+
export const BUILTIN_SHADER_TEMPLATES: readonly BuiltinShaderTemplate[] = [
template('sprite-unlit', 'Unlit', 'Texture × vertex color × tint, no lighting.', SPRITE_UNLIT),
template('sprite-lit', 'Lit', 'Lit by the scene\'s 2D lights; optional normal map.', SPRITE_LIT),
@@ -1386,6 +1733,10 @@ export const BUILTIN_SHADER_TEMPLATES: readonly BuiltinShaderTemplate[] = [
'Four texture layers (grass, dirt, snow, rock) weighted by the Terrain component, tiled by world position.', TERRAIN),
template('foliage', 'Foliage',
'Plants that sway in the wind: a vertex bend by painted weights, two-sided and translucent, with an optional cutout texture.', FOLIAGE),
+ template('hair', 'Hair',
+ 'Strand lighting: Kajiya-Kay diffuse, two shifted highlights along a flow map, and light through the strands.', HAIR),
+ template('skin', 'Skin',
+ 'Soft diffuse by colour, a warm terminator, light through thin places, two shine lobes and a fuzz — without blurring the picture.', SKIN),
];
export function builtinShaderTemplate(id: string): BuiltinShaderTemplate | undefined {
diff --git a/src/esengine/renderer/rhi/GLDevice.cpp b/src/esengine/renderer/rhi/GLDevice.cpp
index d5c00e65e..40b0abcf6 100644
--- a/src/esengine/renderer/rhi/GLDevice.cpp
+++ b/src/esengine/renderer/rhi/GLDevice.cpp
@@ -237,6 +237,25 @@ bool glExtensionPresent(const char* name) {
return false;
}
+/**
+ * How far the bound texture is sharpened where it is seen at a slant. A mipmapped texture is averaged to the footprint's longer side, so a
+ * floor, a hair card or a sleeve seen edge-on washes out; with this the sampler takes extra samples along the long side instead.
+ * WebGL2 has it as an extension and an extension may be absent, so it is asked once and left alone where it is not there.
+ */
+void setAnisotropy(const TextureDesc& desc, bool mipped) {
+ static const GLfloat kMax = [] {
+ constexpr GLenum kMaxAnisotropy = 0x84FF; // GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
+ if (!(glExtensionPresent("GL_EXT_texture_filter_anisotropic") || glExtensionPresent("EXT_texture_filter_anisotropic"))) return 1.0f;
+ GLfloat v = 1.0f;
+ glGetFloatv(kMaxAnisotropy, &v);
+ return v < 1.0f ? 1.0f : v;
+ }();
+ if (kMax <= 1.0f) return;
+ constexpr GLenum kTextureMaxAnisotropy = 0x84FE; // GL_TEXTURE_MAX_ANISOTROPY_EXT
+ const bool linear = desc.minFilter != TextureFilter::Nearest && desc.magFilter != TextureFilter::Nearest;
+ glTexParameterf(GL_TEXTURE_2D, kTextureMaxAnisotropy, (mipped && linear) ? (kMax < 16.0f ? kMax : 16.0f) : 1.0f);
+}
+
std::string readShaderInfoLog(GLuint shader) {
GLint logLength = 0;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &logLength);
@@ -1142,6 +1161,7 @@ bool GLDevice::backendCreateTexture(u32 id, const TextureDesc& desc, const void*
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, toGLFilter(desc.magFilter));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, toGLWrap(desc.wrapS));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, toGLWrap(desc.wrapT));
+ setAnisotropy(desc, desc.mipmaps);
if (desc.mipmaps && pixels) {
glGenerateMipmap(GL_TEXTURE_2D);
@@ -1182,6 +1202,7 @@ bool GLDevice::backendCreateCompressedTexture(u32 id, const TextureDesc& desc, G
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, toGLFilter(desc.magFilter));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, toGLWrap(desc.wrapS));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, toGLWrap(desc.wrapT));
+ setAnisotropy(desc, levels > 1);
return true;
}
@@ -1228,6 +1249,7 @@ void GLDevice::backendSetTextureParams(u32 id, const TextureDesc& desc) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, toGLFilter(desc.magFilter));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, toGLWrap(desc.wrapS));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, toGLWrap(desc.wrapT));
+ setAnisotropy(desc, desc.mipmaps);
}
void GLDevice::backendGenerateMipmaps(u32 id) {
diff --git a/src/esengine/renderer/webgpu/WebGPUDevice.cpp b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
index 99cce3119..8e945f4a7 100644
--- a/src/esengine/renderer/webgpu/WebGPUDevice.cpp
+++ b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
@@ -1398,7 +1398,9 @@ WGPUSampler WebGPUDevice::samplerFor(u8 key) {
sd.mipmapFilter = WGPUMipmapFilterMode_Linear;
sd.lodMinClamp = 0.0f;
sd.lodMaxClamp = 32.0f;
- sd.maxAnisotropy = 1;
+ // Sharpened at a slant (a floor, a hair card, a sleeve seen edge-on): the sampler takes extra samples along the footprint's long side.
+ // WebGPU allows it only when every filter is linear, so a nearest-filtered sampler stays at one.
+ sd.maxAnisotropy = (key & 3u) == 0u ? 16 : 1;
WGPUSampler sampler = wgpuDeviceCreateSampler(device_, &sd);
samplers_[key] = sampler;
return sampler;
diff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cpp
index 6920b3940..96e33b885 100644
--- a/src/esengine/resource/ShaderParser.cpp
+++ b/src/esengine/resource/ShaderParser.cpp
@@ -1400,8 +1400,9 @@ fn perturbNormal(N : vec3f, worldPos : vec3f, uv : vec2f, tangentNormal : vec3f)
let m = max(dot(T, T), dot(B, B));
let scale = max(dot(dp1, dp1), dot(dp2, dp2)) * max(dot(duv1, duv1), dot(duv2, duv2));
if (!(m > scale * 1e-6)) { return N; }
- let invmax = inverseSqrt(m);
- return normalize(mat3x3f(T * invmax, B * invmax, N) * tangentNormal);
+ // Each axis to unit length on its own: a texture stretched more along one axis than the other (a face unwrapped into an atlas) has
+ // a short T beside a long B, and scaling both by the longer one would leave the normal map flat along the short one.
+ return normalize(mat3x3f(T * inverseSqrt(max(dot(T, T), 1e-20)), B * inverseSqrt(max(dot(B, B), 1e-20)), N) * tangentNormal);
}
// Where a world point lands in this camera's part of a screen-space mask: on the Z = 0
// plane, which is the plane a 2D occluder hides things in, and through this same camera
@@ -1710,12 +1711,14 @@ fn applyLightingSurface(albedo : vec3f, N : vec3f, worldPos : vec3f, V : vec3f,
}
let ab = envBRDFApprox(NdotV, roughness);
var envR = reflect(-V, N);
- if (ext.aniso.w != 0.0) {
+ if (ext.aniso.w != 0.0 || ext.misc.y > 0.0) {
let T = ext.aniso.xyz;
var grain = T;
- if (ext.aniso.w >= 0.0) { grain = cross(N, T); }
+ if (ext.aniso.w >= 0.0 && ext.misc.y <= 0.0) { grain = cross(N, T); }
let bent = normalize(cross(cross(grain, V), grain));
- envR = reflect(-V, normalize(mix(N, bent, vec3f(abs(ext.aniso.w)))));
+ var bendBy = abs(ext.aniso.w);
+ if (ext.misc.y > 0.0) { bendBy = 0.55; }
+ envR = reflect(-V, normalize(mix(N, bent, vec3f(bendBy))));
}
var envF = F0 * ab.x + vec3f(ab.y);
if (ext.film.x > 0.0) { envF = filmFresnel(envF, NdotV, ext.film); }
@@ -1783,10 +1786,27 @@ fn shadeLight(pd : vec4f, col : vec4f, sp : vec4f, sh : vec4f, sm : vec4f, fo :
shadowFactor3D(worldPos, N, L, vec2f(sh.x, sm.z), i32(sm.x), i32(sm.y)),
fo.z);
}
- let ndotl = max(dot(N, L), 0.0);
+ var ndotl = max(dot(N, L), 0.0);
+ // Hair (misc.y above zero; aniso.xyz is the strand): Kajiya-Kay diffuse, which lights a strand by how far light is from along it.
+ if (ext.misc.y > 0.0) {
+ let along = dot(ext.aniso.xyz, L);
+ ndotl = mix(ndotl, sqrt(max(1.0 - along * along, 0.0)) * clamp(dot(N, L) * 0.5 + 0.65, 0.0, 1.0), 0.6);
+ }
let radiance = col.rgb * (col.a * ndotl * atten);
lit += radiance;
- if (specular > 0.0) {
+ if (specular > 0.0 && ext.misc.y > 0.0) {
+ // Two shifted, narrow lobes along the strand: a white one near the surface and a coloured one under it (scatter.rgb).
+ let H = normalize(L + V);
+ let primaryExp = clamp(2.0 / (a * a), 8.0, 900.0);
+ let strandA = normalize(ext.aniso.xyz + N * ext.misc.z);
+ let strandB = normalize(ext.aniso.xyz + N * ext.misc.w);
+ let h1 = dot(strandA, H);
+ let h2 = dot(strandB, H);
+ let lobe1 = smoothstep(-1.0, 0.0, h1) * pow(sqrt(max(1.0 - h1 * h1, 0.0)), primaryExp);
+ let lobe2 = smoothstep(-1.0, 0.0, h2) * pow(sqrt(max(1.0 - h2 * h2, 0.0)), primaryExp * 0.3);
+ let lightOn = col.rgb * (col.a * atten * clamp(dot(N, L) + 0.35, 0.0, 1.0));
+ gloss += lightOn * (lobe1 * 0.55 + lobe2 * ext.scatter.rgb * 1.6) * (ext.misc.y * specular);
+ } else if (specular > 0.0) {
let H = normalize(L + V);
var brdf : f32;
if (ext.aniso.w != 0.0) {
@@ -2436,8 +2456,7 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p
" highp float m = max(dot(T, T), dot(B, B));\n"
" highp float scale = max(dot(dp1, dp1), dot(dp2, dp2)) * max(dot(duv1, duv1), dot(duv2, duv2));\n"
" if (!(m > scale * 1e-6)) return N;\n"
- " highp float invmax = inversesqrt(m);\n"
- " return normalize(mat3(T * invmax, B * invmax, N) * tangentNormal);\n"
+ " return normalize(mat3(T * inversesqrt(max(dot(T, T), 1e-20)), B * inversesqrt(max(dot(B, B), 1e-20)), N) * tangentNormal);\n"
"}\n"
// Where a world point lands in this camera's part of a screen-space mask.
// Measured on the Z = 0 plane, which is the plane a 2D occluder hides things
@@ -2797,11 +2816,11 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p
// reflection of it a metal is black wherever no light happens to point.
" highp vec2 ab = envBRDFApprox(NdotV, roughness);\n"
" highp vec3 envR = reflect(-V, N);\n"
- " if (ext.aniso.w != 0.0) {\n"
+ " if (ext.aniso.w != 0.0 || ext.misc.y > 0.0) {\n"
" highp vec3 T = ext.aniso.xyz;\n"
- " highp vec3 grain = ext.aniso.w >= 0.0 ? cross(N, T) : T;\n"
+ " highp vec3 grain = (ext.aniso.w >= 0.0 && ext.misc.y <= 0.0) ? cross(N, T) : T;\n"
" highp vec3 bent = normalize(cross(cross(grain, V), grain));\n"
- " envR = reflect(-V, normalize(mix(N, bent, abs(ext.aniso.w))));\n"
+ " envR = reflect(-V, normalize(mix(N, bent, ext.misc.y > 0.0 ? 0.55 : abs(ext.aniso.w))));\n"
" }\n"
" highp vec3 envF = F0 * ab.x + ab.y;\n"
" if (ext.film.x > 0.0) envF = filmFresnel(envF, NdotV, ext.film);\n"
@@ -2876,12 +2895,27 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p
" int(sm.x), int(sm.y)), fo.z);\n"
" }\n"
" highp float ndotl = max(dot(N, L), 0.0);\n"
+ // Hair (misc.y above zero; aniso.xyz is the strand): Kajiya-Kay diffuse, which lights a strand by how far light is from along it.
+ " if (ext.misc.y > 0.0) {\n"
+ " highp float along = dot(ext.aniso.xyz, L);\n"
+ " ndotl = mix(ndotl, sqrt(max(1.0 - along * along, 0.0)) * clamp(dot(N, L) * 0.5 + 0.65, 0.0, 1.0), 0.6);\n"
+ " }\n"
" highp vec3 radiance = col.rgb * (col.a * ndotl * atten);\n"
" lit += radiance;\n"
- // A uniform branch: a surface that reflects nothing does not pay for the lobe.
- // The pi turns the engine's light intensity into the irradiance the BRDF wants,
- // which the diffuse side cancels against albedo/pi and never has to spell out.
- " if (specular > 0.0) {\n"
+ // A uniform branch: a surface that reflects nothing does not pay for the lobe. The pi turns the engine's light intensity
+ // into the irradiance the BRDF wants (the diffuse side cancels it against albedo/pi). Hair has two narrow lobes of its own.
+ " if (specular > 0.0 && ext.misc.y > 0.0) {\n"
+ " highp vec3 H = normalize(L + V);\n"
+ " highp float primaryExp = clamp(2.0 / (a * a), 8.0, 900.0);\n"
+ " highp vec3 t1 = normalize(ext.aniso.xyz + N * ext.misc.z);\n"
+ " highp vec3 t2 = normalize(ext.aniso.xyz + N * ext.misc.w);\n"
+ " highp float h1 = dot(t1, H);\n"
+ " highp float h2 = dot(t2, H);\n"
+ " highp float lobe1 = smoothstep(-1.0, 0.0, h1) * pow(sqrt(max(1.0 - h1 * h1, 0.0)), primaryExp);\n"
+ " highp float lobe2 = smoothstep(-1.0, 0.0, h2) * pow(sqrt(max(1.0 - h2 * h2, 0.0)), primaryExp * 0.3);\n"
+ " highp vec3 lightOn = col.rgb * (col.a * atten * clamp(dot(N, L) + 0.35, 0.0, 1.0));\n"
+ " gloss += lightOn * (lobe1 * 0.55 + lobe2 * ext.scatter.rgb * 1.6) * (ext.misc.y * specular);\n"
+ " } else if (specular > 0.0) {\n"
" highp vec3 H = normalize(L + V);\n"
" highp float brdf;\n"
" if (ext.aniso.w != 0.0) {\n"
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 7382ac2ae..505c19813 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -2517,6 +2517,10 @@ export const NOTED = {
{"note":"Wilds is a new 3D example: a lake under mountains at dusk, made from a generated heightmap with the Terrain, Water and Foliage features and the sky's cloud shadows."},
"chore(tools): the corpus now authors Terrain and Foliage":
{"internal":"the corpus-authoring list after the Wilds example authors both components"},
+ "feat(render): Skin and Hair shaders, and normal maps keep their shape on stretched UVs":
+ {"note":"Two new shaders for characters: Skin softens diffuse light by colour, warms the terminator and lets light through thin places without blurring the picture, and Hair lights strands along a flow map with two shifted highlights. Normal maps on stretched UVs (a face unwrapped into an atlas) now keep their shape, and mipmapped textures are sampled with anisotropic filtering where the device has it."},
+ "chore(editor-checks): hair-look and skin-look checks":
+ {"internal":"the editor checks for the Skin and Hair entry above"},
"chore(tools): the gates run in parallel with --jobs, and the reds a full run gathered are cleared":
{"internal":"tooling for the static gates, and fixes to checks that had drifted from the code they guard"},
"fix(render): a wire narrower than a pixel is no longer painted over by the sky in dashes":
diff --git a/tools/render-host/run.mjs b/tools/render-host/run.mjs
index b7ff3dd08..9e6450147 100644
--- a/tools/render-host/run.mjs
+++ b/tools/render-host/run.mjs
@@ -49,6 +49,10 @@
* ESTELLA_VERIFY_TIMEOUT_MS how long this run may take before it reports one
*/
import { app, BrowserWindow } from 'electron';
+
+// The launcher that started this reads its output through a pipe. If that launcher is stopped, the pipe is gone and the next line printed
+// would raise an uncaught exception, which Electron shows as a dialog box: a run nobody is listening to ends quietly instead.
+for (const stream of [process.stdout, process.stderr]) stream.on('error', () => app.exit(0));
import os from 'node:os';
import { writeFile } from 'node:fs/promises';
import path from 'node:path';