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(render): a two-channel normal map lights its surface

esengine454b91acd752
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d12f8d31d..25f48e808 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ published separately; it ships inside the editor.
### Fixed
+- Normal maps stored in two channels light correctly. The shader rebuilds Z from X and Y instead of reading blue, so a BC5 map, or one a converter wrote with blue at 0 — every normal map of Bistro's glTF conversion — no longer points its surface's normals inward, which left normal-mapped surfaces unlit by their sun.
- Compressed (KTX2) textures on web and mini-games are sampled with their mip chain. The cook has always written one into every texture it compresses, and only level 0 reached the GPU: a compressed texture shimmered as it shrank into the distance, and the rest of its bytes shipped for nothing. A texture decoded to RGBA on a device with no compressed format gets its chain generated.
- The package size report on Windows attributes the SDK's bytes to the directories they come from again: every module read as "project", since the source map's paths were spelled with backslashes.
- A WeChat package registers every engine component and the built-in AI names again. The WeChat entries lost their start-up calls to the bundler, so a scene using a component with no typed definition — a rigged model's MeshSkin among them — loaded without it ("Unknown component type") and its character was never skinned.
diff --git a/examples/physics-3d/assets/materials/decal-target.esshader b/examples/physics-3d/assets/materials/decal-target.esshader
index 942fdf9cf..879fc57df 100644
--- a/examples/physics-3d/assets/materials/decal-target.esshader
+++ b/examples/physics-3d/assets/materials/decal-target.esshader
@@ -27,7 +27,7 @@ void main() {
// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
// Regenerate after changing the GLSL stages above.
// source-hash: 144f76db1f5f521a
-// assembled-hash: 79eb055be41650e3
+// assembled-hash: 11e880f98c97fd94
struct MaterialConstants {
u_tint: vec4<f32>,
}
diff --git a/fixtures/scenes/mat-builtin-lit/lit.esshader b/fixtures/scenes/mat-builtin-lit/lit.esshader
index 099943952..19e49905d 100644
--- a/fixtures/scenes/mat-builtin-lit/lit.esshader
+++ b/fixtures/scenes/mat-builtin-lit/lit.esshader
@@ -27,7 +27,7 @@ void main() {
// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
// Regenerate after changing the GLSL stages above.
// source-hash: 5330079245724fa2
-// assembled-hash: 98df5be7badb3741
+// assembled-hash: f630aceaa74351b1
struct FrameConstants {
u_projection: mat4x4<f32>,
u_camera: vec4<f32>,
@@ -397,16 +397,16 @@ fn shadowFactor2D_u0028_f1_u003b_vf2_u003b(channel_1: ptr<function, f32>, worldP
var hidden: f32;
var param_10: vec4<f32>;
var param_11: f32;
- var phi_335_: bool;
+ var phi_345_: bool;
let _e103 = (*channel_1);
let _e104 = (_e103 < 0f);
- phi_335_ = _e104;
+ phi_345_ = _e104;
if !(_e104) {
let _e108 = unnamed_1.u_mask2DRect[2u];
- phi_335_ = (_e108 <= 0f);
+ phi_345_ = (_e108 <= 0f);
}
- let _e111 = phi_335_;
+ let _e111 = phi_345_;
if _e111 {
return 1f;
}
@@ -434,16 +434,16 @@ fn shapeFactor2D_u0028_f1_u003b_vf2_u003b(channel_2: ptr<function, f32>, worldPo
var param_12: vec2<f32>;
var param_13: vec4<f32>;
var param_14: f32;
- var phi_374_: bool;
+ var phi_384_: bool;
let _e102 = (*channel_2);
let _e103 = (_e102 < 0f);
- phi_374_ = _e103;
+ phi_384_ = _e103;
if !(_e103) {
let _e107 = unnamed_1.u_mask2DRect[2u];
- phi_374_ = (_e107 <= 0f);
+ phi_384_ = (_e107 <= 0f);
}
- let _e110 = phi_374_;
+ let _e110 = phi_384_;
if _e110 {
return 1f;
}
@@ -737,8 +737,8 @@ fn applyLightingPBR_u0028_vf3_u003b_vf3_u003b_vf3_u003b_vf3_u003b_f1_u003b_f1_u0
var param_64: f32;
var param_65: f32;
var param_66: vec3<f32>;
- var phi_1116_: bool;
- var phi_1189_: bool;
+ var phi_1126_: bool;
+ var phi_1199_: bool;
let _e177 = (*albedo);
let _e178 = (*metallic);
@@ -822,13 +822,13 @@ fn applyLightingPBR_u0028_vf3_u003b_vf3_u003b_vf3_u003b_vf3_u003b_f1_u003b_f1_u0
toLight_3 = _e257;
let _e259 = sh_5[1u];
let _e260 = (_e259 > 0f);
- phi_1116_ = _e260;
+ phi_1126_ = _e260;
if _e260 {
let _e261 = toLight_3;
let _e262 = toLight_3;
- phi_1116_ = (dot(_e261, _e262) > 0.5f);
+ phi_1126_ = (dot(_e261, _e262) > 0.5f);
}
- let _e266 = phi_1116_;
+ let _e266 = phi_1126_;
castShadow = _e266;
let _e267 = (*worldPos_5);
let _e269 = toLight_3;
@@ -889,12 +889,12 @@ fn applyLightingPBR_u0028_vf3_u003b_vf3_u003b_vf3_u003b_vf3_u003b_f1_u003b_f1_u0
atten = (_e312 * _e311);
}
let _e314 = castShadow;
- phi_1189_ = _e314;
+ phi_1199_ = _e314;
if _e314 {
let _e316 = col[3u];
- phi_1189_ = (_e316 > 0f);
+ phi_1199_ = (_e316 > 0f);
}
- let _e319 = phi_1189_;
+ let _e319 = phi_1199_;
let _e320 = atten;
if (_e319 && (_e320 > 0f)) {
let _e323 = i_2;
@@ -1081,9 +1081,15 @@ fn applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b(albedo_2: ptr<function, v
}
fn sampleNormal_u0028_t21_u003b_p1_u003b_vf2_u003b(map_est: texture_2d<f32>, map_ess: sampler, uv_2: ptr<function, vec2<f32>>) -> vec3<f32> {
- let _e99 = (*uv_2);
- let _e100 = textureSample(map_est, map_ess, _e99);
- return normalize(((_e100.xyz * 2f) - vec3(1f)));
+ var xy: vec2<f32>;
+
+ let _e100 = (*uv_2);
+ let _e101 = textureSample(map_est, map_ess, _e100);
+ xy = ((_e101.xy * 2f) - vec2(1f));
+ let _e106 = xy;
+ let _e107 = xy;
+ let _e108 = xy;
+ return vec3<f32>(_e106.x, _e106.y, sqrt(max(0f, (1f - dot(_e107, _e108)))));
}
fn main_1() {
diff --git a/fixtures/scenes/mat-generated-mesh/split.esshader b/fixtures/scenes/mat-generated-mesh/split.esshader
index 5f1602472..9c7763eeb 100644
--- a/fixtures/scenes/mat-generated-mesh/split.esshader
+++ b/fixtures/scenes/mat-generated-mesh/split.esshader
@@ -22,7 +22,7 @@ void main() {
// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
// Regenerate after changing the GLSL stages above.
// source-hash: 7af6948ea05e1a30
-// assembled-hash: 6ec4645bd2387623
+// assembled-hash: 12dac50e0d49bb35
struct MaterialConstants {
u_tint: vec4<f32>,
}
diff --git a/fixtures/scenes/mat-lit-flatnormal/lit-fn.esshader b/fixtures/scenes/mat-lit-flatnormal/lit-fn.esshader
index a3bb640cd..fa4552bed 100644
--- a/fixtures/scenes/mat-lit-flatnormal/lit-fn.esshader
+++ b/fixtures/scenes/mat-lit-flatnormal/lit-fn.esshader
@@ -47,7 +47,7 @@ void main() {
// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
// Regenerate after changing the GLSL stages above.
// source-hash: a8853729e0f76d55
-// assembled-hash: 5dc351f278bd87d7
+// assembled-hash: 7018c9fe2d0593dc
struct gl_PerVertex {
@builtin(position) gl_Position: vec4<f32>,
gl_PointSize: f32,
@@ -123,7 +123,7 @@ fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>,
// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
// Regenerate after changing the GLSL stages above.
// source-hash: a8853729e0f76d55
-// assembled-hash: 5dc351f278bd87d7
+// assembled-hash: 7018c9fe2d0593dc
struct FrameConstants {
u_projection: mat4x4<f32>,
u_camera: vec4<f32>,
@@ -487,16 +487,16 @@ fn shadowFactor2D_u0028_f1_u003b_vf2_u003b(channel_1: ptr<function, f32>, worldP
var hidden: f32;
var param_10: vec4<f32>;
var param_11: f32;
- var phi_335_: bool;
+ var phi_345_: bool;
let _e102 = (*channel_1);
let _e103 = (_e102 < 0f);
- phi_335_ = _e103;
+ phi_345_ = _e103;
if !(_e103) {
let _e107 = unnamed_1.u_mask2DRect[2u];
- phi_335_ = (_e107 <= 0f);
+ phi_345_ = (_e107 <= 0f);
}
- let _e110 = phi_335_;
+ let _e110 = phi_345_;
if _e110 {
return 1f;
}
@@ -524,16 +524,16 @@ fn shapeFactor2D_u0028_f1_u003b_vf2_u003b(channel_2: ptr<function, f32>, worldPo
var param_12: vec2<f32>;
var param_13: vec4<f32>;
var param_14: f32;
- var phi_374_: bool;
+ var phi_384_: bool;
let _e101 = (*channel_2);
let _e102 = (_e101 < 0f);
- phi_374_ = _e102;
+ phi_384_ = _e102;
if !(_e102) {
let _e106 = unnamed_1.u_mask2DRect[2u];
- phi_374_ = (_e106 <= 0f);
+ phi_384_ = (_e106 <= 0f);
}
- let _e109 = phi_374_;
+ let _e109 = phi_384_;
if _e109 {
return 1f;
}
@@ -827,8 +827,8 @@ fn applyLightingPBR_u0028_vf3_u003b_vf3_u003b_vf3_u003b_vf3_u003b_f1_u003b_f1_u0
var param_64: f32;
var param_65: f32;
var param_66: vec3<f32>;
- var phi_1116_: bool;
- var phi_1189_: bool;
+ var phi_1126_: bool;
+ var phi_1199_: bool;
let _e176 = (*albedo);
let _e177 = (*metallic);
@@ -912,13 +912,13 @@ fn applyLightingPBR_u0028_vf3_u003b_vf3_u003b_vf3_u003b_vf3_u003b_f1_u003b_f1_u0
toLight_3 = _e256;
let _e258 = sh_5[1u];
let _e259 = (_e258 > 0f);
- phi_1116_ = _e259;
+ phi_1126_ = _e259;
if _e259 {
let _e260 = toLight_3;
let _e261 = toLight_3;
- phi_1116_ = (dot(_e260, _e261) > 0.5f);
+ phi_1126_ = (dot(_e260, _e261) > 0.5f);
}
- let _e265 = phi_1116_;
+ let _e265 = phi_1126_;
castShadow = _e265;
let _e266 = (*worldPos_5);
let _e268 = toLight_3;
@@ -979,12 +979,12 @@ fn applyLightingPBR_u0028_vf3_u003b_vf3_u003b_vf3_u003b_vf3_u003b_f1_u003b_f1_u0
atten = (_e311 * _e310);
}
let _e313 = castShadow;
- phi_1189_ = _e313;
+ phi_1199_ = _e313;
if _e313 {
let _e315 = col[3u];
- phi_1189_ = (_e315 > 0f);
+ phi_1199_ = (_e315 > 0f);
}
- let _e318 = phi_1189_;
+ let _e318 = phi_1199_;
let _e319 = atten;
if (_e318 && (_e319 > 0f)) {
let _e322 = i_2;
@@ -1171,9 +1171,15 @@ fn applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b(albedo_2: ptr<function, v
}
fn sampleNormal_u0028_t21_u003b_p1_u003b_vf2_u003b(map_est: texture_2d<f32>, map_ess: sampler, uv_2: ptr<function, vec2<f32>>) -> vec3<f32> {
- let _e98 = (*uv_2);
- let _e99 = textureSample(map_est, map_ess, _e98);
- return normalize(((_e99.xyz * 2f) - vec3(1f)));
+ var xy: vec2<f32>;
+
+ let _e99 = (*uv_2);
+ let _e100 = textureSample(map_est, map_ess, _e99);
+ xy = ((_e100.xy * 2f) - vec2(1f));
+ let _e105 = xy;
+ let _e106 = xy;
+ let _e107 = xy;
+ return vec3<f32>(_e105.x, _e105.y, sqrt(max(0f, (1f - dot(_e106, _e107)))));
}
fn main_1() {
diff --git a/fixtures/scenes/mat-lit-normal/lit-normal.esshader b/fixtures/scenes/mat-lit-normal/lit-normal.esshader
index 991234ac2..c1e8d08cc 100644
--- a/fixtures/scenes/mat-lit-normal/lit-normal.esshader
+++ b/fixtures/scenes/mat-lit-normal/lit-normal.esshader
@@ -47,7 +47,7 @@ void main() {
// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
// Regenerate after changing the GLSL stages above.
// source-hash: 577c1ff7b66006ff
-// assembled-hash: 556eba57d702f31a
+// assembled-hash: ae6a70cd0e4bbc69
struct gl_PerVertex {
@builtin(position) gl_Position: vec4<f32>,
gl_PointSize: f32,
@@ -123,7 +123,7 @@ fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>,
// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
// Regenerate after changing the GLSL stages above.
// source-hash: 577c1ff7b66006ff
-// assembled-hash: 556eba57d702f31a
+// assembled-hash: ae6a70cd0e4bbc69
struct FrameConstants {
u_projection: mat4x4<f32>,
u_camera: vec4<f32>,
@@ -487,16 +487,16 @@ fn shadowFactor2D_u0028_f1_u003b_vf2_u003b(channel_1: ptr<function, f32>, worldP
var hidden: f32;
var param_10: vec4<f32>;
var param_11: f32;
- var phi_335_: bool;
+ var phi_345_: bool;
let _e102 = (*channel_1);
let _e103 = (_e102 < 0f);
- phi_335_ = _e103;
+ phi_345_ = _e103;
if !(_e103) {
let _e107 = unnamed_1.u_mask2DRect[2u];
- phi_335_ = (_e107 <= 0f);
+ phi_345_ = (_e107 <= 0f);
}
- let _e110 = phi_335_;
+ let _e110 = phi_345_;
if _e110 {
return 1f;
}
@@ -524,16 +524,16 @@ fn shapeFactor2D_u0028_f1_u003b_vf2_u003b(channel_2: ptr<function, f32>, worldPo
var param_12: vec2<f32>;
var param_13: vec4<f32>;
var param_14: f32;
- var phi_374_: bool;
+ var phi_384_: bool;
let _e101 = (*channel_2);
let _e102 = (_e101 < 0f);
- phi_374_ = _e102;
+ phi_384_ = _e102;
if !(_e102) {
let _e106 = unnamed_1.u_mask2DRect[2u];
- phi_374_ = (_e106 <= 0f);
+ phi_384_ = (_e106 <= 0f);
}
- let _e109 = phi_374_;
+ let _e109 = phi_384_;
if _e109 {
return 1f;
}
@@ -827,8 +827,8 @@ fn applyLightingPBR_u0028_vf3_u003b_vf3_u003b_vf3_u003b_vf3_u003b_f1_u003b_f1_u0
var param_64: f32;
var param_65: f32;
var param_66: vec3<f32>;
- var phi_1116_: bool;
- var phi_1189_: bool;
+ var phi_1126_: bool;
+ var phi_1199_: bool;
let _e176 = (*albedo);
let _e177 = (*metallic);
@@ -912,13 +912,13 @@ fn applyLightingPBR_u0028_vf3_u003b_vf3_u003b_vf3_u003b_vf3_u003b_f1_u003b_f1_u0
toLight_3 = _e256;
let _e258 = sh_5[1u];
let _e259 = (_e258 > 0f);
- phi_1116_ = _e259;
+ phi_1126_ = _e259;
if _e259 {
let _e260 = toLight_3;
let _e261 = toLight_3;
- phi_1116_ = (dot(_e260, _e261) > 0.5f);
+ phi_1126_ = (dot(_e260, _e261) > 0.5f);
}
- let _e265 = phi_1116_;
+ let _e265 = phi_1126_;
castShadow = _e265;
let _e266 = (*worldPos_5);
let _e268 = toLight_3;
@@ -979,12 +979,12 @@ fn applyLightingPBR_u0028_vf3_u003b_vf3_u003b_vf3_u003b_vf3_u003b_f1_u003b_f1_u0
atten = (_e311 * _e310);
}
let _e313 = castShadow;
- phi_1189_ = _e313;
+ phi_1199_ = _e313;
if _e313 {
let _e315 = col[3u];
- phi_1189_ = (_e315 > 0f);
+ phi_1199_ = (_e315 > 0f);
}
- let _e318 = phi_1189_;
+ let _e318 = phi_1199_;
let _e319 = atten;
if (_e318 && (_e319 > 0f)) {
let _e322 = i_2;
@@ -1171,9 +1171,15 @@ fn applyLighting2D_u0028_vf3_u003b_vf3_u003b_vf2_u003b(albedo_2: ptr<function, v
}
fn sampleNormal_u0028_t21_u003b_p1_u003b_vf2_u003b(map_est: texture_2d<f32>, map_ess: sampler, uv_2: ptr<function, vec2<f32>>) -> vec3<f32> {
- let _e98 = (*uv_2);
- let _e99 = textureSample(map_est, map_ess, _e98);
- return normalize(((_e99.xyz * 2f) - vec3(1f)));
+ var xy: vec2<f32>;
+
+ let _e99 = (*uv_2);
+ let _e100 = textureSample(map_est, map_ess, _e99);
+ xy = ((_e100.xy * 2f) - vec2(1f));
+ let _e105 = xy;
+ let _e106 = xy;
+ let _e107 = xy;
+ return vec3<f32>(_e105.x, _e105.y, sqrt(max(0f, (1f - dot(_e106, _e107)))));
}
fn main_1() {
diff --git a/fixtures/scenes/mat-lit/lit.esshader b/fixtures/scenes/mat-lit/lit.esshader
index 94f08bb1b..09701467b 100644
--- a/fixtures/scenes/mat-lit/lit.esshader
+++ b/fixtures/scenes/mat-lit/lit.esshader
@@ -53,7 +53,7 @@ void main() {
// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
// Regenerate after changing the GLSL stages above.
// source-hash: 8c118f2b442c055e
-// assembled-hash: 07ec67bfdb9b24e9
+// assembled-hash: fa2a2c85e10fb0e9
struct gl_PerVertex {
@builtin(position) gl_Position: vec4<f32>,
gl_PointSize: f32,
@@ -125,7 +125,7 @@ fn vs_main(@location(0) a_position: vec3<f32>, @location(1) a_color: vec4<f32>,
// GENERATED by tools/gen-shader-twins.mjs (glslang + naga) - do not edit.
// Regenerate after changing the GLSL stages above.
// source-hash: 8c118f2b442c055e
-// assembled-hash: 07ec67bfdb9b24e9
+// assembled-hash: fa2a2c85e10fb0e9
struct FrameConstants {
u_projection: mat4x4<f32>,
u_camera: vec4<f32>,
diff --git a/fixtures/scenes/mesh-normalmap-xy.esscene b/fixtures/scenes/mesh-normalmap-xy.esscene
new file mode 100644
index 000000000..c58c95e74
--- /dev/null
+++ b/fixtures/scenes/mesh-normalmap-xy.esscene
@@ -0,0 +1,66 @@
+{
+ "version": 4,
+ "name": "MeshNormalMapXY",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 10
+ }
+ }
+ },
+ {
+ "type": "Camera",
+ "data": {
+ "projectionType": 1,
+ "orthoSize": 300,
+ "isActive": true,
+ "priority": 0
+ }
+ }
+ ]
+ },
+ {
+ "id": 1,
+ "name": "Sun",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "Light",
+ "data": {
+ "type": 1,
+ "color": {
+ "r": 1,
+ "g": 1,
+ "b": 1,
+ "a": 1
+ },
+ "intensity": 1
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/fixtures/scenes/mesh-normalmap-xy.textures.json b/fixtures/scenes/mesh-normalmap-xy.textures.json
new file mode 100644
index 000000000..0967ef424
--- /dev/null
+++ b/fixtures/scenes/mesh-normalmap-xy.textures.json
@@ -0,0 +1 @@
+{}
diff --git a/fixtures/scenes/normalmap-xy.esprefab b/fixtures/scenes/normalmap-xy.esprefab
new file mode 100644
index 000000000..6a641ccb8
--- /dev/null
+++ b/fixtures/scenes/normalmap-xy.esprefab
@@ -0,0 +1,37 @@
+{
+ "version": "2",
+ "name": "normalmap-xy",
+ "rootEntityId": "n0",
+ "entities": [
+ {
+ "prefabEntityId": "n0",
+ "name": "Quad",
+ "parent": null,
+ "children": [],
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {}
+ },
+ {
+ "type": "MeshRenderer",
+ "data": {
+ "mesh": "scenes/normalmap-quad.esmesh",
+ "lit": true,
+ "material": "scenes/normalmap-xy_m0.esmaterial",
+ "color": {
+ "r": 1,
+ "g": 1,
+ "b": 1,
+ "a": 1
+ },
+ "opaque": true,
+ "cullBackfaces": true,
+ "enabled": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/fixtures/scenes/normalmap-xy.esprefab.meta b/fixtures/scenes/normalmap-xy.esprefab.meta
new file mode 100644
index 000000000..848b38d5e
--- /dev/null
+++ b/fixtures/scenes/normalmap-xy.esprefab.meta
@@ -0,0 +1,8 @@
+{
+ "uuid": "a7a34c46-2551-49db-a1d7-7fe894e8ce7e",
+ "version": "2.0",
+ "type": "prefab",
+ "importer": {
+ "autoMigrate": true
+ }
+}
diff --git a/fixtures/scenes/normalmap-xy_0.png b/fixtures/scenes/normalmap-xy_0.png
new file mode 100644
index 000000000..15f6992f6
Binary files /dev/null and b/fixtures/scenes/normalmap-xy_0.png differ
diff --git a/fixtures/scenes/normalmap-xy_0.png.meta b/fixtures/scenes/normalmap-xy_0.png.meta
new file mode 100644
index 000000000..8543850b8
--- /dev/null
+++ b/fixtures/scenes/normalmap-xy_0.png.meta
@@ -0,0 +1,20 @@
+{
+ "uuid": "ee3ecef7-647c-4159-a3d6-bc1069df547e",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 2048,
+ "compress": true,
+ "compressFormat": "uastc",
+ "filterMode": "linear",
+ "wrapMode": "repeat",
+ "premultiplyAlpha": false,
+ "sRGB": true,
+ "sliceBorder": {
+ "left": 0,
+ "right": 0,
+ "top": 0,
+ "bottom": 0
+ }
+ }
+}
diff --git a/fixtures/scenes/normalmap-xy_m0.esmaterial b/fixtures/scenes/normalmap-xy_m0.esmaterial
new file mode 100644
index 000000000..b3f6ae25a
--- /dev/null
+++ b/fixtures/scenes/normalmap-xy_m0.esmaterial
@@ -0,0 +1,14 @@
+{
+ "version": "1.0",
+ "type": "material",
+ "shader": "builtin:model",
+ "blendMode": 9,
+ "depthTest": true,
+ "depthWrite": true,
+ "cull": 1,
+ "properties": {
+ "u_normalMap": "normalmap-xy_0.png",
+ "u_metallic": 0,
+ "u_roughness": 1
+ }
+}
diff --git a/fixtures/scenes/normalmap-xy_m0.esmaterial.meta b/fixtures/scenes/normalmap-xy_m0.esmaterial.meta
new file mode 100644
index 000000000..da8a80571
--- /dev/null
+++ b/fixtures/scenes/normalmap-xy_m0.esmaterial.meta
@@ -0,0 +1,6 @@
+{
+ "uuid": "049e4611-33c8-49aa-b3ea-cccdb7c1824c",
+ "version": "2.0",
+ "type": "material",
+ "importer": {}
+}
diff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cpp
index 4513fbe22..e612a74ab 100644
--- a/src/esengine/resource/ShaderParser.cpp
+++ b/src/esengine/resource/ShaderParser.cpp
@@ -1201,7 +1201,8 @@ fn shadowFactor3D(worldPos : vec3f, N : vec3f, L : vec3f, source : vec2f,
#endif
}
fn sampleNormal(map : texture_2d<f32>, samp : sampler, uv : vec2f) -> vec3f {
- return normalize(textureSampleLevel(map, samp, uv, 0.0).xyz * 2.0 - 1.0);
+ let xy = textureSampleLevel(map, samp, uv, 0.0).xy * 2.0 - 1.0;
+ return vec3f(xy, sqrt(max(0.0, 1.0 - dot(xy, xy))));
}
fn perturbNormal(N : vec3f, worldPos : vec3f, uv : vec2f, tangentNormal : vec3f) -> vec3f {
let dp1 = dpdx(worldPos);
@@ -2029,11 +2030,12 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p
" return 1.0;\n"
"#endif\n"
"}\n"
- // Engine-owned normal-map convention (RGB[0,1] -> normal[-1,1], normalized), so every
- // Lit shader unpacks tangent-space normals the same way. 2D applies it screen-space
- // (no per-sprite tangent frame); a flat surface uses vec3(0,0,1).
+ // The one normal-map unpack: X and Y from RG, Z rebuilt to unit length, so a
+ // two-channel map (BC5, or B left at 0) lights like the three-channel one. 2D
+ // applies it screen-space; a flat surface uses vec3(0,0,1).
"highp vec3 sampleNormal(in highp sampler2D map, in highp vec2 uv) {\n"
- " return normalize(texture(map, uv).xyz * 2.0 - 1.0);\n"
+ " highp vec2 xy = texture(map, uv).xy * 2.0 - 1.0;\n"
+ " return vec3(xy, sqrt(max(0.0, 1.0 - dot(xy, xy))));\n"
"}\n"
// Tangent frame from screen-space derivatives, so a tangent-space normal
// lands in world space without the geometry carrying a tangent channel —
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 4ff223387..3e0c6dbc4 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -1228,6 +1228,8 @@ export const NOTED = {
{ note: 'Web exports pack their small local assets — meshes, materials, KTX2 textures, timelines and animation assets — into a few `packs/*.pack` files, one request each, and the runtime reads each asset out of its pack. A browser holds six connections to a site, so a scene of thousands of small files loaded at the pace of its requests: Bistro\'s 1505 meshes took 43 s of load time for 0.2 s of upload. Its first frame on a Windows machine went from 15.2 s to 7.3 s, pixel for pixel the same. An export with hot update configured keeps one file per asset, since an update downloads assets one by one; an update that meets a packed asset refuses it by name.' },
'feat(export): a web export packs its small local assets into a few files':
{ note: 'Web exports pack their small local assets — meshes, materials, KTX2 textures, timelines and animation assets — into a few `packs/*.pack` files, one request each, and the runtime reads each asset out of its pack. A browser holds six connections to a site, so a scene of thousands of small files loaded at the pace of its requests: Bistro\'s 1505 meshes took 43 s of load time for 0.2 s of upload. Its first frame on a Windows machine went from 15.2 s to 7.3 s, pixel for pixel the same. An export with hot update configured keeps one file per asset, since an update downloads assets one by one; an update that meets a packed asset refuses it by name.' },
+ 'fix(render): a two-channel normal map lights its surface':
+ { note: 'Normal maps stored in two channels light correctly. The shader rebuilds Z from X and Y instead of reading blue, so a BC5 map, or one a converter wrote with blue at 0 — every normal map of Bistro\'s glTF conversion — no longer points its surface\'s normals inward, which left normal-mapped surfaces unlit by their sun.' },
'fix(eht): the generator writes LF on every platform':
{ internal: 'The engine header tool is a repository generator; on Windows it rewrote every generated file with CRLF, which only a contributor there ever saw.' },
};
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index e2ae3416d..36dd44b55 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -688,6 +688,10 @@ export const SCENES = [
// both halves take the same light. Its texels point -X and +X, so the lit half
// and the unlit one are the tangent frame, derived per pixel from derivatives.
{ id: "mesh-normalmap", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PREFAB: "/scenes/normalmap-quad.esprefab", ESTELLA_VERIFY_SCENE: "/scenes/mesh-normalmap.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-normalmap.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.375,\"y\":0.5,\"rgb\":[180,180,180],\"tol\":45},{\"x\":0.625,\"y\":0.5,\"rgb\":[0,0,0],\"tol\":30}]" } },
+ // The same quad under a two-channel normal map (B = 0, as BC5 and some converters
+ // store it), lit from the front. Rebuilding Z from X and Y turns both halves toward
+ // the light; unpacking B as Z points them into the surface and both go black.
+ { id: "mesh-normalmap-xy", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_PREFAB: "/scenes/normalmap-xy.esprefab", ESTELLA_VERIFY_SCENE: "/scenes/mesh-normalmap-xy.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-normalmap-xy.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.375,\"y\":0.5,\"rgb\":[241,241,241],\"tol\":30},{\"x\":0.625,\"y\":0.5,\"rgb\":[241,241,241],\"tol\":30}]" } },
// The channels only a material can carry, one quad each, through the products a
// real import wrote. Ambient light only: the black quad's lit half can only be
// emission, the white quad's right half is occluded away, the cutout discards.