Use case
flutter.assets entries can declare transformers for build-time processing. flutter.shaders historically only accepted a list of paths, which makes it hard to apply the same build-time transformation pipeline to fragment shaders.
When porting existing shaders (e.g. Shadertoy/GLSL Sandbox style sources) to Flutter runtime effects, developers often need to inject Flutter-specific boilerplate (headers/uniforms + an entrypoint bridge) while keeping the upstream shader logic intact.
Without build-time transformers for shaders, developers must either:
- manually edit shader sources (hard to keep in sync with upstream), or
- maintain duplicated “Flutterized” copies (noise + churn).
Implemented (PR)
PR: #181889
This PR extends flutter.shaders to support the same map form used by assets entries, including transformers.
YAML sketch:
...
flutter:
shaders:
# Legacy string format (backwards compatible)
- shaders/simple.frag
# New map format with transformers
- path: assets/shaders/shadertoy_port.frag
transformers:
- package: shadertoy_transpiler
# args: [...] (optional, same as assets)
...
Semantics:
- If a shader entry declares
transformers, the transformer pipeline runs first.
- The shader compiler (
impellerc) is then invoked on the transformed output.
Backwards compatibility:
- The legacy string-list format remains supported.
- Only shader entries that explicitly declare
transformers are transformed.
Non-goals:
- No change to
impellerc / shader language compatibility.
- No Shadertoy-specific behavior in Flutter itself — this only enables a build-time hook.
- No change to built-in/material shaders.
Tests
Added flutter_tools unit tests to verify:
- transformers are invoked for shader entries that declare them
impellerc compiles the transformed output
- built-in/material shaders are not affected
Local verification command:
cd $FLUTTER_ROOT/packages/flutter_tools
FLUTTER_ROOT=$FLUTTER_ROOT ../../bin/cache/dart-sdk/bin/dart pub get
FLUTTER_ROOT=$FLUTTER_ROOT ../../bin/cache/dart-sdk/bin/dart test \
test/general.shard/flutter_manifest_test.dart \
test/general.shard/build_system/targets/assets_test.dart \
-r expanded
Optional example
I also put together a minimal example repo demonstrating how to declare shader transformers in pubspec.yaml and how the transformer output is used during shader compilation:
This is optional reference material; the implementation and tests live entirely in the Flutter repo.
Use case
flutter.assetsentries can declaretransformersfor build-time processing.flutter.shadershistorically only accepted a list of paths, which makes it hard to apply the same build-time transformation pipeline to fragment shaders.When porting existing shaders (e.g. Shadertoy/GLSL Sandbox style sources) to Flutter runtime effects, developers often need to inject Flutter-specific boilerplate (headers/uniforms + an entrypoint bridge) while keeping the upstream shader logic intact.
Without build-time transformers for shaders, developers must either:
Implemented (PR)
PR: #181889
This PR extends
flutter.shadersto support the same map form used by assets entries, includingtransformers.YAML sketch:
...
flutter:
shaders:
# Legacy string format (backwards compatible)
- shaders/simple.frag
...
Semantics:
transformers, the transformer pipeline runs first.impellerc) is then invoked on the transformed output.Backwards compatibility:
transformersare transformed.Non-goals:
impellerc/ shader language compatibility.Tests
Added
flutter_toolsunit tests to verify:impellerccompiles the transformed outputLocal verification command:
Optional example
I also put together a minimal example repo demonstrating how to declare shader transformers in
pubspec.yamland how the transformer output is used during shader compilation:This is optional reference material; the implementation and tests live entirely in the Flutter repo.