[Native] Load single-file .dds/.ktx/.ktx2 cubemaps on the native engine#18560
[Native] Load single-file .dds/.ktx/.ktx2 cubemaps on the native engine#18560bkaradzic-microsoft wants to merge 2 commits into
Conversation
|
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
1 similar comment
|
Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s). |
|
Snapshot stored with reference name: Test environment: To test a playground add it to the URL, for example: https://snapshots-cvgtc2eugrd3cgfd.z01.azurefd.net/refs/pull/18560/merge/index.html#WGZLGJ#4600 Links to test your changes to core in the published versions of the Babylon tools (does not contain changes you made to the tools themselves): https://playground.babylonjs.com/?snapshot=refs/pull/18560/merge To test the snapshot in the playground with a playground ID add it after the snapshot query string: https://playground.babylonjs.com/?snapshot=refs/pull/18560/merge#BCU1XR#0 If you made changes to the sandbox or playground in this PR, additional comments will be generated soon containing links to the dev versions of those tools. |
|
Visualization tests for WebGPU |
🟢 Memory Leak Test Results13 passed, 0 leaked out of 13 scenarios 🟢 All memory leak tests passed — no leaks detected. Passed Scenarios (13)
|
|
WebGL2 visualization test reporter: |
⚡ Performance Test Results🟢 All performance tests passed — no regressions detected. |
…armonics loadCubeTexture now accepts a single self-contained cubemap container (all six faces + mips), decoded via bimg::imageParse, and uploads sides 0-5 x mips. ComputeCubeSphericalPolynomial derives the diffuse-IBL spherical harmonics from the top-mip faces (port of CubeMapToSphericalPolynomialTools) and returns the polynomial coefficients to JS. This is done natively because the WebGL upload and cube-readback paths are unimplemented on native and .dds stores no SH. Re-enables 6 prefiltered-environment PBR validation tests. Pairs with BabylonJS/Babylon.js#18560 (native createCubeTexture dispatch for single-URL containers). Depends on a babylonjs dependency bump including it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The native createCubeTexture override only handled a single .env file or six face files; a single self-contained cubemap container (.dds/.ktx/.ktx2, as produced by CubeTexture.CreateFromPrefilteredData) threw "Cannot load cubemap because 6 files were not defined". The generic WebGL loader route is unusable on native (its texture-upload and cube-readback entry points are unimplemented). Route a single-URL container cubemap to engine.loadCubeTexture with the raw buffer; the native engine decodes it (bimg) and, when polynomials are requested, returns spherical-harmonics coefficients computed from the top mip, which are set as the texture's spherical polynomial. loadCubeTexture's onSuccess now optionally carries those coefficients. The .env and six-file paths are unchanged. Pairs with a Babylon Native NativeEngine change implementing the single-buffer cube decode and spherical-harmonics computation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…d onSuccess The six-file path passed the Promise resolve directly, which is not assignable to the widened onSuccess signature (sphericalPolynomial?: Float32Array). Wrap with () => resolve() / () => reject(new Error(...)). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
09715d8 to
843f25c
Compare
|
WebGL2 visualization test reporter: |
|
Closing as superseded by the loader rework (the BabylonNative#218 loader rework, BabylonJS/BabylonNative#218): implementing the native |
🟢 Memory Leak Test Results13 passed, 0 leaked out of 13 scenarios 🟢 All memory leak tests passed — no leaks detected. Passed Scenarios (13)
|
|
Visualization tests for WebGPU |
⚡ Performance Test Results🟢 All performance tests passed — no regressions detected. |
…armonics loadCubeTexture now accepts a single self-contained cubemap container (all six faces + mips), decoded via bimg::imageParse, and uploads sides 0-5 x mips. ComputeCubeSphericalPolynomial derives the diffuse-IBL spherical harmonics from the top-mip faces (port of CubeMapToSphericalPolynomialTools) and returns the polynomial coefficients to JS. This is done natively because the WebGL upload and cube-readback paths are unimplemented on native and .dds stores no SH. Re-enables 6 prefiltered-environment PBR validation tests. Pairs with BabylonJS/Babylon.js#18560 (native createCubeTexture dispatch for single-URL containers). Depends on a babylonjs dependency bump including it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…armonics loadCubeTexture now accepts a single self-contained cubemap container (all six faces + mips), decoded via bimg::imageParse, and uploads sides 0-5 x mips. ComputeCubeSphericalPolynomial derives the diffuse-IBL spherical harmonics from the top-mip faces (port of CubeMapToSphericalPolynomialTools) and returns the polynomial coefficients to JS. This is done natively because the WebGL upload and cube-readback paths are unimplemented on native and .dds stores no SH. Re-enables 6 prefiltered-environment PBR validation tests. Pairs with BabylonJS/Babylon.js#18560 (native createCubeTexture dispatch for single-URL containers). Depends on a babylonjs dependency bump including it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
[Native] Load single-file
.dds/.ktx/.ktx2cubemaps on the native engineProblem
The native engine overrides
createCubeTexture(nativeEngine.cubeTexture.pure.ts) and onlyhandles two cases: a single
.envfile, and an array of six face files. A single self-containedcubemap container —
.dds/.ktx/.ktx2, the format produced byCubeTexture.CreateFromPrefilteredData(...)— falls through to:So prefiltered-environment scenes (PBR IBL) that reference a single
.ddscannot load it onnative at all.
This path was never wired because the generic WebGL loader route isn't usable on native: the
engine's
_uploadDataToTextureDirectly/_uploadCompressedDataToTextureDirectly(and cube_readTexturePixels) are unimplemented there — native uploads via its own command path, and the.envbranch worked only because.envships pre-split faces plus baked spherical harmonics.Fix
Route a single-URL container cubemap to the native engine, which decodes it (bimg already supports
DDS/KTX/KTX2 cube containers) and, when polynomials are requested, returns the spherical-harmonics
coefficients it computed from the top mip. The diffuse-IBL spherical polynomial is then set on the
texture from those coefficients.
nativeEngine.cubeTexture.pure.ts: in the non-.envbranch, keep the existing six-file path,and add a branch for a single-URL container — fetch the bytes (or use the provided
buffer),call
engine.loadCubeTexture(resource, [buffer], ...), and on success set_sphericalPolynomialfrom the returned coefficients (whencreatePolynomialswas requested).nativeInterfaces.ts:loadCubeTexture'sonSuccessnow optionally carries the sphericalpolynomial coefficients (
(sphericalPolynomial?: Float32Array) => void); the existing six-filecaller ignores them.
No change to the
.envor six-file paths.Testing
Validated on Babylon Native (Win32 / D3D11) with the Playground validation suite: six previously
unloadable prefiltered-environment
.ddsPBR scenes now load and render correctly, matching theirreference images. The computed spherical-harmonics integration is correct (total solid angle = 4π).
Related PRs & landing order
Co-dependent; land in this order:
babylonjsnpm release ships that TS change.babylonjsand re-enables the 6 prefiltered-.ddsPBR validation tests, which only pass once the paired JS is present in the bundled engine. The folded-inblur-cube-with-the-effect-renderertest additionally requires [Native] Honor depthCullingState.depthTest on the native engine #18558 to be in the samebabylonjsrelease.