-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to compress textures with Basis Universal #16142
base: master
Are you sure you want to change the base?
Conversation
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/16142/merge/index.html#WGZLGJ#4600 Links to test babylon tools with this snapshot: https://playground.babylonjs.com/?snapshot=refs/pull/16142/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/16142/merge#BCU1XR#0 |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
… basisu-encoder
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
…eSRGBBuffer" This reverts commit 2504c3f.
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
WebGL2 visualization test reporter: |
WebGL2 visualization test reporter: |
Visualization tests for WebGPU |
2e82263
to
b739d2b
Compare
* Initialize resources for the Basis Universal encoder. | ||
* @returns a promise that resolves when the Basis Universal encoder resources are initialized | ||
*/ | ||
export async function InitializeBasisEncoderAsync(): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitty, but any opinions about whether the encoder should be a class or not?
On the one hand,
- It is stateful (workerpool management)
- Module level functions clutter the BABYLON namespace and (I assume) require unique names
On the other,
- Since this is a singleton, it makes sense to leave things at the module-level
- Opportunity to move this all into
basis.ts
, our transcoder module that is also module-level
Logger.Warn("Texture data will be converted into unsigned bytes for Basis encoding. This may result in loss of precision."); | ||
} | ||
|
||
const pixels = await GetTextureDataAsync(babylonTexture, size.width, size.height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not figure out why GetTextureDataAsync()
doesn't actually wait for the texture to be loaded, hence why I'm forced to call this function like:
texture.onLoadObservable.addOnce(() => EncodeTextureToBasis(...))
Does anyone have any ideas?
For a repro of the issue, see https://playground.babylonjs.com/#OHUP0G
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @returns a promise that resolves when the worker is initialized | ||
* @internal | ||
*/ | ||
export function initializeWebWorker(worker: Worker, wasmBinary: ArrayBuffer, moduleUrl?: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: I'd like to eventually move this to workerUtils and reuse, if possible, across other places... but perhaps sometime after this PR. I don't think this makes it to the public API right now, anyway
This PR exposes the method
EncodeTextureToBasisAsync
which will encode a non-HDR, non-cube texture data to a KTX v2 image with Basis Universal supercompression.