Optimize shaders
CI / quality (push) Failing after 5m56s

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-04-21 17:40:21 +02:00
parent 37e0814483
commit 9564096a5c
40 changed files with 678 additions and 1442 deletions
+24 -97
View File
@@ -30,13 +30,8 @@ class ExampleHome extends StatefulWidget {
}
class _ExampleHomeState extends State<ExampleHome> {
/// Sensor-driven controller used by the first two demo surfaces.
late final ShinyController _sensorController;
/// Manual stream used by tilt preset buttons.
late final StreamController<Offset> _externalTiltController;
/// Controller backed by [_externalTiltController].
late final ShinyController _overrideController;
double _prismatic = 0.8;
@@ -44,20 +39,7 @@ class _ExampleHomeState extends State<ExampleHome> {
double _specular = 0.8;
double _diffraction = 0.8;
double _opacity = 1.0;
HolographStyle _style = HolographStyle.crackedIce;
SparkleShapeSpec _sparkleShape = SparkleShapeSpec.none;
static const Map<String, SparkleShapeSpec> _sparkleChoices =
<String, SparkleShapeSpec>{
'None': SparkleShapeSpec.none,
'8-Point Star': SparkleShapeSpec.eightPointStar,
'5-Point Star': SparkleShapeSpec.fivePointStar,
'Rectangle': SparkleShapeSpec.rectangle,
'Diamond': SparkleShapeSpec.diamond,
'Hexagon': SparkleShapeSpec.hexagon,
'Random Polygon': SparkleShapeSpec.randomPolygon,
'Confetti': SparkleShapeSpec.confetti,
};
ShinyProfile _profile = ShinyProfile.crackedIce;
@override
void initState() {
@@ -95,13 +77,12 @@ class _ExampleHomeState extends State<ExampleHome> {
height: 120,
child: Shiny(
controller: _sensorController,
style: _style,
profile: _profile,
prismatic: _prismatic,
sparkle: _sparkle,
specular: _specular,
diffraction: _diffraction,
opacity: _opacity,
sparkleShape: _sparkleShape,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
@@ -130,8 +111,7 @@ class _ExampleHomeState extends State<ExampleHome> {
Center(
child: ShinyCard(
controller: _sensorController,
style: _style,
sparkleShape: _sparkleShape,
profile: _profile,
background: const _DemoCardBackground(),
foreground: const _RareBadge(),
prismatic: _prismatic,
@@ -143,20 +123,10 @@ class _ExampleHomeState extends State<ExampleHome> {
),
const SizedBox(height: 16),
_StylePicker(
selectedStyle: _style,
onChanged: (HolographStyle style) {
selectedProfile: _profile,
onChanged: (ShinyProfile profile) {
setState(() {
_style = style;
});
},
),
const SizedBox(height: 8),
_SparkleShapePicker(
selectedShape: _sparkleShape,
choices: _sparkleChoices,
onChanged: (SparkleShapeSpec shape) {
setState(() {
_sparkleShape = shape;
_profile = profile;
});
},
),
@@ -198,8 +168,7 @@ class _ExampleHomeState extends State<ExampleHome> {
Center(
child: ShinyCard(
controller: _overrideController,
style: _style,
sparkleShape: _sparkleShape,
profile: _profile,
prismatic: _prismatic,
sparkle: _sparkle,
specular: _specular,
@@ -258,31 +227,30 @@ class _LabeledSlider extends StatelessWidget {
}
class _StylePicker extends StatelessWidget {
/// Creates the style selection control.
const _StylePicker({
required this.selectedStyle,
required this.selectedProfile,
required this.onChanged,
});
final HolographStyle selectedStyle;
final ValueChanged<HolographStyle> onChanged;
final ShinyProfile selectedProfile;
final ValueChanged<ShinyProfile> onChanged;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text('Style'),
const Text('Profile'),
const SizedBox(height: 6),
SegmentedButton<HolographStyle>(
segments: HolographStyle.values
.map((HolographStyle style) => ButtonSegment<HolographStyle>(
value: style,
label: Text(_styleLabel(style)),
SegmentedButton<ShinyProfile>(
segments: ShinyProfile.values
.map((ShinyProfile profile) => ButtonSegment<ShinyProfile>(
value: profile,
label: Text(_profileLabel(profile)),
))
.toList(),
selected: <HolographStyle>{selectedStyle},
onSelectionChanged: (Set<HolographStyle> value) {
selected: <ShinyProfile>{selectedProfile},
onSelectionChanged: (Set<ShinyProfile> value) {
if (value.isNotEmpty) {
onChanged(value.first);
}
@@ -294,61 +262,20 @@ class _StylePicker extends StatelessWidget {
);
}
String _styleLabel(HolographStyle style) {
switch (style) {
case HolographStyle.holographicSilver:
String _profileLabel(ShinyProfile profile) {
switch (profile) {
case ShinyProfile.holographicSilver:
return 'Holographic Silver';
case HolographStyle.crackedIce:
case ShinyProfile.crackedIce:
return 'Cracked Ice';
case HolographStyle.silverMosaic:
case ShinyProfile.silverMosaic:
return 'Silver Mosaic';
case HolographStyle.superGoldVinyl:
case ShinyProfile.superGoldVinyl:
return 'Super Gold Vinyl';
}
}
}
class _SparkleShapePicker extends StatelessWidget {
/// Creates sparkle shape chips from the provided shape map.
const _SparkleShapePicker({
required this.selectedShape,
required this.choices,
required this.onChanged,
});
final SparkleShapeSpec selectedShape;
final Map<String, SparkleShapeSpec> choices;
final ValueChanged<SparkleShapeSpec> onChanged;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const Text('Sparkle Shape'),
const SizedBox(height: 6),
Wrap(
spacing: 8,
runSpacing: 8,
children:
choices.entries.map((MapEntry<String, SparkleShapeSpec> entry) {
return ChoiceChip(
label: Text(entry.key),
selected: selectedShape == entry.value,
onSelected: (bool selected) {
if (!selected) {
return;
}
onChanged(entry.value);
},
);
}).toList(),
),
],
);
}
}
/// Circular D-pad control for feeding the external tilt stream.
class _TiltPresetPicker extends StatelessWidget {
const _TiltPresetPicker({required this.onChanged});