I made a small patch to replace WebGLRenderer with WebGPURenderer in Lume (the patch is shown here).
I noticed that PMREMGenerator
has a fix coming out in r169 thanks for @Mugen87, which I manually patched into node_modules
for now, to try migrating to WebGPU.
Here is my test case scene, which is written with Lume HTML elements (powered by Three.js rendering), showing the expected result:
https://raw.githack.com/lume/lume/b5242eb39d1f3613c1071f6db40d954ca559faf6/examples/gltf-model.html
Video:
After applying that patch from the PR PMREMGenerator in node_modules, and the patch for Lume I linked above (very simple), the new outcome is this:
I’m wondering if there may be a bug, or if the background has to be handled differently with WebGPURenderer.
Here’s the piece of code that uses PMREMGenerator to make the background, fairly simple (specifically the lines marked with // HERE
):
enableBackground(
scene: Scene,
isEquirectangular: boolean,
blurAmount: number,
cb: (tex: Texture | undefined) => void,
): void {
const state = this.sceneStates.get(scene)
if (!state) throw new ReferenceError('Internal error: Scene not registered with WebGLRendererThree.')
this.#bgVersion += 1
state.bgIsEquirectangular = isEquirectangular
if (isEquirectangular) {
// Load the PMREM machinery only if needed.
if (!state.pmremgen) {
state.pmremgen = new PMREMGenerator(state.renderer) // HERE
// @ts-expect-error no type yet
state.pmremgen.compileCubemapShader() // HERE (fixed with the mentioned patch)
}
}
state.hasBg = true
this.#loadBackgroundTexture(scene, blurAmount, cb)
}
#loadBackgroundTexture(scene: Scene, blurAmount: number, cb: (texture: Texture) => void): void {
const state = this.sceneStates.get(scene)
if (!state) throw new ReferenceError('Internal error: Scene not registered with WebGLRendererThree.')
const version = this.#bgVersion
new TextureLoader().load(scene.background ?? '', tex => {
// In case state changed during load, ignore a loaded texture that
// corresponds to previous state:
if (version !== this.#bgVersion) return
if (blurAmount > 0) {
// TODO port to WebGPURenderer
// // state.bgTexture = blurTexture(state.renderer, tex, 5) // Faster, but quality is not as good, has a pixelated effect. Perhaps we should provide a Scene attribute to easily pick which blur to use.
// state.bgTexture = triangleBlurTexture(state.renderer, tex, blurAmount, 2)
// tex.dispose()
// tex = state.bgTexture
}
if (state.bgIsEquirectangular) {
// @ts-expect-error no type yet
state.bgTexture = state.pmremgen!.fromEquirectangular(tex).texture // HERE
tex.dispose() // might not be needed, but just in case.
} else {
state.bgTexture = tex
}
cb(state.bgTexture!)
})
}
Basically the three lines marked with // HERE
use the PMREMGenerator if the conditions are true that will cause pmrem generator to be used.
Is there anything obviously wrong that needs to be changed for WebGPURenderer
? Or should the API usage be the same, and this might be a bug?