flutter3d
Showcase Changelog 62 packages API reference

Bloom and halation: the source

since 0.1.0 Post-processing

Regions the guide quotes: lamp (line 34), glow (line 56), reach (line 58), halation (line 59).

1/// Bloom: the light that is brighter than the display spills over its edge.
2///
3/// Quoted by `bloom.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
10/// The `bloom` page: the post stage and a lamp brighter than the display.
11/// Its check is that the bloom pass ran.
12final class BloomDemo extends ShowcaseDemo {
13 /// The brightness above which light blooms, 0 to 4.
14 double threshold = 1.0;
16 /// How much of the bloom is added back to the frame, 0 to 1.5.
17 double intensity = 0.35;
19 /// How warm the wide part of the bloom is made, as film's halation makes it,
20 /// 0 to 1; the core around a highlight keeps its colour.
21 double halation = 0.0;
23 /// How many halving levels the bloom spreads over, 1 to 7: more levels
24 /// reach further.
25 int levels = 5;
27 @override
28 void configureView(DemoContext context) => PostStage.frame(context);
30 @override
31 Scene build(DemoContext context) {
32 final PostStage stage = PostStage.build(context);
34 // Hung on the side the sun comes from, so the lit faces of the shapes turn
35 // towards the glow: the lamp itself lights nothing.
36 final MeshNode lamp = MeshNode(
37 DeviceMesh.upload(
38 context.device,
39 const SphereShape(radius: 0.25, segments: 24, rings: 12).build(),
40 ),
41 RenderMaterial(
42 name: 'lamp',
43 baseColor: LinearColor.fromSrgb(0.1, 0.1, 0.1, 1.0),
44 emissive: LinearColor(1.0, 0.85, 0.6),
45 emissiveStrength: 9.0 * RenderMaterial.defaultEmissiveStrength,
46 ),
47 name: 'lamp',
48 )..setPosition(1.0, 2.3, 0.7);
50 return stage.scene..add(lamp);
51 }
53 @override
54 RenderSettings settings(DemoContext context) => RenderSettings(
55 bloom: BloomSettings(
56 threshold: threshold,
57 intensity: intensity,
58 levels: levels,
59 halation: halation,
60 ),
61 );
63 @override
64 List<DemoControl> controls(DemoContext context) => <DemoControl>[
65 SliderControl(
66 'Threshold',
67 min: 0,
68 max: 4,
69 value: () => threshold,
70 onChanged: (double v) => threshold = v,
71 ),
72 SliderControl(
73 'Intensity',
74 min: 0,
75 max: 1.5,
76 value: () => intensity,
77 onChanged: (double v) => intensity = v,
78 ),
79 SliderControl(
80 'Reach (levels)',
81 min: 1,
82 max: 7,
83 divisions: 6,
84 value: () => levels.toDouble(),
85 onChanged: (double v) => levels = v.round(),
86 format: (double v) => '${v.round()}',
87 ),
88 SliderControl(
89 'Halation',
90 min: 0,
91 max: 1,
92 value: () => halation,
93 onChanged: (double v) => halation = v,
94 ),
95 ];
97 @override
98 void verify(Scene scene, FrameResult frame) {
99 if (!passRan(frame, 'bloom')) {
100 throw StateError('the bloom pass did not run: ${frame.skipped}');
101 }
102 }