Viewport shading: the source
Open the live demo · Read the guide · View on GitHub
Regions the guide quotes: settings (line 27), ran (line 42).
1/// Viewport shading: normals, clay, outline and curvature, each read out of
2/// the surface buffer instead of the materials.
3///
4/// Quoted by `viewport_shading.md` and shown whole in the Source tab.
5library;
7import 'package:flutter3d/flutter3d.dart';
8import 'package:flutter3d_showcase/pages/post/post_stage.dart';
9import 'package:flutter3d_showcase/src/demo/demo.dart';
11/// The `viewport-shading` page: the post stage drawn in a viewport shading
12/// mode. Its check is that the mode picked ran, and that off runs nothing.
13final class ViewportShadingDemo extends ShowcaseDemo {
14 /// Which mode is drawn, an index into the "Mode" choice.
15 int mode = 1;
17 static const List<ViewportShading> _modes = ViewportShading.values;
20 void configureView(DemoContext context) => PostStage.frame(context);
23 Scene build(DemoContext context) => PostStage.build(context).scene;
26 RenderSettings settings(DemoContext context) => RenderSettings(
27 viewportShading: ViewportShadingSettings(mode: _modes[mode]),
28 );
31 List<DemoControl> controls(DemoContext context) => <DemoControl>[
32 ChoiceControl(
33 'Mode',
34 options: <String>[for (final ViewportShading m in _modes) m.name],
35 index: () => mode,
36 onChanged: (int i) => mode = i,
37 ),
38 ];
41 void verify(Scene scene, FrameResult frame) {
42 final ViewportShading picked = _modes[mode];
43 final bool ran = frame.passes.any(
44 (FramePass p) => p.name == 'viewport shading',
45 );
46 if (picked == ViewportShading.off) {
47 if (ran) throw StateError('off should not run the pass');
48 } else if (!ran) {
49 throw StateError('$picked did not run: ${frame.skipped}');
50 }
51 }
52}