flutter3d
Showcase Changelog 38 packages API reference

Switching passes off: the source

since 0.7.0 Post-processing

Regions the guide quotes: names (line 11), disabled (line 42), report (line 58).

1/// Switching a pass off by its name, and asking the frame what became of it.
2///
3/// Quoted by `disabled_passes.md` and shown whole in the Source tab.
4library;
5
6import 'package:flutter3d/flutter3d.dart';
7import 'package:flutter3d_showcase/pages/post/post_stage.dart';
8import 'package:flutter3d_showcase/src/demo/demo.dart';
9
10final class DisabledPassesDemo extends ShowcaseDemo {
11 /// The passes this scene turns on, in the order the frame runs them.
12 static final List<String> switchable = <String>[
13 for (final String name in RenderSettings.passOrder)
14 if (const <String>{
15 'directional shadows',
16 'ssao',
17 'contact shadows',
18 'bloom',
19 'antialias',
20 }.contains(name))
21 name,
22 ];
24 final Set<String> disabled = <String>{'bloom'};
26 @override
27 void configureView(DemoContext context) => PostStage.frame(context);
29 @override
30 Scene build(DemoContext context) =>
31 PostStage.build(context, shadows: true).scene;
33 @override
34 RenderSettings settings(DemoContext context) => RenderSettings(
35 ambientOcclusion: const AmbientOcclusionSettings(
36 enabled: true,
37 radius: 0.8,
38 ),
39 contactShadows: const ContactShadowSettings(enabled: true),
40 antiAlias: const AntiAliasSettings(enabled: true),
41 bloom: const BloomSettings(intensity: 0.3),
42 disabledPasses: <String>{...disabled},
43 );
45 @override
46 List<DemoControl> controls(DemoContext context) => <DemoControl>[
47 for (final String name in switchable)
48 ToggleControl(
49 'Skip $name',
50 value: () => disabled.contains(name),
51 onChanged: (bool skip) =>
52 skip ? disabled.add(name) : disabled.remove(name),
53 ),
54 ];
56 @override
57 void verify(Scene scene, FrameResult frame) {
58 for (final String name in disabled) {
59 final PassSkip? why = frame.skipReasonOf(name);
60 if (why != PassSkip.disabled) {
61 throw StateError('"$name" was named and the frame says $why');
62 }
63 }
64 if (!passRan(frame, 'composite')) {
65 throw StateError('the composite pass is the frame and it did not run');
66 }
67 }