Skip to content

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.

Run or build your Flutter app for the web as usual:

Terminal window
flutter run -d chrome
# or
flutter build web

Serve the app with the headers in Cross-origin isolation.

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: webgpu

For 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),
);

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.

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:

Terminal window
flutter run -d chrome \
--web-header=Cross-Origin-Opener-Policy=same-origin \
--web-header=Cross-Origin-Embedder-Policy=require-corp

For 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-origin

In a standalone Dart app, run this command before compiling the app to WebAssembly.

Terminal window
dart run thermion_dart:download_web --backend webgpu

Use --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 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: true

Extract the matching Filament release archive into thermion_dart/native/web/lib/release. For WebGL2, build from thermion_dart/native/web.

Terminal window
emcmake cmake -S . -B build
cmake --build build

For webgpu or hybrid, use the WebGPU Filament archive and build from the same directory.

Terminal window
emcmake cmake -S . -B build-webgpu -DTHERMION_ENABLE_WEBGPU=ON
cmake --build build-webgpu

With 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.

See Thermion running in the browser in the live examples on the overview, or open the full-screen gallery.