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 mesh with no colour channel draws, as white vertices

esengine62b063563c0e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c4958ba7b..7db5e08c7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -355,12 +355,18 @@ published separately; it ships inside the editor.
### Fixed
+- **A baked decal draws on devices and under WebGPU.** A decal bake writes its mesh
+ without a vertex colour, and every mesh shader reads one: WebGL2 read black, while
+ WebGPU and the native hosts rejected the pipeline, so `physics-3d` drew nothing at
+ all on Android. A mesh with no colour channel now draws as white vertices, which is
+ what an import without vertex colours already meant.
+
- **A material that writes only its fragment stage draws on a mesh under WebGPU and on
devices.** Its generated WebGPU twin carried a copy of the vertex stage made for
- sprites, so on a mesh the device rejected the pipeline and the surface never drew —
- `physics-3d`'s decal target on Android among them. Twins for such materials now
- carry only the fragment stage, and the engine supplies the vertex stage for every
- source; an older twin is regenerated when the project is opened or exported.
+ sprites, so on a mesh the device rejected the pipeline and the surface never drew.
+ Twins for such materials now carry only the fragment stage, and the engine supplies
+ the vertex stage for every source; an older twin is regenerated when the project is
+ opened or exported.
- **Opening a project from inside the editor no longer leaves the loading screen up.**
An agent's `open_project` while a project was already open — once that project had
diff --git a/fixtures/scenes/colorless-triangles.esmesh b/fixtures/scenes/colorless-triangles.esmesh
new file mode 100644
index 000000000..c7b26cf2c
Binary files /dev/null and b/fixtures/scenes/colorless-triangles.esmesh differ
diff --git a/src/esengine/resource/ResourceManager.cpp b/src/esengine/resource/ResourceManager.cpp
index 8e9b39b58..fa71abacf 100644
--- a/src/esengine/resource/ResourceManager.cpp
+++ b/src/esengine/resource/ResourceManager.cpp
@@ -503,6 +503,36 @@ bool ResourceManager::realizeMesh(Mesh& mesh, ConstSpan<u8> vertexBytes, ConstSp
ConstSpan<f32> inverseBind, const MeshMorphSource& morph) {
if (!device_ || vertexBytes.empty() || indices.empty() || channels.empty()) return false;
+ // Every mesh shader reads a colour, and a layout without one is a pipeline WebGPU
+ // refuses (WebGL2 reads black). A producer that wrote none meant white, so the
+ // channel is added here, where every mesh reaches the device.
+ std::vector<u8> coloredBytes;
+ std::vector<GfxVertexAttribute> coloredChannels;
+ const bool hasColor = std::any_of(channels.begin(), channels.end(), [](const GfxVertexAttribute& c) {
+ return c.location == static_cast<u32>(MeshChannel::Color);
+ });
+ if (!hasColor && vertexStride > 0) {
+ const usize count = vertexBytes.size() / vertexStride;
+ const u32 colorOffset = (vertexStride + 3u) & ~3u;
+ const u32 stride = colorOffset + 4u;
+ coloredBytes.assign(count * stride, 0);
+ for (usize v = 0; v < count; ++v) {
+ std::memcpy(&coloredBytes[v * stride], &vertexBytes[v * vertexStride], vertexStride);
+ std::memset(&coloredBytes[v * stride + colorOffset], 0xFF, 4);
+ }
+ coloredChannels.assign(channels.begin(), channels.end());
+ GfxVertexAttribute color;
+ color.location = static_cast<u32>(MeshChannel::Color);
+ color.components = 4;
+ color.type = GfxDataType::UnsignedByte;
+ color.normalized = true;
+ color.offset = colorOffset;
+ coloredChannels.push_back(color);
+ vertexBytes = ConstSpan<u8>(coloredBytes);
+ channels = ConstSpan<GfxVertexAttribute>(coloredChannels);
+ vertexStride = stride;
+ }
+
// The mesh describes its own vertices and nothing else: the per-object
// transform reaches the shader through the frame's record texture, which is
// what leaves every slot above the mesh channels free.
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index 3420ed827..b2fb9ebd0 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,9 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(render): a mesh with no colour channel draws, as white vertices':
+ { note: 'A baked decal draws on devices and under WebGPU.' },
+
'fix(render): a material that writes only its fragment draws on a mesh under WebGPU':
{ note: 'A material that writes only its fragment stage draws on a mesh under WebGPU and on' },
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 2fec52454..f90a25e87 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -567,6 +567,9 @@ export const SCENES = [
// asset layer replaces the inline payload. Its fixture is written by the
// engine's own encoder from this scene's vertices, so the assertions hold.
{ id: "mesh-asset", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_MESH_ASSET: "/scenes/two-triangles.esmesh", ESTELLA_VERIFY_SCENE: "/scenes/mesh-renderer.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-renderer.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.30,\"y\":0.556,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.70,\"y\":0.556,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.30,\"y\":0.40,\"rgb\":[255,0,0],\"tol\":40}]" } },
+ // The same triangles with no colour channel, as a decal bake writes them. Every mesh
+ // shader reads one: WebGL2 read black and WebGPU refused the pipeline.
+ { id: "mesh-colorless", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_MESH_ASSET: "/scenes/colorless-triangles.esmesh", ESTELLA_VERIFY_SCENE: "/scenes/mesh-renderer.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-renderer.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.30,\"y\":0.556,\"rgb\":[255,255,255],\"tol\":40},{\"x\":0.70,\"y\":0.556,\"rgb\":[255,255,255],\"tol\":40}]" } },
{ id: "mesh-resident", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_MESH_RESIDENT: "1", ESTELLA_VERIFY_SCENE: "/scenes/mesh-renderer.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mesh-renderer.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "4", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.30,\"y\":0.556,\"rgb\":[255,0,0],\"tol\":40},{\"x\":0.70,\"y\":0.556,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.30,\"y\":0.40,\"rgb\":[255,0,0],\"tol\":40}]" } },
// A material drawing GPU-resident geometry. Its shader writes only a fragment,
// so the ENGINE owns the vertex stage and compiles a second variant for this