Skip to content

Adapt reflection and screenshot components to WebGPURenderer#5848

Open
vincentfretin wants to merge 1 commit into
aframevr:masterfrom
vincentfretin:webgpu-reflection-screenshot
Open

Adapt reflection and screenshot components to WebGPURenderer#5848
vincentfretin wants to merge 1 commit into
aframevr:masterfrom
vincentfretin:webgpu-reflection-screenshot

Conversation

@vincentfretin

Copy link
Copy Markdown
Contributor

Makes the reflection and screenshot components work with WebGPURenderer (three.webgpu.js build, see #5749 for context).

Changes

  • Cube render target: WebGLCubeRenderTarget is not exported by the three.webgpu.js build, which uses CubeRenderTarget instead. Both components now select the class at runtime with the same trick a-scene uses to select the renderer implementation, so webpack can't statically resolve the export. This also removes the WebGLCubeRenderTarget webpack warning when building with WEBGPU=true. THREE.CubeCamera works unchanged with either target.
  • Equirectangular projection: WebGPURenderer does not support RawShaderMaterial/ShaderMaterial (not in its node library). When THREE.TSL is available, the cubemap-to-equirectangular projection is built as a MeshBasicNodeMaterial with TSL nodes implementing the same longitude/latitude math as the GLSL shaders; the cube texture is swapped per capture through the texture node's .value.
  • Pixel readback: WebGPURenderer only supports asynchronous read back. renderCapture uses readRenderTargetPixelsAsync when readRenderTargetPixels is not available. getCanvas() still returns the canvas synchronously with WebGLRenderer (no breaking change) and returns a Promise resolving to the canvas with WebGPURenderer (documented in screenshot.md). capture() works on both.
  • RGBAFormat: the equirect cube render target used RGBFormat, which is not color-renderable with the WebGL 2 backend of WebGPURenderer (incomplete framebuffer, black capture). Switched to RGBAFormat; the projection outputs alpha 1 and the readback path already assumed 4 bytes per pixel.

Verification

Tested with a scene with distinct sky/box/ground colors on both builds (npm run dev and npm run start:webgpu) driving headless Chrome, probing pixels of the resulting canvas:

  • Perspective and equirectangular captures produce identical colors/orientation on WebGLRenderer and on WebGPURenderer (WebGL 2 fallback backend — no WebGPU adapters on Linux Chrome).
  • The reflection component sets a live cube texture as scene.environment on both renderers without errors.
  • Scene component tests and lint pass.

Note: the actual WebGPU backend readback couldn't be tested on Linux; worth a quick check of equirect orientation in a desktop Chrome with WebGPU support.

ar-hit-test.js uses the same readRenderTargetPixels pattern but is WebXR-only, so it's left untouched until WebXR support lands for WebGPURenderer.

🤖 Generated with Claude Code

- Use CubeRenderTarget with WebGPURenderer (WebGLCubeRenderTarget is not
  exported by the three.webgpu.js build), selected at runtime like the
  renderer implementation in a-scene. This also removes a webpack warning
  when building with WEBGPU=true.
- WebGPURenderer does not support RawShaderMaterial; the equirectangular
  cubemap-to-equirect projection is implemented with TSL nodes when
  THREE.TSL is available.
- WebGPURenderer only supports asynchronous pixels read back, use
  readRenderTargetPixelsAsync when readRenderTargetPixels is not
  available. getCanvas() returns a Promise resolving to the canvas with
  WebGPURenderer; it still returns the canvas synchronously with
  WebGLRenderer.
- Use RGBAFormat instead of RGBFormat for the cube render target;
  RGBFormat is not color-renderable with the WebGL 2 backend of
  WebGPURenderer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vincentfretin

Copy link
Copy Markdown
Contributor Author

Testing help wanted: on this machine I could only verify WebGPURenderer running on its WebGL 2 fallback backend (Chrome on Linux has no WebGPU adapters). If someone has a machine with WebGPU support (chrome://gpu shows WebGPU: Hardware accelerated), could you test this PR with the actual WebGPU backend?

gh pr checkout 5848
# or without the GitHub CLI:
# git fetch https://github.com/vincentfretin/aframe.git webgpu-reflection-screenshot && git checkout FETCH_HEAD
npm ci
npm run dist
npm run start:webgpu

Then open https://localhost:8080/examples/ (accept the self-signed certificate), pick any example and check in the devtools console that the WebGPU backend is really active:

AFRAME.scenes[0].renderer.backend.isWebGPUBackend // should be true

Things to verify:

  • <ctrl> + <alt> + s: perspective screenshot downloads, correct content, not upside down.
  • <ctrl> + <alt> + <shift> + s: equirectangular screenshot, correct content and orientation. This exercises the new TSL projection material and the async pixels read back, and is the part I couldn't fully verify: the readback orientation could differ between the WebGPU backend and the WebGL 2 fallback backend.
  • Reflection: run document.querySelector('a-scene').setAttribute('reflection', '') in the console, check there is no error and AFRAME.scenes[0].object3D.environment is set.

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.

1 participant