Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions packages/xrui/core/textures/KTX2Encoder.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
import { createWorkerFromCrossOriginURL } from '@etherealengine/common/src/utils/createWorkerFromCrossOriginURL'

import { WorkerPool } from '../WorkerPool'

// @ts-ignore
const workerURL = new URL('./KTX2Worker.bundle.txt', import.meta.url).href
const workerPath = new URL('./KTX2Worker.bundle.js', import.meta.url).href

export enum UASTCFlags {
/** Fastest is the lowest quality, although it's stil substantially higher quality vs. BC1/ETC1. It supports 5 modes.
/* The output may be somewhat blocky because this setting doesn't support 2/3-subset UASTC modes, but it should be less blocky vs. BC1/ETC1.
/* This setting doesn't write BC1 hints, so BC1 transcoding will be slower.
/* Transcoded ETC1 quality will be lower because it only considers 2 hints out of 32.
/* Avg. 43.45 dB
/* The output may be somewhat blocky because this setting doesn't support 2/3-subset UASTC modes, but it should be less blocky vs. BC1/ETC1.
/* This setting doesn't write BC1 hints, so BC1 transcoding will be slower.
/* Transcoded ETC1 quality will be lower because it only considers 2 hints out of 32.
/* Avg. 43.45 dB
*/
UASTCLevelFastest = 0,

/** Faster is ~3x slower than fastest. It supports 9 modes.
/* Avg. 46.49 dB
*/
/* Avg. 46.49 dB
*/
UASTCLevelFaster = 1,

/** Default is ~5.5x slower than fastest. It supports 14 modes.
/* Avg. 47.47 dB
*/
/* Avg. 47.47 dB
*/
UASTCLevelDefault = 2,

/** Slower is ~14.5x slower than fastest. It supports all 18 modes.
/* Avg. 48.01 dB
*/
/* Avg. 48.01 dB
*/
UASTCLevelSlower = 3,

/** VerySlow is ~200x slower than fastest.
/* The best quality the codec is capable of, but you'll need to be patient or have a lot of cores.
/* Avg. 48.24 dB
*/
/* The best quality the codec is capable of, but you'll need to be patient or have a lot of cores.
/* Avg. 48.24 dB
*/
UASTCLevelVerySlow = 4,

UASTCLevelMask = 0xf,

/** By default the encoder tries to strike a balance between UASTC and transcoded BC7 quality.
/** These flags allow you to favor only optimizing for lowest UASTC error, or lowest BC7 error.
*/
/** These flags allow you to favor only optimizing for lowest UASTC error, or lowest BC7 error.
*/
UASTCFavorUASTCError = 8,
UASTCFavorBC7Error = 16,

Expand Down Expand Up @@ -115,7 +117,7 @@ export class KTX2Encoder {
pool = new WorkerPool(1)

constructor() {
this.pool.setWorkerCreator(() => new Worker(workerURL))
this.pool.setWorkerCreator(() => createWorkerFromCrossOriginURL(workerPath, false, { name: 'KTX2 Encoder' }))
}

setWorkerLimit(limit: number) {
Expand Down
2 changes: 1 addition & 1 deletion packages/xrui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"npmClient": "npm",
"scripts": {
"build": "npm run build:worker",
"build:worker": "esbuild core/textures/KTX2Worker.ts --bundle --format=esm --outfile=core/textures/KTX2Worker.bundle.txt --loader:.wasm=binary",
"build:worker": "esbuild core/textures/KTX2Worker.ts --bundle --format=esm --outfile=core/textures/KTX2Worker.bundle.js --loader:.wasm=binary",
"test": "cross-env TEST=true mocha --config .mocharc.cjs"
},
"dependencies": {
Expand Down