WebGPU
Explore experimental WebGPU rendering capabilities in TresJS.
Experimental Feature: WebGPU support in TresJS is experimental and requires modern browser support. WebGPU is still being developed and may have breaking changes.
What is WebGPU?
WebGPU is the next-generation graphics API for the web, designed to provide high-performance 3D graphics and general-purpose computing capabilities directly in web browsers. It offers several advantages over WebGL:
Key Benefits
- Better Performance: More efficient GPU utilization and reduced CPU overhead
- Modern GPU Features: Access to compute shaders, advanced texturing, and modern GPU capabilities
- Unified API: Single API for both graphics and compute operations
- Better Debugging: Improved error handling and debugging capabilities
- Future-Proof: Designed for modern GPU architectures
Browser Support
WebGPU is currently supported in:
- Chrome/Edge: Stable support (Chrome 113+)
- Firefox: Behind experimental flag
- Safari: Experimental support in Safari Technology Preview
Check current WebGPU browser support at Can I Use WebGPU and the official wiki.
Usage with TresJS
TresJS supports WebGPU through Three.js's WebGPU renderer. You can enable WebGPU by providing a custom renderer factory to the <TresCanvas>
component.
Basic Setup
basic-webgpu.vue
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { WebGPURenderer } from 'three/webgpu'
import type { TresRendererSetupContext } from '@tresjs/core'
// Create WebGPU renderer factory
const createWebGPURenderer = (ctx: TresRendererSetupContext) => {
const renderer = new WebGPURenderer({
canvas: toValue(ctx.canvas),
// WebGPU specific configuration
alpha: true,
antialias: true,
})
return renderer
}
</script>
<template>
<TresCanvas :renderer="createWebGPURenderer">
<TresPerspectiveCamera :position="[3, 3, 3]" />
<TresBoxGeometry :args="[1, 1, 1]" />
<TresMeshBasicMaterial color="hotpink" />
<!-- Your 3D scene here -->
</TresCanvas>
</template>
Advanced WebGPU Example
app.vue
<script setup lang="ts">
import { TresCanvas } from '@tresjs/core'
import { WebGPURenderer } from 'three/webgpu'
import type { ShadowMapType, ToneMapping } from 'three'
import type { TresRendererSetupContext } from '@tresjs/core'
import HologramCube from './HologramCube.vue'
const createWebGPURenderer = (ctx: TresRendererSetupContext) => {
const renderer = new WebGPURenderer({
canvas: toValue(ctx.canvas),
// WebGPU specific configuration
alpha: true,
antialias: true,
})
return renderer
}
</script>
<template>
<TresCanvas :renderer="createWebGPURenderer">
<TresPerspectiveCamera
:position="[3, 3, 3]"
:look-at="[0, 0, 0]"
/>
<Suspense>
<HologramCube />
</Suspense>
</TresCanvas>
</template>
Primitives
Use the primitive component to directly integrate any Three.js object within your Vue application.
Cookbook ๐ณ๐งโ๐ณ
Discover guided recipes to help you get started with the basics of using Tres. Each recipe is designed to help you understand the core concepts of Tres and how to use them in your projects.