Specular strength: the source
Open the live demo · Read the guide · View on GitHub
Regions the guide quotes: material (line 26), light (line 43), settings (line 53), check (line 69).
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';
9import 'package:vector_math/vector_math.dart';
11final class SpecularScaleDemo extends ShowcaseDemo {
12 double specular = 1.5;
14 late final Material _ball;
15 late final LightNode _sun;
18 void configureView(DemoContext context) {
19 context.orbit
20 ..distance = 4.5
21 ..pitch = 0.15;
22 }
25 Scene build(DemoContext context) {
26 _ball = Material(
27 name: 'ball',
28 lighting: LightingModel.pbr,
29 baseColor: Vector4(0.75, 0.2, 0.2, 1.0),
30 metallic: 0.9,
31 roughness: 0.18,
32 );
34 final MeshNode ball = MeshNode(
35 DeviceMesh.upload(
36 context.device,
37 SphereShape(segments: 48, rings: 24).build(),
38 ),
39 _ball,
40 name: 'ball',
41 );
43 _sun = LightNode(name: 'sun', intensity: 3.0)
44 ..setLocalForward(Vector3(-0.3, -0.6, -0.7));
46 return Scene()
47 ..add(ball)
48 ..add(_sun);
49 }
52 RenderSettings settings(DemoContext context) => RenderSettings(
53 specular: specular,
54 );
57 List<DemoControl> controls(DemoContext context) => <DemoControl>[
58 SliderControl(
59 'Specular',
60 min: 0,
61 max: 3,
62 value: () => specular,
63 onChanged: (double v) => specular = v,
64 ),
65 ];
68 void verify(Scene scene, FrameResult frame) {
69 if (_ball.metallic < 0.5 || _ball.roughness > 0.4) {
70 throw StateError('the ball is not shiny enough to show a highlight');
71 }
72 if (frame.drawCalls < 1) {
73 throw StateError('the ball was not drawn');
74 }
75 }
76}