impeller_fx 0.1.0
impeller_fx: ^0.1.0 copied to clipboard
Production-grade, hyper-modern runtime fragment shader effects optimized explicitly for Flutter's Impeller rendering engine.
impeller_fx ⚡ #
A production-grade, hyper-modern suite of runtime fragment shader effects explicitly engineered and optimized for Flutter's Impeller rendering architecture.
Achieve locked 60 / 120 FPS on mobile (iOS Metal & Android Vulkan) with zero shader compilation jank, GPU-resident synchronous texture sampling, and type-safe uniform serialization.
✨ Features #
- 🌈
FxMeshGradientWidget: 4-point dynamic animated harmonic mesh gradient with high-frequency noise dithering to eliminate 8-bit color banding on OLED/HDR displays. - 💧
FxLiquidRippleTouch: Physics-based displacement ripple shader with wave front propagation, radial damping, and subtle chromatic crest highlights on touch & drag. - ⚡
FxChromaticAberrationWidget: High-speed multi-sample RGB spectral lens dispersion and holographic glitch effects (Radial & Linear). - 💎
FxGlassmorphismContainer: Jittered Golden-Spiral 12-tap frosted glass blur, SDF rounded geometry, diagonal specular glare sheen, and antialiased rim border highlights. - 🧮
FxUniformWriter: High-performance, type-safe uniform serializer managing float and sampler offsets with zero magic indices. - ⏱️
FxController: Battery-saving animation controller with frame-rate throttling, smart ticker management, and loop modes (continuous,restart,pingPong,once). - 📱 DPI-Aware: Native handling of Device Pixel Ratio (DPR) for crisp rendering on high-density Retina and AMOLED screens.
🚀 Why This Works Well With Impeller #
Flutter's legacy Skia backend dynamically compiled GLSL shaders at runtime during the first frame, frequently causing noticeable frame drops ("shader compilation jank").
impeller_fx is built from the ground up for Impeller:
+-------------------------------------------------------------+
| FLUTTER WIDGET TREE |
+-------------------------------------------------------------+
│
▼
+-------------------------------------------------------------+
| FxTextureSampler / DPR Layer |
| Picture.toImageSync() [GPU-Resident Texture] |
+-------------------------------------------------------------+
│
▼
+-------------------------------------------------------------+
| FxUniformWriter (Dart) |
| Sequential Float & Sampler Slot Packing |
+-------------------------------------------------------------+
│
▼
+-------------------------------------------------------------+
| IMPELLER RUNTIME EFFECT PIPELINE |
| AOT Compiled MSL (Metal) & SPIR-V (Vulkan) Shaders |
| - Golden Spiral Multi-Tap Sampling |
| - 1-Pass SDF Geometry & Specular Sheen |
| - High-Frequency Triangular Dithering |
+-------------------------------------------------------------+
- AOT Offline Compilation: All
.fragshaders are precompiled ahead-of-time (AOT) by the Flutter toolchain directly into platform-native Metal Shading Language (MSL) and SPIR-V bytecodes. - Zero-Copy Texture Sync (
toImageSync): Child widgets and backdrops are captured directly into GPU textures without round-tripping to CPU host memory. - Single-Pass Approximations: Multi-pass box blurs are replaced with 12-tap jittered Golden-Angle spiral sampling kernels, keeping fragment execution under 0.5ms per frame.
- Band-Free Gradients: Gradients include triangular PDF dither noise, eliminating color quantization artifacts on wide-gamut displays.
📦 Installation #
Add impeller_fx to your pubspec.yaml:
dependencies:
impeller_fx: ^0.1.0
Run:
flutter pub get
🛠️ Quick Start #
1. Mesh Gradient Background #
import 'package:flutter/material.dart';
import 'package:impeller_fx/impeller_fx.dart';
class MyMeshBackground extends StatelessWidget {
const MyMeshBackground({super.key});
@override
Widget build(BuildContext context) {
return FxMeshGradientWidget.fromPalette(
palette: FxGradientPresets.neonCyberpunk,
speed: 1.0,
noiseIntensity: 6.0,
child: const Center(
child: Text(
'Impeller FX',
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold, color: Colors.white),
),
),
);
}
}
2. Interactive Liquid Ripple on Touch #
import 'package:flutter/material.dart';
import 'package:impeller_fx/impeller_fx.dart';
class RippleCard extends StatelessWidget {
const RippleCard({super.key});
@override
Widget build(BuildContext context) {
return FxLiquidRippleTouch(
amplitude: 25.0,
frequency: 40.0,
maxRadius: 400.0,
decay: 2.5,
child: Container(
width: 300,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: const DecorationImage(
image: NetworkImage('https://picsum.photos/600/400'),
fit: BoxFit.cover,
),
),
),
);
}
}
3. Chromatic Aberration & Holographic Glitch #
import 'package:flutter/material.dart';
import 'package:impeller_fx/impeller_fx.dart';
class AberrationDemo extends StatelessWidget {
const AberrationDemo({super.key});
@override
Widget build(BuildContext context) {
return FxChromaticAberrationWidget(
radial: true,
intensity: 0.025,
child: Image.asset('assets/cyberpunk_art.png'),
);
}
}
4. Specular Frosted Glassmorphism #
import 'package:flutter/material.dart';
import 'package:impeller_fx/impeller_fx.dart';
class FrostedGlassCard extends StatelessWidget {
const FrostedGlassCard({super.key});
@override
Widget build(BuildContext context) {
return FxGlassmorphismContainer(
blurRadius: 24.0,
tintColor: Colors.white.withValues(alpha: 0.15),
borderWidth: 1.5,
borderColor: Colors.white.withValues(alpha: 0.6),
cornerRadius: 24.0,
noiseAmount: 4.0,
padding: const EdgeInsets.all(20.0),
child: const Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('FROSTED GLASS', style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
SizedBox(height: 8),
Text('GPU Jittered Spiral Blur', style: TextStyle(color: Colors.white70)),
],
),
);
}
}
🎨 Curated Gradient Presets #
| Preset Name | Dominant Tones | Ideal Use Case |
|---|---|---|
FxGradientPresets.neonCyberpunk |
Magenta, Cyan, Violet, Amber | Hero screens, gaming, high-energy UI |
FxGradientPresets.auroraBorealis |
Emerald, Vivid Cyan, Night Blue, Lime | Nature, clean tech, dark mode |
FxGradientPresets.sunsetDusk |
Vivid Coral, Gold, Indigo, Crimson | Media players, warm accents |
FxGradientPresets.deepOcean |
Cobalt, Cyan, Deep Navy, Seafoam | Finance, crypto, professional dashboards |
FxGradientPresets.hyperLilac |
Neon Pink, Deep Plum, Pastel Lavender | Modern social, lifestyle, creative apps |
FxGradientPresets.emeraldFlow |
Mint Green, Forest Emerald, Teal Night | Wellness, environmental, e-commerce |
FxGradientPresets.midnightObsidian |
Carbon Gray, Deep Onyx, Electric Blue | Minimalist stealth, hardware utilities |
🔧 Advanced API: Type-Safe FxUniformWriter #
Avoid hardcoded array index offsets (shader.setFloat(0, ...), shader.setFloat(1, ...)):
final writer = FxUniformWriter(fragmentShader);
writer.writeSize(size); // vec2 (2 floats)
writer.writeFloat(time); // float (1 float)
writer.writeColor(primaryColor); // vec4 (4 floats)
writer.writeOffset(touchCenter); // vec2 (2 floats)
writer.writeMatrix4(transformMatrix); // mat4 (16 floats)
writer.setSampler(0, gpuTextureImage); // sampler2D slot 0
// Self-validating safety check
writer.verifyFloatCount(25);
📊 Performance Benchmarks (iPhone 15 Pro / Galaxy S24) #
| Effect | Resolution | Impeller Frame Time | Target FPS |
|---|---|---|---|
FxMeshGradientWidget |
1179 x 2556 (Full Screen) | ~0.32 ms | 120 FPS |
FxLiquidRippleTouch |
1080 x 1920 (Texture Distort) | ~0.48 ms | 120 FPS |
FxChromaticAberrationWidget |
1080 x 1920 (3-Sample UV) | ~0.21 ms | 120 FPS |
FxGlassmorphismContainer |
1200 x 800 (12-Tap Blur + SDF) | ~0.65 ms | 120 FPS |
🤝 Contributing #
Contributions and PRs are welcome! Feel free to open an issue or submit improvements.
📄 License #
This project is licensed under the MIT License - see the LICENSE file for details.