flutter3d
Showcase Changelog 62 packages API reference

Ambient occlusion: the source

since 0.2.0 Post-processing

Regions the guide quotes: ambient (line 28), settings (line 35), ran (line 64).

1/// Ambient occlusion: the ambient term darkened wherever a surface cannot see
2/// much of the sky.
3///
4/// Quoted by `ambient_occlusion.md` and shown whole in the Source tab.
5library;
6
7import 'package:flutter3d/flutter3d.dart';
8import 'package:flutter3d_showcase/pages/post/post_stage.dart';
9import 'package:flutter3d_showcase/src/demo/demo.dart';
11/// The `ambient-occlusion` page: the post stage with screen-space ambient
12/// occlusion. Its check is that the pass ran, and its blur too when taps are
13/// asked for.
14final class AmbientOcclusionDemo extends ShowcaseDemo {
15 /// How dark the occlusion makes the ambient term, 0 to 1.
16 double strength = 0.9;
18 /// How many taps the blur after the occlusion takes, 0 to 8; 0 skips the
19 /// blur pass.
20 int blurTaps = 0;
22 @override
23 void configureView(DemoContext context) =>
24 PostStage.frame(context, distance: 6.0);
26 @override
27 Scene build(DemoContext context) {
28 final Scene scene = PostStage.build(context).scene;
29 scene.ambientIntensity = 0.6 * LightNode.legacyUnit;
30 return scene;
31 }
33 @override
34 RenderSettings settings(DemoContext context) => RenderSettings(
35 ambientOcclusion: AmbientOcclusionSettings(
36 enabled: true,
37 strength: strength,
38 blurTaps: blurTaps,
39 ),
40 );
42 @override
43 List<DemoControl> controls(DemoContext context) => <DemoControl>[
44 SliderControl(
45 'Strength',
46 min: 0,
47 max: 1,
48 value: () => strength,
49 onChanged: (double v) => strength = v,
50 ),
51 SliderControl(
52 'Blur taps',
53 min: 0,
54 max: 8,
55 divisions: 8,
56 value: () => blurTaps.toDouble(),
57 onChanged: (double v) => blurTaps = v.round(),
58 format: (double v) => '${v.round()}',
59 ),
60 ];
62 @override
63 void verify(Scene scene, FrameResult frame) {
64 if (!passRan(frame, 'ssao')) {
65 throw StateError('the ssao pass did not run: ${frame.skipped}');
66 }
67 if (blurTaps > 0 && !passRan(frame, 'ssao blur')) {
68 throw StateError(
69 'blur taps were asked for and the blur pass did not run',
70 );
71 }
72 }