-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add bloom and crt shaders * agjsts * cleanup * format
- Loading branch information
1 parent
bd42df3
commit b3419b8
Showing
11 changed files
with
294 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import 'dart:ui' as ui; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_shaders/flutter_shaders.dart'; | ||
import 'package:vector_math/vector_math.dart' hide Colors; | ||
|
||
class CRTShader extends StatelessWidget { | ||
const CRTShader({ | ||
required this.enabled, | ||
required this.child, | ||
super.key, | ||
}); | ||
|
||
final bool enabled; | ||
final Widget child; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (!enabled) { | ||
return child; | ||
} | ||
|
||
return ColoredBox( | ||
color: Colors.black, | ||
child: ImageBuilder( | ||
assetImageProvider: const AssetImage('assets/images/liltex_3.jpg'), | ||
(context, pixelTexture) { | ||
return ShaderBuilder( | ||
assetKey: 'shaders/super_crt.glsl', | ||
child: child, | ||
(context, shader, child) { | ||
return AnimatedSampler( | ||
(image, size, canvas) { | ||
shader | ||
..setFloatUniforms((value) { | ||
value | ||
..setSize(size) | ||
..setFloat(1) | ||
..setVector(Vector2(2, 3)); | ||
}) | ||
..setImageSampler(0, pixelTexture) | ||
..setImageSampler(1, image); | ||
|
||
canvas.drawRect( | ||
Offset.zero & size, | ||
Paint()..shader = shader, | ||
); | ||
}, | ||
child: child!, | ||
); | ||
}, | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} | ||
|
||
class ImageBuilder extends StatefulWidget { | ||
const ImageBuilder( | ||
this.builder, { | ||
required this.assetImageProvider, | ||
super.key, | ||
}); | ||
|
||
final Widget Function(BuildContext context, ui.Image image) builder; | ||
final ImageProvider assetImageProvider; | ||
|
||
@override | ||
State<ImageBuilder> createState() => _ImageBuilderState(); | ||
} | ||
|
||
class _ImageBuilderState extends State<ImageBuilder> { | ||
ui.Image? image; | ||
|
||
@override | ||
void didChangeDependencies() { | ||
super.didChangeDependencies(); | ||
|
||
getImage(); | ||
} | ||
|
||
Future<void> getImage() async { | ||
widget.assetImageProvider.resolve(ImageConfiguration.empty).addListener( | ||
ImageStreamListener((info, synchronousCall) { | ||
setState(() { | ||
image = info.image; | ||
}); | ||
}), | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final image = this.image; | ||
|
||
if (image == null) { | ||
return const SizedBox.shrink(); | ||
} | ||
|
||
return widget.builder(context, image); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'crt.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,4 @@ SPEC CHECKSUMS: | |
|
||
PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367 | ||
|
||
COCOAPODS: 1.12.0 | ||
COCOAPODS: 1.12.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.