How albeno-degra/custom_shader works
Project type and purpose
• This is a single‐codebase Flutter demo app (mobile) that integrates custom GLSL fragment shaders to render a dynamic checkerboard background (Photoshop‐style transparency visualization).
• Primary use case: teach and experiment with Flutter’s shader API, blending UI widgets with GPU‐accelerated fragment shaders.
File structure
Top-level:
• .fvm, fvm_config.json, fvmrc – Flutter version management
• pubspec.yaml / pubspec.lock – dependency and asset declaration
• ios/… – native iOS project generated by Flutter
• lib/… – Dart code, organized into subfolders:
– core/ – shared services (image_loader.dart, shader_cache.dart)
– features/ – UI features grouped by functionality (dash, photo_shimmer, pokemons)
– shaders/ – Flutter widgets wrapping shader programs and helper code
– main.dart – application entrypoint
• shaders/*.frag – raw GLSL fragment shader source
Key insights from README
• Emphasis on a custom FragmentShader using Flutter’s API.
• GPU‐accelerated demo.
Main components
A. Flutter Application Layer (Dart)
1. main.dart (App bootstrap)
2. Feature Widgets (/features/dash, /features/photo_shimmer, /features/pokemons)
B. Core Services
1. image_loader.dart – async image loading
2. shader_cache.dart – compiles / caches FragmentShaders
C. Shader Layer
1. CheckerboardShaderWidget, FlickBoxShaderWidget, etc. (lib/shaders/…)
2. Raw GLSL files (shaders/checkerboard.frag, shaders/pixel_flicker.frag)
D. Flutter Engine & GPU
1. Dart VM & Skia renderer
2. GPU executes compiled fragment shaders
E. Native Platform
1. iOS Runner project (AppDelegate.swift, Info.plist, asset catalogs)
2. Asset pipeline (images, shader .frag files bundled via pubspec.yaml)
F. External Tools
1. FVM – locks Flutter SDK version
2. pub – package manager
Relationships & data flows
1. User taps / interacts → Dart UI (Feature Widget)
2. Feature Widget requests shader from shader_cache
3. shader_cache compiles .frag GLSL → FragmentShader object
4. Flutter Engine uploads shader to GPU
5. GPU runs shader each frame → draws checkerboard pattern into a Canvas
6. Canvas is composited into Flutter scene → displayed on iOS screen
7. image_loader (if used) fetches image bits and feeds into shader inputs
Architectural patterns & design principles
• Modular “feature” folder structure: each UI feature isolated
• Separation of concerns: core services vs feature widgets vs shader code
• GPU offload: heavy work in shader layer, minimal CPU-side logic
• Flutter’s standard layering: Dart UI → engine → native host
Specific elements
• Asset bundling path: pubspec.yaml → Runner.app → GPU
• Notes on FVM version lock and pub dependencies