flutter3d
Showcase Changelog 62 packages API reference

Spatial upscaling: the source

since 0.8.0 Post-processing

Regions the guide quotes: stage (line 30), settings (line 34), runs (line 68).

1/// Spatial upscaling: a frame drawn below full size brought up to it by an
2/// edge-directed filter instead of a plain stretch.
3///
4/// Quoted by `spatial_upscale.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 `spatial-upscale` page: the post stage drawn small and brought up to
12/// full size. Its check is that the upscale ran or was declined when it is
13/// on, and never when the frame is full size.
14final class SpatialUpscaleDemo extends ShowcaseDemo {
15 /// Whether the edge-directed upscale runs rather than a plain stretch.
16 bool upscale = true;
18 /// The scale the frame is drawn at, 0.25 to 1.
19 double renderScale = 0.5;
21 /// How much the upscale sharpens, 0 to 1.
22 double sharpen = 0.2;
24 @override
25 void configureView(DemoContext context) =>
26 PostStage.frame(context, distance: 6.0);
28 @override
29 Scene build(DemoContext context) {
30 final Scene scene = PostStage.build(context, shadows: true).scene;
31 return scene;
32 }
34 RenderSettings _settings() => RenderSettings(
35 renderScale: renderScale,
36 spatialUpscale: SpatialUpscaleSettings(enabled: upscale, sharpen: sharpen),
37 );
39 @override
40 RenderSettings settings(DemoContext context) => _settings();
42 @override
43 List<DemoControl> controls(DemoContext context) => <DemoControl>[
44 ToggleControl(
45 'Upscale',
46 value: () => upscale,
47 onChanged: (bool v) => upscale = v,
48 ),
49 SliderControl(
50 'Render scale',
51 min: 0.25,
52 max: 1,
53 value: () => renderScale,
54 onChanged: (double v) => renderScale = v,
55 format: (double v) => '${(v * 100).round()}%',
56 ),
57 SliderControl(
58 'Sharpen',
59 min: 0,
60 max: 1,
61 value: () => sharpen,
62 onChanged: (double v) => sharpen = v,
63 ),
64 ];
66 @override
67 void verify(Scene scene, FrameResult frame) {
68 if (SpatialUpscaleSettings.runsFor(_settings())) {
69 expectPassOrDecline(frame, 'spatial upscale');
70 } else if (passRan(frame, 'spatial upscale')) {
71 throw StateError('the upscale ran on a frame that does not need it');
72 }
73 }