Auto exposure: the source
Open the live demo · Read the guide · View on GitHub
Regions the guide quotes: seed (line 33), auto (line 34), reads (line 69).
1/// Auto exposure: a meter reads the frame's own brightness and the next
2/// frame is exposed by what it found.
3///
4/// Quoted by `auto_exposure.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 `auto-exposure` page: the post stage exposed by a meter that reads
12/// the frame before. Its check is that the luminance pass ran and that the
13/// first frame wears the seed exposure.
14final class AutoExposureDemo extends ShowcaseDemo {
15 /// The grey the meter exposes the frame towards, 0.05 to 0.4.
16 double target = 0.18;
18 /// How fast the exposure adapts, 0.2 to 6, the same up and down.
19 double speed = 1.5;
21 /// The exposure the first frame is drawn at, 0.3 to 4, before anything has
22 /// been metered.
23 double seedExposure = 1.6;
26 void configureView(DemoContext context) => PostStage.frame(context);
29 Scene build(DemoContext context) => PostStage.build(context).scene;
32 RenderSettings settings(DemoContext context) => RenderSettings(
33 exposure: seedExposure,
34 autoExposure: AutoExposureSettings(
35 enabled: true,
36 target: target,
37 speedUp: speed,
38 speedDown: speed,
39 ),
40 );
43 List<DemoControl> controls(DemoContext context) => <DemoControl>[
44 SliderControl(
45 'Seed exposure',
46 min: 0.3,
47 max: 4,
48 value: () => seedExposure,
49 onChanged: (double v) => seedExposure = v,
50 ),
51 SliderControl(
52 'Target grey',
53 min: 0.05,
54 max: 0.4,
55 value: () => target,
56 onChanged: (double v) => target = v,
57 ),
58 SliderControl(
59 'Adaptation speed',
60 min: 0.2,
61 max: 6,
62 value: () => speed,
63 onChanged: (double v) => speed = v,
64 ),
65 ];
68 void verify(Scene scene, FrameResult frame) {
69 if (!passRan(frame, 'luminance')) {
70 throw StateError('the luminance pass did not run: ${frame.skipped}');
71 }
72 if ((frame.exposure - seedExposure).abs() > 1e-6) {
73 throw StateError(
74 'the first frame should wear the seed exposure, since nothing has '
75 'been metered yet; it reported ${frame.exposure}',
76 );
77 }
78 }
79}