Web
Thermion uses a prebuilt WebAssembly engine in the browser. In a Flutter
build, the build hook copies thermion_dart.js and thermion_dart.wasm into
web/. For a standalone Dart app, stage them with
download_web.
Quick start
Section titled “Quick start”Run or build your Flutter app for the web as usual:
flutter run -d chrome# orflutter build webServe the app with the headers in Cross-origin isolation.
Choose a backend
Section titled “Choose a backend”The build hook and download_web default to WebGL2 with GLSL materials.
In a Flutter app’s pubspec.yaml, set backend.web to choose a backend.
hooks: user_defines: thermion_dart: backend: web: webgpuFor a standalone Dart app, pass one of the same values to download_web --backend.
| Build choice | Built-in shaders | Backend to pass at startup |
|---|---|---|
webgl2 (default) |
GLSL | Backend.OPENGL |
webgpu |
WGSL | Backend.WEBGPU |
hybrid |
GLSL and WGSL | Backend.OPENGL or Backend.WEBGPU |
The build setting selects what the app ships. The runtime setting selects the
renderer when you create the engine. Use hybrid to make that choice at
startup and compile any custom materials
for both backends.
The webgpu and hybrid choices use the same main-thread engine and precompiled
materials. To compile materials at runtime,
choose WebGL2 and set runtime_materials: true in Flutter or pass
--variant runtime-materials to download_web.
Import package:thermion_dart/thermion_dart.dart and
package:thermion_dart/src/filament/src/implementation/ffi_filament_app.dart.
Pass the backend when creating the engine, after loading thermion_dart.js
and initializing the bindings.
await FFIFilamentApp.create( config: FFIFilamentConfig(backend: Backend.WEBGPU),);Flutter
Section titled “Flutter”Import package:thermion_flutter/thermion_flutter.dart. In main(), set
the backend before calling runApp() or creating a Thermion viewer.
ThermionFlutterPlugin.instance.setOptions( const ThermionFlutterOptions( webOptions: WebOptions(backend: Backend.WEBGPU), ),);For a hybrid build, Flutter’s WebGpu.isSupported() can help choose a
renderer at startup. It checks whether the browser exposes WebGPU. Rendering
with WebGPU also requires a usable GPU device.
Cross-origin isolation
Section titled “Cross-origin isolation”Thermion’s browser engines use shared WebAssembly memory. Serve your app with
COOP and COEP headers to enable SharedArrayBuffer.
For local runs, pass them on the command line:
flutter run -d chrome \ --web-header=Cross-Origin-Opener-Policy=same-origin \ --web-header=Cross-Origin-Embedder-Policy=require-corpFor production, set the headers on your host. On Cloudflare Pages, add a web/_headers
file:
/* Cross-Origin-Opener-Policy: same-origin Cross-Origin-Embedder-Policy: require-corp Cross-Origin-Resource-Policy: cross-originPre-fetching the artifacts
Section titled “Pre-fetching the artifacts”In a standalone Dart app, run this command before compiling the app to WebAssembly.
dart run thermion_dart:download_web --backend webgpuUse --backend hybrid to ship both shader formats. Omit --backend for
WebGL2. The command writes to web/ by default. Use -o to choose another
directory.
Building the WASM locally
Section titled “Building the WASM locally”Building the WASM yourself is only needed if you’re modifying Thermion’s native C++ and want to test on web without bumping the pinned version and waiting for CI to rebuild the R2 artifacts.
Build the emscripten target locally and opt in via your app’s pubspec.yaml:
hooks: user_defines: thermion_dart: web_local: trueExtract the matching Filament release archive into
thermion_dart/native/web/lib/release. For WebGL2, build from
thermion_dart/native/web.
emcmake cmake -S . -B buildcmake --build buildFor webgpu or hybrid, use the WebGPU Filament archive and build from the
same directory.
emcmake cmake -S . -B build-webgpu -DTHERMION_ENABLE_WEBGPU=ONcmake --build build-webgpuWith web_local: true, the hook stages the engine from build/build/out for
the default WebGL2 build or build-webgpu/build/out for WebGPU and hybrid.
Live examples
Section titled “Live examples”See Thermion running in the browser in the live examples on the overview, or open the full-screen gallery.
