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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(render): the batch vertex carries z, and the engine stops flattening it
esengine3354f73691b5
diff --git a/src/esengine/data/shaders/batch.esshader b/src/esengine/data/shaders/batch.esshaderindex 31e81915d..fb6dc84dc 100644--- a/src/esengine/data/shaders/batch.esshader+++ b/src/esengine/data/shaders/batch.esshader@@ -18,7 +18,7 @@#pragma feature ALPHA_CLIP#pragma vertex-layout(location = 0) in vec2 a_position;+layout(location = 0) in vec3 a_position;layout(location = 1) in vec4 a_color;layout(location = 2) in vec2 a_texCoord;layout(location = 3) in float a_texIndex;@@ -41,7 +41,7 @@ out highp vec2 v_worldPos;#endifvoid main() {- gl_Position = u_projection * vec4(a_position, 0.0, 1.0);+ gl_Position = u_projection * vec4(a_position, 1.0);v_color = a_color;v_texCoord = a_texCoord;v_texIndex = int(a_texIndex);@@ -49,7 +49,7 @@ void main() {v_sdfBias = a_sdfBias;#endif#ifdef LIT- v_worldPos = a_position;+ v_worldPos = a_position.xy;#endif}#pragma end@@ -125,7 +125,7 @@ struct FrameConstants { projection : mat4x4f };@group(0) @binding(0) var<uniform> frame : FrameConstants;struct VSIn {- @location(0) a_position : vec2f,+ @location(0) a_position : vec3f,@location(1) a_color : vec4f,@location(2) a_texCoord : vec2f,@location(3) a_texIndex : f32,@@ -148,7 +148,7 @@ struct VSOut {@vertex fn vs_main(v : VSIn) -> VSOut {var out : VSOut;- out.pos = frame.projection * vec4f(v.a_position, 0.0, 1.0);+ out.pos = frame.projection * vec4f(v.a_position, 1.0);out.v_color = v.a_color;out.v_texCoord = v.a_texCoord;out.v_texIndex = v.a_texIndex;@@ -156,7 +156,7 @@ struct VSOut {out.v_sdfBias = v.a_sdfBias;#endif#ifdef LIT- out.v_worldPos = v.a_position;+ out.v_worldPos = v.a_position.xy;#endifreturn out;}diff --git a/src/esengine/renderer/draw/BatchBuilder.hpp b/src/esengine/renderer/draw/BatchBuilder.hppindex 09ca8a2be..303ebf1eb 100644--- a/src/esengine/renderer/draw/BatchBuilder.hpp+++ b/src/esengine/renderer/draw/BatchBuilder.hpp@@ -62,12 +62,14 @@ inline constexpr glm::vec2 BATCH_QUAD_TEX_COORDS[4] = {/** @brief Canonical two-triangle quad winding shared by every batch path. */inline constexpr u32 BATCH_QUAD_INDICES[6] = { 0, 1, 2, 2, 3, 0 };-/** @brief Rotates a point around @p center using a precomputed cos/sin. */-inline glm::vec2 rotatePoint(const glm::vec2& center, f32 px, f32 py, f32 cosA, f32 sinA) {+/** @brief Rotates a point around @p center in the XY plane, carrying the center's z+ * through untouched — the rotation a 2D renderer means is about z. */+inline glm::vec3 rotatePoint(const glm::vec3& center, f32 px, f32 py, f32 cosA, f32 sinA) {f32 dx = px - center.x;f32 dy = py - center.y;return { center.x + dx * cosA - dy * sinA,- center.y + dx * sinA + dy * cosA };+ center.y + dx * sinA + dy * cosA,+ center.z };}// =============================================================================diff --git a/src/esengine/renderer/draw/BatchVertex.hpp b/src/esengine/renderer/draw/BatchVertex.hppindex 1fa0ee18c..aa37a87e4 100644--- a/src/esengine/renderer/draw/BatchVertex.hpp+++ b/src/esengine/renderer/draw/BatchVertex.hpp@@ -7,8 +7,19 @@namespace esengine {+/**+ * @brief One vertex of the shared batch stream.+ *+ * @details `position.z` must be the same world z the draw reports as its sort depth+ * (`BatchDrawKey::depth`). The two answer different questions — the key decides+ * draw ORDER, the vertex feeds projection and the depth test — and a draw whose+ * answers disagree is one the painter's order and the depth buffer would place+ * differently. Under an orthographic camera with the depth test off (today's 2D+ * default) that disagreement is invisible, which is exactly why it has to be an+ * invariant rather than a habit.+ */struct BatchVertex {- glm::vec2 position;+ glm::vec3 position;u32 color;glm::vec2 texCoord;f32 texIndex = 0.0f; // sampler slot within the draw's texture set; assigned at merge timediff --git a/src/esengine/renderer/draw/ImmediateDraw.cpp b/src/esengine/renderer/draw/ImmediateDraw.cppindex 6aa84e840..af4a5cc2d 100644--- a/src/esengine/renderer/draw/ImmediateDraw.cpp+++ b/src/esengine/renderer/draw/ImmediateDraw.cpp@@ -196,7 +196,9 @@ void ImmediateDraw::emitQuad(const glm::vec2& center, const glm::vec2& size, f32glm::vec2 rotated = rotation != 0.0f? glm::vec2(scaled.x * cosR - scaled.y * sinR, scaled.x * sinR + scaled.y * cosR): scaled;- verts[i].position = center + rotated;+ // Immediate geometry bypasses the sort key and draws with the depth test+ // off, so it has no depth of its own to carry — it lands on the z=0 plane.+ verts[i].position = glm::vec3(center + rotated, 0.0f);verts[i].color = packed;verts[i].texCoord = QUAD_UV[i] * uvScale + uvOffset;}@@ -213,9 +215,9 @@ void ImmediateDraw::emitTriangle(const glm::vec2& p0, const glm::vec2& p1, constconst u32 packed = packColor(color);std::array<BatchVertex, 3> verts{- BatchVertex{ p0, packed, {0.0f, 0.0f} },- BatchVertex{ p1, packed, {1.0f, 0.0f} },- BatchVertex{ p2, packed, {1.0f, 1.0f} },+ BatchVertex{ {p0, 0.0f}, packed, {0.0f, 0.0f} },+ BatchVertex{ {p1, 0.0f}, packed, {1.0f, 0.0f} },+ BatchVertex{ {p2, 0.0f}, packed, {1.0f, 1.0f} },};u32 base = pool_.appendVertices(LayoutId::Batch, verts.data(), sizeof(verts)) / sizeof(BatchVertex);diff --git a/src/esengine/renderer/frame/RenderFrameSubmit.cpp b/src/esengine/renderer/frame/RenderFrameSubmit.cppindex 64fee137a..a7976f040 100644--- a/src/esengine/renderer/frame/RenderFrameSubmit.cpp+++ b/src/esengine/renderer/frame/RenderFrameSubmit.cpp@@ -21,10 +21,10 @@ void RenderFrame::submitTileQuad(u32 pc = packColor(color);BatchVertex verts[4] = {- { {position.x - hw, position.y - hh}, pc, uvOffset },- { {position.x + hw, position.y - hh}, pc, {uvOffset.x + uvScale.x, uvOffset.y} },- { {position.x + hw, position.y + hh}, pc, {uvOffset.x + uvScale.x, uvOffset.y + uvScale.y} },- { {position.x - hw, position.y + hh}, pc, {uvOffset.x, uvOffset.y + uvScale.y} },+ { {position.x - hw, position.y - hh, depth}, pc, uvOffset },+ { {position.x + hw, position.y - hh, depth}, pc, {uvOffset.x + uvScale.x, uvOffset.y} },+ { {position.x + hw, position.y + hh, depth}, pc, {uvOffset.x + uvScale.x, uvOffset.y + uvScale.y} },+ { {position.x - hw, position.y + hh, depth}, pc, {uvOffset.x, uvOffset.y + uvScale.y} },};appendQuad(pool_, draw_list_, clip_state_, verts, BatchDrawKey{@@ -60,7 +60,7 @@ void RenderFrame::submitTextBatch(u32 pc = packColor(glm::vec4(v[4], v[5], v[6], v[7]));// texIndex is assigned at merge time; sdfBias rides in from the layout,// which is where an outline pass says how far to grow the glyph.- dst[i] = { {worldPos.x, worldPos.y}, pc, {v[2], v[3]}, 0.0f, v[8] };+ dst[i] = { {worldPos.x, worldPos.y, worldPos.z}, pc, {v[2], v[3]}, 0.0f, v[8] };}// sdf: the SDF variant derives coverage from the distance field; otherwise the@@ -102,7 +102,7 @@ void RenderFrame::submitSpineBatch(const f32* v = vertices + i * FLOATS_PER_VERTEX;glm::vec4 worldPos = model * glm::vec4(v[0], v[1], 0.0f, 1.0f);u32 pc = packColor(glm::vec4(v[4], v[5], v[6], v[7]));- dst[i] = { {worldPos.x, worldPos.y}, pc, {v[2], v[3]} };+ dst[i] = { {worldPos.x, worldPos.y, worldPos.z}, pc, {v[2], v[3]} };}pushBatchCommand(pool_, draw_list_, clip_state_, vOff, static_cast<u32>(vertexCount), indices,diff --git a/src/esengine/renderer/plugins/BatchPlugin.cpp b/src/esengine/renderer/plugins/BatchPlugin.cppindex 8d6ec978b..0ddc084c3 100644--- a/src/esengine/renderer/plugins/BatchPlugin.cpp+++ b/src/esengine/renderer/plugins/BatchPlugin.cpp@@ -19,7 +19,7 @@ namespace esengine {void BatchPlugin::emitQuad(TransientBufferPool& buffers, DrawList& draw_list, const ClipState& clips,- const glm::vec2& position, const glm::vec2& size, const glm::vec2& pivotNorm,+ const glm::vec3& position, const glm::vec2& size, const glm::vec2& pivotNorm,f32 angle, const glm::vec2& uvOffset, const glm::vec2& uvScale,const glm::vec4& color, const BatchDrawKey& key) {@@ -34,18 +34,20 @@ void BatchPlugin::emitQuad(for (u32 i = 0; i < 4; ++i) {f32 lx = (BATCH_QUAD_POSITIONS[i].x + ox) * size.x;f32 ly = (BATCH_QUAD_POSITIONS[i].y + oy) * size.y;- verts[i].position = glm::vec2(+ verts[i].position = glm::vec3(position.x + lx * cosA - ly * sinA,- position.y + lx * sinA + ly * cosA+ position.y + lx * sinA + ly * cosA,+ position.z);verts[i].color = packedColor;verts[i].texCoord = BATCH_QUAD_TEX_COORDS[i] * uvScale + uvOffset;}} else {for (u32 i = 0; i < 4; ++i) {- verts[i].position = glm::vec2(+ verts[i].position = glm::vec3(position.x + (BATCH_QUAD_POSITIONS[i].x + ox) * size.x,- position.y + (BATCH_QUAD_POSITIONS[i].y + oy) * size.y+ position.y + (BATCH_QUAD_POSITIONS[i].y + oy) * size.y,+ position.z);verts[i].color = packedColor;verts[i].texCoord = BATCH_QUAD_TEX_COORDS[i] * uvScale + uvOffset;@@ -57,7 +59,7 @@ void BatchPlugin::emitQuad(void BatchPlugin::emitNineSlice(TransientBufferPool& buffers, DrawList& draw_list, const ClipState& clips,- const glm::vec2& position, const glm::vec2& size, const glm::vec2& pivotNorm,+ const glm::vec3& position, const glm::vec2& size, const glm::vec2& pivotNorm,f32 angle, const glm::vec2& texSize, const glm::vec4& border,const glm::vec2& uvOffset, const glm::vec2& uvScale,const glm::vec4& color, const BatchDrawKey& key@@ -117,7 +119,7 @@ void BatchPlugin::emitNineSlice(void BatchPlugin::emitRadialFill(TransientBufferPool& buffers, DrawList& draw_list, const ClipState& clips,- const glm::vec2& center, const glm::vec2& size, f32 angle,+ const glm::vec3& center, const glm::vec2& size, f32 angle,f32 startAngle, f32 sweep,const glm::vec2& uvOffset, const glm::vec2& uvScale,const glm::vec4& color, const BatchDrawKey& keydiff --git a/src/esengine/renderer/plugins/BatchPlugin.hpp b/src/esengine/renderer/plugins/BatchPlugin.hppindex 86294044a..19beecf21 100644--- a/src/esengine/renderer/plugins/BatchPlugin.hpp+++ b/src/esengine/renderer/plugins/BatchPlugin.hpp@@ -38,7 +38,7 @@ protected:* @param key Non-geometry attributes (stage/layer/shader/blend/texture/depth/entity/type).*/void emitQuad(TransientBufferPool& buffers, DrawList& draw_list, const ClipState& clips,- const glm::vec2& position, const glm::vec2& size, const glm::vec2& pivotNorm,+ const glm::vec3& position, const glm::vec2& size, const glm::vec2& pivotNorm,f32 angle, const glm::vec2& uvOffset, const glm::vec2& uvScale,const glm::vec4& color, const BatchDrawKey& key);@@ -48,7 +48,7 @@ protected:* @param texSize Texture dimensions; if either axis is <= 0 the slice UVs collapse to the outer rect.*/void emitNineSlice(TransientBufferPool& buffers, DrawList& draw_list, const ClipState& clips,- const glm::vec2& position, const glm::vec2& size, const glm::vec2& pivotNorm,+ const glm::vec3& position, const glm::vec2& size, const glm::vec2& pivotNorm,f32 angle, const glm::vec2& texSize, const glm::vec4& border,const glm::vec2& uvOffset, const glm::vec2& uvScale,const glm::vec4& color, const BatchDrawKey& key);@@ -68,7 +68,7 @@ protected:* @param sweep Total swept angle in radians, [0, 2π].*/void emitRadialFill(TransientBufferPool& buffers, DrawList& draw_list, const ClipState& clips,- const glm::vec2& center, const glm::vec2& size, f32 angle,+ const glm::vec3& center, const glm::vec2& size, f32 angle,f32 startAngle, f32 sweep,const glm::vec2& uvOffset, const glm::vec2& uvScale,const glm::vec4& color, const BatchDrawKey& key);diff --git a/src/esengine/renderer/plugins/MeshPlugin.cpp b/src/esengine/renderer/plugins/MeshPlugin.cppindex 0a66d6ff7..2cdc45752 100644--- a/src/esengine/renderer/plugins/MeshPlugin.cpp+++ b/src/esengine/renderer/plugins/MeshPlugin.cpp@@ -104,10 +104,11 @@ void MeshPlugin::collect(RenderCollectContext& collect_ctx) {for (usize v = 0; v < mesh.vertices.size(); ++v) {const auto& in = mesh.vertices[v];glm::vec2 local(in.position.x * scale.x, in.position.y * scale.y);- glm::vec2 world = rotated- ? glm::vec2(position.x + local.x * cosA - local.y * sinA,- position.y + local.x * sinA + local.y * cosA)- : glm::vec2(position.x + local.x, position.y + local.y);+ glm::vec3 world = rotated+ ? glm::vec3(position.x + local.x * cosA - local.y * sinA,+ position.y + local.x * sinA + local.y * cosA,+ position.z)+ : glm::vec3(position.x + local.x, position.y + local.y, position.z);scratch_[v] = { world, tinted ? mulColor(in.color, tint) : in.color, in.uv };}diff --git a/src/esengine/renderer/plugins/ParticlePlugin.cpp b/src/esengine/renderer/plugins/ParticlePlugin.cppindex c2ab0abaf..a5c0a0dd3 100644--- a/src/esengine/renderer/plugins/ParticlePlugin.cpp+++ b/src/esengine/renderer/plugins/ParticlePlugin.cpp@@ -226,8 +226,8 @@ void ParticlePlugin::collect(RenderCollectContext& collect_ctx) {col.a *= t;u32 packed = packColor(col);- trail_verts_.push_back({trail_center_[j] + perp * halfW, packed, glm::vec2(1.0f - t, 0.0f)});- trail_verts_.push_back({trail_center_[j] - perp * halfW, packed, glm::vec2(1.0f - t, 1.0f)});+ trail_verts_.push_back({{trail_center_[j] + perp * halfW, emitterWorldPos.z}, packed, glm::vec2(1.0f - t, 0.0f)});+ trail_verts_.push_back({{trail_center_[j] - perp * halfW, emitterWorldPos.z}, packed, glm::vec2(1.0f - t, 1.0f)});}trail_indices_.clear();diff --git a/src/esengine/renderer/plugins/SpritePlugin.cpp b/src/esengine/renderer/plugins/SpritePlugin.cppindex a91f432bc..3fc348bf9 100644--- a/src/esengine/renderer/plugins/SpritePlugin.cpp+++ b/src/esengine/renderer/plugins/SpritePlugin.cpp@@ -111,20 +111,20 @@ void SpritePlugin::collect(RenderCollectContext& collect_ctx) {if (hasTiling) {emitTiledQuads(buffers, draw_list, clips,- glm::vec2(position), finalSize, sprite.pivot,+ position, finalSize, sprite.pivot,angle, sprite.color, uvOff, uvSc,sprite.tileSize * glm::vec2(scale),sprite.tileSpacing * glm::vec2(scale),key);} else if (useNineSlice) {emitNineSlice(buffers, draw_list, clips,- glm::vec2(position), finalSize, sprite.pivot,+ position, finalSize, sprite.pivot,angle, texSize,glm::vec4(sliceBorder.left, sliceBorder.right, sliceBorder.top, sliceBorder.bottom),uvOff, uvSc, sprite.color, key);} else {emitQuad(buffers, draw_list, clips,- glm::vec2(position), finalSize, sprite.pivot,+ position, finalSize, sprite.pivot,angle, uvOff, uvSc, sprite.color, key);}}@@ -132,7 +132,7 @@ void SpritePlugin::collect(RenderCollectContext& collect_ctx) {void SpritePlugin::emitTiledQuads(TransientBufferPool& buffers, DrawList& draw_list, const ClipState& clips,- const glm::vec2& position, const glm::vec2& size, const glm::vec2& pivot,+ const glm::vec3& position, const glm::vec2& size, const glm::vec2& pivot,f32 angle, const glm::vec4& color,const glm::vec2& uvOffset, const glm::vec2& uvScale,const glm::vec2& tileSize, const glm::vec2& tileSpacing,@@ -170,10 +170,10 @@ void SpritePlugin::emitTiledQuads(verts[2] = { rotatePoint(position, baseX + absSize.x, baseY + absSize.y, cosA, sinA), pc, { uvOffset.x + uvScale.x, uvOffset.y + uvScale.y } };verts[3] = { rotatePoint(position, baseX, baseY + absSize.y, cosA, sinA), pc, { uvOffset.x, uvOffset.y + uvScale.y } };} else {- verts[0] = { { baseX, baseY }, pc, { uvOffset.x, uvOffset.y } };- verts[1] = { { baseX + absSize.x, baseY }, pc, { uvOffset.x + uvScale.x, uvOffset.y } };- verts[2] = { { baseX + absSize.x, baseY + absSize.y }, pc, { uvOffset.x + uvScale.x, uvOffset.y + uvScale.y } };- verts[3] = { { baseX, baseY + absSize.y }, pc, { uvOffset.x, uvOffset.y + uvScale.y } };+ verts[0] = { { baseX, baseY, position.z }, pc, { uvOffset.x, uvOffset.y } };+ verts[1] = { { baseX + absSize.x, baseY, position.z }, pc, { uvOffset.x + uvScale.x, uvOffset.y } };+ verts[2] = { { baseX + absSize.x, baseY + absSize.y, position.z }, pc, { uvOffset.x + uvScale.x, uvOffset.y + uvScale.y } };+ verts[3] = { { baseX, baseY + absSize.y, position.z }, pc, { uvOffset.x, uvOffset.y + uvScale.y } };}appendQuad(buffers, draw_list, clips, verts, key);return;@@ -205,10 +205,10 @@ void SpritePlugin::emitTiledQuads(verts[2] = { rotatePoint(position, x1, y1, cosA, sinA), pc, { uvOffset.x + tileUvScale.x, uvOffset.y + tileUvScale.y } };verts[3] = { rotatePoint(position, x0, y1, cosA, sinA), pc, { uvOffset.x, uvOffset.y + tileUvScale.y } };} else {- verts[0] = { { x0, y0 }, pc, { uvOffset.x, uvOffset.y } };- verts[1] = { { x1, y0 }, pc, { uvOffset.x + tileUvScale.x, uvOffset.y } };- verts[2] = { { x1, y1 }, pc, { uvOffset.x + tileUvScale.x, uvOffset.y + tileUvScale.y } };- verts[3] = { { x0, y1 }, pc, { uvOffset.x, uvOffset.y + tileUvScale.y } };+ verts[0] = { { x0, y0, position.z }, pc, { uvOffset.x, uvOffset.y } };+ verts[1] = { { x1, y0, position.z }, pc, { uvOffset.x + tileUvScale.x, uvOffset.y } };+ verts[2] = { { x1, y1, position.z }, pc, { uvOffset.x + tileUvScale.x, uvOffset.y + tileUvScale.y } };+ verts[3] = { { x0, y1, position.z }, pc, { uvOffset.x, uvOffset.y + tileUvScale.y } };}appendQuad(buffers, draw_list, clips, verts, key);diff --git a/src/esengine/renderer/plugins/SpritePlugin.hpp b/src/esengine/renderer/plugins/SpritePlugin.hppindex b70ac868e..4014949c0 100644--- a/src/esengine/renderer/plugins/SpritePlugin.hpp+++ b/src/esengine/renderer/plugins/SpritePlugin.hpp@@ -16,7 +16,7 @@ private:// so this stays here rather than in BatchPlugin. Emits one quad per tile via appendQuad.void emitTiledQuads(TransientBufferPool& buffers, DrawList& draw_list, const ClipState& clips,- const glm::vec2& position, const glm::vec2& size, const glm::vec2& pivot,+ const glm::vec3& position, const glm::vec2& size, const glm::vec2& pivot,f32 angle, const glm::vec4& color,const glm::vec2& uvOffset, const glm::vec2& uvScale,const glm::vec2& tileSize, const glm::vec2& tileSpacing,diff --git a/src/esengine/renderer/plugins/TextPlugin.cpp b/src/esengine/renderer/plugins/TextPlugin.cppindex 7fd48b551..0316128cc 100644--- a/src/esengine/renderer/plugins/TextPlugin.cpp+++ b/src/esengine/renderer/plugins/TextPlugin.cpp@@ -102,10 +102,10 @@ void TextPlugin::rebuildLayout(const text::BitmapFont& font, const ecs::BitmapTef32 vBottom = (glyph->y + glyph->height) / texH;u32 baseVertex = static_cast<u32>(cache.vertices.size());- cache.vertices.push_back({ {cx - halfW, cy - halfH}, 0, {uMin, vBottom} });- cache.vertices.push_back({ {cx + halfW, cy - halfH}, 0, {uMax, vBottom} });- cache.vertices.push_back({ {cx + halfW, cy + halfH}, 0, {uMax, vTop} });- cache.vertices.push_back({ {cx - halfW, cy + halfH}, 0, {uMin, vTop} });+ cache.vertices.push_back({ {cx - halfW, cy - halfH, 0.0f}, 0, {uMin, vBottom} });+ cache.vertices.push_back({ {cx + halfW, cy - halfH, 0.0f}, 0, {uMax, vBottom} });+ cache.vertices.push_back({ {cx + halfW, cy + halfH, 0.0f}, 0, {uMax, vTop} });+ cache.vertices.push_back({ {cx - halfW, cy + halfH, 0.0f}, 0, {uMin, vTop} });for (u32 i = 0; i < 6; ++i) {cache.indices.push_back(baseVertex + BATCH_QUAD_INDICES[i]);}@@ -171,7 +171,7 @@ void TextPlugin::collect(RenderCollectContext& collect_ctx) {scratch_.reserve(cache.vertices.size());for (const BatchVertex& v : cache.vertices) {scratch_.push_back({- { position.x + v.position.x * s, position.y + v.position.y * s },+ { position.x + v.position.x * s, position.y + v.position.y * s, position.z },packedColor, v.texCoord });}diff --git a/src/esengine/renderer/plugins/TilemapRenderPlugin.cpp b/src/esengine/renderer/plugins/TilemapRenderPlugin.cppindex f49b68c66..b0a143c8b 100644--- a/src/esengine/renderer/plugins/TilemapRenderPlugin.cpp+++ b/src/esengine/renderer/plugins/TilemapRenderPlugin.cpp@@ -130,10 +130,10 @@ void TilemapRenderPlugin::rebuildChunk(SlotMesh& mesh = cache.slots[slotIndex];u32 baseVertex = static_cast<u32>(mesh.vertices.size());- mesh.vertices.push_back({ {worldX - hw, worldY - hh}, 0, {bl.x, bl.y} });- mesh.vertices.push_back({ {worldX + hw, worldY - hh}, 0, {br.x, br.y} });- mesh.vertices.push_back({ {worldX + hw, worldY + hh}, 0, {tr.x, tr.y} });- mesh.vertices.push_back({ {worldX - hw, worldY + hh}, 0, {tl.x, tl.y} });+ mesh.vertices.push_back({ {worldX - hw, worldY - hh, 0.0f}, 0, {bl.x, bl.y} });+ mesh.vertices.push_back({ {worldX + hw, worldY - hh, 0.0f}, 0, {br.x, br.y} });+ mesh.vertices.push_back({ {worldX + hw, worldY + hh, 0.0f}, 0, {tr.x, tr.y} });+ mesh.vertices.push_back({ {worldX - hw, worldY + hh, 0.0f}, 0, {tl.x, tl.y} });for (u32 i = 0; i < 6; ++i) {mesh.indices.push_back(baseVertex + BATCH_QUAD_INDICES[i]);@@ -330,7 +330,7 @@ void TilemapRenderPlugin::collect(RenderCollectContext& collect_ctx) {u32 baseVertex = static_cast<u32>(slotVertices[si].size());for (const BatchVertex& v : mesh.vertices) {slotVertices[si].push_back({- { v.position.x + adjOriginX, v.position.y + adjOriginY },+ { v.position.x + adjOriginX, v.position.y + adjOriginY, depth },packedColor, v.texCoord });}for (u32 idx : mesh.indices) {diff --git a/src/esengine/renderer/plugins/TrailPlugin.cpp b/src/esengine/renderer/plugins/TrailPlugin.cppindex b6422ecf0..e49a19a1c 100644--- a/src/esengine/renderer/plugins/TrailPlugin.cpp+++ b/src/esengine/renderer/plugins/TrailPlugin.cpp@@ -129,8 +129,8 @@ void TrailPlugin::collect(RenderCollectContext& collect_ctx) {glm::vec2 left = c.pos + perp * halfW;glm::vec2 right = c.pos - perp * halfW;- scratch_verts_.push_back({left, color, glm::vec2(u, 0.0f)});- scratch_verts_.push_back({right, color, glm::vec2(u, 1.0f)});+ scratch_verts_.push_back({{left, headWorld.z}, color, glm::vec2(u, 0.0f)});+ scratch_verts_.push_back({{right, headWorld.z}, color, glm::vec2(u, 1.0f)});}scratch_indices_.clear();diff --git a/src/esengine/renderer/plugins/UIElementPlugin.cpp b/src/esengine/renderer/plugins/UIElementPlugin.cppindex 72120b71b..369b60c40 100644--- a/src/esengine/renderer/plugins/UIElementPlugin.cpp+++ b/src/esengine/renderer/plugins/UIElementPlugin.cpp@@ -262,17 +262,17 @@ void UIElementPlugin::collect(RenderCollectContext& collect_ctx) {f32 sweep = std::clamp(renderer.fillAmount, 0.0f, 1.0f)* radialMaxSweep(renderer.fillMethod);emitRadialFill(buffers, draw_list, clips,- glm::vec2(position), finalSize, angle,+ position, finalSize, angle,radialStartAngle(renderer.fillOrigin), sweep,uvOffset, uvScale, color, key);} else if (useNineSlice) {emitNineSlice(buffers, draw_list, clips,- glm::vec2(position), finalSize, CENTERED_PIVOT,+ position, finalSize, CENTERED_PIVOT,angle, texSize, sliceBorder,uvOffset, uvScale, color, key);} else {emitQuad(buffers, draw_list, clips,- glm::vec2(position), finalSize, CENTERED_PIVOT,+ position, finalSize, CENTERED_PIVOT,angle, uvOffset, uvScale, color, key);}}diff --git a/src/esengine/renderer/rhi/ShaderEmbeds.generated.hpp b/src/esengine/renderer/rhi/ShaderEmbeds.generated.hppindex 4efe8c944..869cc9627 100644--- a/src/esengine/renderer/rhi/ShaderEmbeds.generated.hpp+++ b/src/esengine/renderer/rhi/ShaderEmbeds.generated.hpp@@ -22,7 +22,7 @@ inline constexpr const char* BATCH = R"esshader(#pragma shader "Batch"#pragma feature ALPHA_CLIP#pragma vertex-layout(location = 0) in vec2 a_position;+layout(location = 0) in vec3 a_position;layout(location = 1) in vec4 a_color;layout(location = 2) in vec2 a_texCoord;layout(location = 3) in float a_texIndex;@@ -45,7 +45,7 @@ out highp vec2 v_worldPos;#endifvoid main() {- gl_Position = u_projection * vec4(a_position, 0.0, 1.0);+ gl_Position = u_projection * vec4(a_position, 1.0);v_color = a_color;v_texCoord = a_texCoord;v_texIndex = int(a_texIndex);@@ -53,7 +53,7 @@ void main() {v_sdfBias = a_sdfBias;#endif#ifdef LIT- v_worldPos = a_position;+ v_worldPos = a_position.xy;#endif}#pragma end@@ -129,7 +129,7 @@ struct FrameConstants { projection : mat4x4f };@group(0) @binding(0) var<uniform> frame : FrameConstants;struct VSIn {- @location(0) a_position : vec2f,+ @location(0) a_position : vec3f,@location(1) a_color : vec4f,@location(2) a_texCoord : vec2f,@location(3) a_texIndex : f32,@@ -152,7 +152,7 @@ struct VSOut {@vertex fn vs_main(v : VSIn) -> VSOut {var out : VSOut;- out.pos = frame.projection * vec4f(v.a_position, 0.0, 1.0);+ out.pos = frame.projection * vec4f(v.a_position, 1.0);out.v_color = v.a_color;out.v_texCoord = v.a_texCoord;out.v_texIndex = v.a_texIndex;@@ -160,7 +160,7 @@ struct VSOut {out.v_sdfBias = v.a_sdfBias;#endif#ifdef LIT- out.v_worldPos = v.a_position;+ out.v_worldPos = v.a_position.xy;#endifreturn out;}diff --git a/src/esengine/renderer/rhi/TransientBufferPool.cpp b/src/esengine/renderer/rhi/TransientBufferPool.cppindex 9c1a4b640..0ba693c6b 100644--- a/src/esengine/renderer/rhi/TransientBufferPool.cpp+++ b/src/esengine/renderer/rhi/TransientBufferPool.cpp@@ -230,14 +230,14 @@ void TransientBufferPool::setupStream(LayoutId layout) {VertexLayoutDesc desc;switch (layout) {case LayoutId::Batch:- // BatchVertex: pos(8) + color(4) + uv(8) + texIndex(4) + sdfBias(4)+ // BatchVertex: pos(12) + color(4) + uv(8) + texIndex(4) + sdfBias(4)desc.attributeCount = 5;- desc.strides[0] = 28;- desc.attributes[0] = {0, 2, GfxDataType::Float, false, 0, 0};- desc.attributes[1] = {1, 4, GfxDataType::UnsignedByte, true, 8, 0};- desc.attributes[2] = {2, 2, GfxDataType::Float, false, 12, 0};- desc.attributes[3] = {3, 1, GfxDataType::Float, false, 20, 0};- desc.attributes[4] = {4, 1, GfxDataType::Float, false, 24, 0};+ desc.strides[0] = 32;+ desc.attributes[0] = {0, 3, GfxDataType::Float, false, 0, 0};+ desc.attributes[1] = {1, 4, GfxDataType::UnsignedByte, true, 12, 0};+ desc.attributes[2] = {2, 2, GfxDataType::Float, false, 16, 0};+ desc.attributes[3] = {3, 1, GfxDataType::Float, false, 24, 0};+ desc.attributes[4] = {4, 1, GfxDataType::Float, false, 28, 0};break;case LayoutId::Shape:desc.attributeCount = 4;diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cppindex 678de562e..e75897f61 100644--- a/tests/renderer/test_batch_builder.cpp+++ b/tests/renderer/test_batch_builder.cpp@@ -63,10 +63,10 @@ TEST_CASE("pool reports each stream's vertex stride (single source for baseVerteTEST_CASE("appendQuad: Batch command with baseVertex-offset indices and one texture slot") {Harness h;BatchVertex quad[4] = {- { {0, 0}, 0xFFFFFFFFu, {0, 0} },- { {1, 0}, 0xFFFFFFFFu, {1, 0} },- { {1, 1}, 0xFFFFFFFFu, {1, 1} },- { {0, 1}, 0xFFFFFFFFu, {0, 1} },+ { {0, 0, 0}, 0xFFFFFFFFu, {0, 0} },+ { {1, 0, 0}, 0xFFFFFFFFu, {1, 0} },+ { {1, 1, 0}, 0xFFFFFFFFu, {1, 1} },+ { {0, 1, 0}, 0xFFFFFFFFu, {0, 1} },};appendQuad(h.pool, h.list, h.clips, quad, quadKey(42));appendQuad(h.pool, h.list, h.clips, quad, quadKey(42));@@ -129,10 +129,10 @@ TEST_CASE("pushBatchDraw: instanced key assembles an instanced command over statTEST_CASE("finalize: adjacent same-key Batch draws with different textures merge multi-texture") {Harness h;BatchVertex quad[4] = {- { {0, 0}, 0xFFFFFFFFu, {0, 0} },- { {1, 0}, 0xFFFFFFFFu, {1, 0} },- { {1, 1}, 0xFFFFFFFFu, {1, 1} },- { {0, 1}, 0xFFFFFFFFu, {0, 1} },+ { {0, 0, 0}, 0xFFFFFFFFu, {0, 0} },+ { {1, 0, 0}, 0xFFFFFFFFu, {1, 0} },+ { {1, 1, 0}, 0xFFFFFFFFu, {1, 1} },+ { {0, 1, 0}, 0xFFFFFFFFu, {0, 1} },};appendQuad(h.pool, h.list, h.clips, quad, quadKey(42));appendQuad(h.pool, h.list, h.clips, quad, quadKey(43));