Skip to content

Add native cube render target support (re-enables 2 shadow-with-instances tests)#1750

Draft
bkaradzic-microsoft wants to merge 1 commit into
BabylonJS:masterfrom
bkaradzic-microsoft:native-cube-render-target
Draft

Add native cube render target support (re-enables 2 shadow-with-instances tests)#1750
bkaradzic-microsoft wants to merge 1 commit into
BabylonJS:masterfrom
bkaradzic-microsoft:native-cube-render-target

Conversation

@bkaradzic-microsoft

@bkaradzic-microsoft bkaradzic-microsoft commented Jun 11, 2026

Copy link
Copy Markdown
Member

Paired engine PR: BabylonJS/Babylon.js#18561

What

Implements cube render targets on the native engine so ReflectionProbe and
point-light cube shadow maps render instead of crashing on the null WebGL
context. Pairs with the Babylon.js change that adds the JS-side overrides.

Changes

  • Plugins/NativeEngine/Source/NativeEngine.cpp
    • 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.
  • Apps/Playground/Scripts/config.json: re-enables "Shadows with instances in
    left/right handed system" (previously excluded as crash/hang).

CI

The validation suite uses the published babylonjs npm, which does not yet
contain the paired JS overrides, so the re-enabled tests stay red until a
babylonjs release with the Babylon.js change ships and the dependency is
bumped here. Draft until then.

Verified locally

Built against a local babylon.max.js with the paired change: the two
re-enabled tests pass and there are no regressions in post-process / 2D
render-target tests.


Related PRs & landing order

Co-dependent; land in this order:

  1. Babylon.js #18561 first — adds the cube render-target TS overrides; no WebGL behavior change.
  2. A babylonjs npm release ships that TS change.
  3. BabylonNative Add native cube render target support (re-enables 2 shadow-with-instances tests) #1750 last — bumps the bundled babylonjs and re-enables the 2 Shadows with instances (left/right handed) validation tests, which only pass once the paired JS is present in the bundled engine.

bkaradzic-microsoft added a commit to BabylonJS/Babylon.js that referenced this pull request Jun 17, 2026
Addresses review: cube RT adds isCube/layer params that old native silently ignores (2D RT with aliased faces, no error). Bumping the protocol version makes any JS<->Native version skew fail loudly at engine init via the existing strict-equality check, instead of rendering incorrectly. Pairs with the native-side bump in BabylonJS/BabylonNative#1750 (landed together with the babylonjs pin bump).
@bkaradzic-microsoft

Copy link
Copy Markdown
Member Author

TODO at landing: bump the native PROTOCOL_VERSION (Plugins/NativeEngine/Source/NativeEngine.cpp, the StaticValue("PROTOCOL_VERSION", ...)) from 9 → 10 to pair with the JS-side bump in BabylonJS/Babylon.js#18561 (the cube-RT version gate from bghgary's review).

This must land in the same change that bumps the babylonjs pin to a release containing #18561's PROTOCOL_VERSION = 10. Bumping it standalone now would make every test here throw Protocol version mismatch at engine init against the currently-bundled 9.x, so it's deferred until the coordinated pin bump.

bkaradzic-microsoft added a commit to BabylonJS/Babylon.js that referenced this pull request Jun 18, 2026
Paired native PR: BabylonJS/BabylonNative#1750

## What

Adds cube render target support to the Babylon Native engine. Previously
the
native engine had no `createRenderTargetCubeTexture` override and
`bindFramebuffer(faceIndex)` threw, so any feature that renders into a
cube map
— `ReflectionProbe`, point-light cube shadow maps — fell through to the
WebGL
code path and dereferenced the null `_gl` context (`TEXTURE_CUBE_MAP
undefined`).

## Changes (`packages/dev/core/src/Engines`)

- `thinNativeEngine.pure.ts`
- `createRenderTargetCubeTexture`: creates a native cube color texture
and one
framebuffer per face (the native side binds the matching cube layer).
- `bindFramebuffer`: binds the per-face framebuffer for cube render
targets.
- `generateMipMapsForCubemap`: no-op on Native — bgfx auto-generates the
mip
    chain on render-target resolve, the same way 2D RTTs get their mips.
- `Native/nativeRenderTargetWrapper.ts`: tracks per-face framebuffers
and
  releases them on dispose.
- `Native/nativeInterfaces.ts`: threads the cube/layer params through
  `initializeTexture` and `createFrameBuffer`.

## Paired native change

Requires the matching BabylonNative C++ change (cube color texture +
per-face
attachment). Draft until both land.

## Testing

Built `babylon.max.js` and ran the BabylonNative Playground validation
suite
(D3D11). The "Shadows with instances" tests (left/right handed), which
previously crashed, now pass; the ReflectionProbe and point-light-shadow
scenes
render with correct geometry and orientation.

---

## Related PRs & landing order

- **Babylon.js (engine / TS):**
#18561
- **BabylonNative (C++ engine + test re-enable):**
BabylonJS/BabylonNative#1750

Co-dependent; land in this order:
1. **Babylon.js #18561 first** — adds the cube render-target TS
overrides; no WebGL behavior change.
2. A **`babylonjs` npm release** ships that TS change.
3. **BabylonNative #1750 last** — bumps the bundled `babylonjs` and
re-enables the 2 `Shadows with instances` (left/right handed) validation
tests, which only pass once the paired JS is present in the bundled
engine.

---------

Co-authored-by: Branimir Karadzic <branimirkaradzic@gmail.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nces 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>
@bkaradzic-microsoft bkaradzic-microsoft force-pushed the native-cube-render-target branch from 77c4f66 to f7da119 Compare June 18, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants