Colour grade: the source
Open the live demo · Read the guide · View on GitHub
Regions the guide quotes: whole (line 49), ranges (line 52), lens (line 54).
1/// A colour grade: contrast, saturation and warmth for the whole picture, a tint
2/// for the shadows and another for the highlights, and the marks a lens leaves.
3///
4/// Quoted by `color_grading.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 `color-grading` page: the post stage through a grade and the marks of
12/// a lens. Its check is that the composite pass, which grades, ran.
13final class ColorGradingDemo extends ShowcaseDemo {
14 /// The grade's contrast, 0.5 to 1.8; 1 leaves it as drawn.
15 double contrast = 1.15;
17 /// The grade's saturation, 0 to 2; 0 is grey and 1 leaves it as drawn.
18 double saturation = 1.2;
20 /// The grade's warmth, -1 (cooler) to 1 (warmer).
21 double temperature = 0.15;
23 /// How much blue is lifted into the shadows, 0 to 0.15.
24 double coolShadows = 0.03;
26 /// How much the highlights' gain is pushed to red, and less to green, 0 to
27 /// 0.5.
28 double warmHighlights = 0.15;
30 /// How dark the corners go, 0 to 1.
31 double vignette = 0.45;
33 /// How strong the film grain is, 0 to 0.1.
34 double grain = 0.03;
36 /// How far the colours fringe apart towards the edges, 0 to 0.015; the
37 /// grade's `chromaticAberration`.
38 double aberration = 0.004;
41 void configureView(DemoContext context) => PostStage.frame(context);
44 Scene build(DemoContext context) => PostStage.build(context).scene;
47 RenderSettings settings(DemoContext context) => RenderSettings(
48 look: LookSettings(
49 contrast: contrast,
50 saturation: saturation,
51 temperature: temperature,
52 lift: LinearColor(0.0, 0.0, coolShadows),
53 gain: LinearColor(1.0 + warmHighlights, 1.0 + warmHighlights * 0.4, 1.0),
54 vignette: vignette,
55 grain: grain,
56 chromaticAberration: aberration,
57 ),
58 );
61 List<DemoControl> controls(DemoContext context) => <DemoControl>[
62 SliderControl(
63 'Contrast',
64 min: 0.5,
65 max: 1.8,
66 value: () => contrast,
67 onChanged: (double v) => contrast = v,
68 ),
69 SliderControl(
70 'Saturation',
71 min: 0,
72 max: 2,
73 value: () => saturation,
74 onChanged: (double v) => saturation = v,
75 ),
76 SliderControl(
77 'Temperature',
78 min: -1,
79 max: 1,
80 value: () => temperature,
81 onChanged: (double v) => temperature = v,
82 ),
83 SliderControl(
84 'Cool shadows',
85 min: 0,
86 max: 0.15,
87 value: () => coolShadows,
88 onChanged: (double v) => coolShadows = v,
89 ),
90 SliderControl(
91 'Warm highlights',
92 min: 0,
93 max: 0.5,
94 value: () => warmHighlights,
95 onChanged: (double v) => warmHighlights = v,
96 ),
97 SliderControl(
98 'Vignette',
99 min: 0,
100 max: 1,
101 value: () => vignette,
102 onChanged: (double v) => vignette = v,
103 ),
104 SliderControl(
105 'Grain',
106 min: 0,
107 max: 0.1,
108 value: () => grain,
109 onChanged: (double v) => grain = v,
110 ),
111 SliderControl(
112 'Colour fringe',
113 min: 0,
114 max: 0.015,
115 value: () => aberration,
116 onChanged: (double v) => aberration = v,
117 format: (double v) => v.toStringAsFixed(3),
118 ),
119 ];
122 void verify(Scene scene, FrameResult frame) {
123 if (!passRan(frame, 'composite')) {
124 throw StateError('the composite pass, which grades the frame, is absent');
125 }
126 }
127}