From f7da119cb93cc4395aac65f335a5d28728c0712a Mon Sep 17 00:00:00 2001 From: Branimir Karadzic Date: Wed, 10 Jun 2026 21:24:45 -0700 Subject: [PATCH] Add native cube render target support (re-enables 2 shadow-with-instances tests) Render-to-cubemap on the native engine so ReflectionProbe and point-light cube shadow maps render instead of dereferencing the null WebGL context. - InitializeTexture: optional isCube param -> Texture::CreateCube. - CreateFrameBuffer: optional layer param so the color attachment targets a single cube face (bgfx::Attachment layer); the JS side creates one framebuffer per face and binds the matching one per face. Re-enables the "Shadows with instances in left/right handed system" validation tests that previously crashed/hung. Requires the paired Babylon.js change (native cube render target JS overrides); CI stays red until a babylonjs npm with that change is published and the dep bumped here. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Apps/Playground/Scripts/config.json | 4 ---- Plugins/NativeEngine/Source/NativeEngine.cpp | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Apps/Playground/Scripts/config.json b/Apps/Playground/Scripts/config.json index 3b7389558..75cc09441 100644 --- a/Apps/Playground/Scripts/config.json +++ b/Apps/Playground/Scripts/config.json @@ -1823,16 +1823,12 @@ "title": "Shadows with instances in left handed system", "playgroundId": "#MSAHKR#79", "renderCount": 10, - "excludeFromAutomaticTesting": true, - "reason": "Test crashes or hangs on Babylon Native", "referenceImage": "shadowsinstancesleft.png" }, { "title": "Shadows with instances in right handed system", "playgroundId": "#MSAHKR#13", "renderCount": 10, - "excludeFromAutomaticTesting": true, - "reason": "Test crashes or hangs on Babylon Native", "referenceImage": "shadowsinstancesright.png" }, { diff --git a/Plugins/NativeEngine/Source/NativeEngine.cpp b/Plugins/NativeEngine/Source/NativeEngine.cpp index 864031710..7d7bee390 100644 --- a/Plugins/NativeEngine/Source/NativeEngine.cpp +++ b/Plugins/NativeEngine/Source/NativeEngine.cpp @@ -1348,6 +1348,7 @@ namespace Babylon const bool renderTarget = info[5].As(); const bool srgb = info[6].As(); const uint32_t samples = info[7].IsUndefined() ? 1 : info[7].As().Uint32Value(); + const bool isCube = info.Length() > 8 && !info[8].IsUndefined() && info[8].As(); auto flags = BGFX_TEXTURE_NONE; if (renderTarget) @@ -1359,7 +1360,15 @@ namespace Babylon flags |= BGFX_TEXTURE_SRGB; } - texture->Create2D(width, height, hasMips, 1, format, flags); + if (isCube) + { + // Cube render target: width is the per-face size. + texture->CreateCube(width, hasMips, 1, format, flags); + } + else + { + texture->Create2D(width, height, hasMips, 1, format, flags); + } } void NativeEngine::LoadTexture(const Napi::CallbackInfo& info) @@ -1852,6 +1861,8 @@ namespace Babylon const bool generateStencilBuffer = info[3].As(); const bool generateDepth = info[4].As(); const uint32_t samples = info[5].IsUndefined() ? 1 : info[5].As().Uint32Value(); + // Optional cube-face / array layer for the color attachment (single-face cube render targets). + const uint16_t layer = (info.Length() > 6 && !info[6].IsUndefined()) ? static_cast(info[6].As().Uint32Value()) : 0; std::array attachments{}; uint8_t numAttachments = 0; @@ -1862,7 +1873,7 @@ namespace Babylon // bgfx validation now asserts when trying to use BGFX_RESOLVE_AUTO_GEN_MIPS with a texture that doesn't have the BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN flag, // but before it would just ignore the flag and not generate mips without any warning. This prevents validation assert, but rendering might be broken if autogen // mips were expected. Basically this change preserves previous behavior. - attachments[numAttachments++].init(texture->Handle(), bgfx::Access::Write, 0, 1, 0 + attachments[numAttachments++].init(texture->Handle(), bgfx::Access::Write, layer, 1, 0 , 0 != (caps->formats[texture->Format()] & BGFX_CAPS_FORMAT_TEXTURE_MIP_AUTOGEN) ? BGFX_RESOLVE_AUTO_GEN_MIPS : BGFX_RESOLVE_NONE ); }