flutter3d
Showcase Changelog 38 packages API reference

Ambient occlusion: the source

since 0.2.0 Post-processing

Regions the guide quotes: ambient (line 21), settings (line 28), ran (line 57).

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';
11final class AmbientOcclusionDemo extends ShowcaseDemo {
12 double strength = 0.9;
13 int blurTaps = 0;
15 @override
16 void configureView(DemoContext context) =>
17 PostStage.frame(context, distance: 6.0);
19 @override
20 Scene build(DemoContext context) {
21 final Scene scene = PostStage.build(context).scene;
22 scene.ambientIntensity = 0.6;
23 return scene;
24 }
26 @override
27 RenderSettings settings(DemoContext context) => RenderSettings(
28 ambientOcclusion: AmbientOcclusionSettings(
29 enabled: true,
30 strength: strength,
31 blurTaps: blurTaps,
32 ),
33 );
35 @override
36 List<DemoControl> controls(DemoContext context) => <DemoControl>[
37 SliderControl(
38 'Strength',
39 min: 0,
40 max: 1,
41 value: () => strength,
42 onChanged: (double v) => strength = v,
43 ),
44 SliderControl(
45 'Blur taps',
46 min: 0,
47 max: 8,
48 divisions: 8,
49 value: () => blurTaps.toDouble(),
50 onChanged: (double v) => blurTaps = v.round(),
51 format: (double v) => '${v.round()}',
52 ),
53 ];
55 @override
56 void verify(Scene scene, FrameResult frame) {
57 if (!passRan(frame, 'ssao')) {
58 throw StateError('the ssao pass did not run: ${frame.skipped}');
59 }
60 if (blurTaps > 0 && !passRan(frame, 'ssao blur')) {
61 throw StateError(
62 'blur taps were asked for and the blur pass did not run',
63 );
64 }
65 }