VTK::RenderingWebGPU#
vtkRenderingWebGPU - WebGPU Backend for Rendering#
Description#
This module contains the WebGPU native backend for RenderingCore. Currently, it supports rendering polygonal geometry in different representations with point/cell scalar-mapped colors.
When both the RenderingOpenGL2 and RenderingWebGPU libraries are linked, the user must provide preferences to select the rendering backend at runtime. This can be done in two ways:
Pass command line arguments to your application
--vtk-factory-prefer RenderingBackend=WebGPUor--vtk-factory-prefer RenderingBackend=OpenGL2. Then, you will need to invokevtkObjectFactory::InitializePreferencesFromCommandLineArgs(argc, argv)in your main function before creating any VTK object.Alternatively, set the
VTK_FACTORY_PREFERenvironment variable toRenderingBackend=WebGPUorRenderingBackend=OpenGL2.
Building VTK with Dawn (Highly Experimental)#
Prerequisites#
Git
tools for building VTK
This module uses Dawn’s C++ WebGPU implementation on desktop and the emdawnwebgpu subcomponent for wasm (automatically fetched by emscripten with --use-port=emdawnwebgpu flag)
Cloning and Building Dawn#
Dawn should be built at tag v20250621.085109.
# Clone the repo and checkout the required version
git clone https://github.com/google/dawn dawn && cd dawn
git checkout v20250621.085109
Build Dawn with CMake and Ninja#
cmake -S . -B out/Debug -GNinja -DDAWN_FETCH_DEPENDENCIES=ON -DDAWN_ENABLE_INSTALL=ON
cmake --build out/Debug
cmake --install out/Debug --prefix /path/to/install/dawn
Configuring and Building VTK#
When configuring VTK’s build for wasm, configure with:
cmake \
-S /path/to/vtk/src \
-B /path/to/vtk/build \
-GNinja \
-DVTK_ENABLE_WEBGPU=ON \
-DVTK_BUILD_TESTING=ON
cmake --build
When building on desktop (x86_64/aarch64), configure with:
cmake \
-S /path/to/vtk/src \
-B /path/to/vtk/build \
-GNinja \
-DVTK_ENABLE_WEBGPU=ON \
-DDawn_DIR=/path/to/where/dawn/is/installed/lib/cmake/Dawn \
-DVTK_BUILD_TESTING=ON
cmake --build
Running Tests#
WebGPU Tests#
./bin/vtkRenderingWebGPUCxxTests
Available tests:
0. TestActorFaceCullingProperty
1. TestAxesActor
2. TestCellScalarMappedColors
3. TestCompositePolyDataMapper
..
..
Rendering Core Tests#
To run the RenderingCore tests with VTK::RenderingWebGPU, edit vtk.module to link unit tests with TEST_DEPENDS:
Uncomment the module name under
TEST_DEPENDS.Rebuild and run the tests (only a few pass currently).
Set the
VTK_FACTORY_PREFERenvironment variable toRenderingBackend=WebGPUor pass--vtk-factory-prefer RenderingBackend=WebGPUas command line arguments to the test executable.
export VTK_FACTORY_PREFER="RenderingBackend=WebGPU"
./bin/vtkRenderingCoreCxxTests Mace -I
or
./bin/vtkRenderingCoreCxxTests Mace -I --vtk-factory-prefer RenderingBackend=WebGPU
Features#
The following features are currently implemented:
vtkPolyData Rendering: Supports point, line, and triangle primitives.
Glyph Rendering: Supports point, line, and triangle primitives.
Composite vtkPolyData Rendering: Supports point, line, and triangle primitives.
Scalar Mapped Coloring:
Point scalar mapped coloring of surfaces.
Cell scalar mapped coloring.
Actor Representations:
VTK_POINTSVTK_WIREFRAMEVTK_SURFACEVTK_SURFACEwith edge visibility
Lighting:
Based on VTK headlights.
Supports point/cell normals.
Rendering Adjustments:
Point size adjustments.
Line width adjustments for wireframe and surface with edges.
Depth Testing: Enables correct rendering of 3D objects.
Selections: Hardware selector can pick cells, composite datasets and actors.
Compute Shader API#
The compute shader API allows offloading work from the CPU to the GPU using WebGPU compute shaders.
User-level information: Compute API User Guide
Developer-level information: Compute API Developer Guide
Future Work#
Since WebGPU is already an abstraction over graphics APIs, this module avoids creating another level of abstraction. It leverages WebGPU’s C++ flavor for its object-oriented API and RAII. Helper classes in the vtkWebGPUInternals... files ensure cleaner bind group initialization code.
Planned improvements include:
Volume mappers
Textures
Dual-depth peeling
Advanced lighting
Platform-native render windows for Windows, macOS, Android, iOS and wayland.
References#
Here are some valuable resources for learning WebGPU:
-
Complete introduction to using WebGPU
-
Builds an efficient glTF renderer in WebGPU using JavaScript.
Discusses various rendering pitfalls and optimizations.
-
A collection of single-file examples demonstrating various WebGPU use cases in C.
-
Similar to LearnOpenGL and Vulkan tutorials.
Covers window setup, triangle rendering, buffers, textures, and 3D rendering.
-
Beginner-friendly tutorial using wgpu.rs.
-
Introductory tutorial covering WebGPU concepts using JavaScript.
How to Render a WebGPU Triangle (Series)
Explains swapchain and image presentation in detail.
-
A well-organized WebGPU API and WGSL summary.
For WGSL specification, refer to: WGSL Spec