Specular strength: the source
Open the live demo · Read the guide · View on GitHub
Regions the guide quotes: material (line 28), light (line 45), settings (line 55), check (line 71).
1/// `RenderSettings.specular`: one scalar that turns the whole frame's
2/// specular response up or down without touching a single material.
3///
4/// Quoted by `specular_scale.md` and shown whole in the Source tab.
5library;
7import 'package:flutter3d/flutter3d.dart';
8import 'package:flutter3d_showcase/src/demo/demo.dart';
10/// The `specular-scale` page: a shiny ball under a sun. Its check is that the
11/// ball is shiny enough to show a highlight.
12final class SpecularScaleDemo extends ShowcaseDemo {
13 /// The frame's specular scale, 0 to 3; 1 leaves every material as it is.
14 double specular = 1.5;
16 late final RenderMaterial _ball;
17 late final LightNode _sun;
20 void configureView(DemoContext context) {
21 context.orbit
22 ..distance = 4.5
23 ..pitch = 0.15;
24 }
27 Scene build(DemoContext context) {
28 _ball = RenderMaterial(
29 name: 'ball',
30 lighting: LightingModel.pbr,
31 baseColor: LinearColor.fromSrgb(0.75, 0.2, 0.2, 1.0),
32 metallic: 0.9,
33 roughness: 0.18,
34 );
36 final MeshNode ball = MeshNode(
37 DeviceMesh.upload(
38 context.device,
39 SphereShape(segments: 48, rings: 24).build(),
40 ),
41 _ball,
42 name: 'ball',
43 );
45 _sun = LightNode(name: 'sun', intensity: 3.0 * LightNode.legacyUnit)
46 ..setLocalForward(Vector3(-0.3, -0.6, -0.7));
48 return Scene()
49 ..add(ball)
50 ..add(_sun);
51 }
54 RenderSettings settings(DemoContext context) => RenderSettings(
55 specular: specular,
56 );
59 List<DemoControl> controls(DemoContext context) => <DemoControl>[
60 SliderControl(
61 'Specular',
62 min: 0,
63 max: 3,
64 value: () => specular,
65 onChanged: (double v) => specular = v,
66 ),
67 ];
70 void verify(Scene scene, FrameResult frame) {
71 if (_ball.metallic < 0.5 || _ball.roughness > 0.4) {
72 throw StateError('the ball is not shiny enough to show a highlight');
73 }
74 if (frame.drawCalls < 1) {
75 throw StateError('the ball was not drawn');
76 }
77 }
78}