WebGPURenderer

This example shows how to run the experimental Three.js WebGPURenderer renderer with Threlte’s <Canvas>.

Adapted from this Three.js example.

In a browser that supports WebGPU, such as Chrome, this example will default to the new WebGPURenderer. In other browsers, it will fallback to a WebGL Renderer.

Vite

The WebGPURenderer uses top-level async to determine WebGPU compatibility. Vite will often throw an error when it detects top level await.

To circumvent this issue, the following can be added to your Vite config.

// vite.config.js
optimizeDeps: {
  esbuildOptions: {
    target: 'esnext'
  }
},
build: {
  target: 'esnext'
}

Alternatively, vite-plugin-top-level-await can be used, although less success has been reported with this method.