-
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.
- Loading branch information
1 parent
1e36549
commit 5ef6121
Showing
10 changed files
with
406 additions
and
12 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'dart:ui' as ui; | ||
|
||
import 'package:vector_math/vector_math.dart' hide Colors; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_shaders/flutter_shaders.dart'; | ||
|
||
class BloomShader extends StatelessWidget { | ||
const BloomShader({ | ||
super.key, | ||
required this.enabled, | ||
required this.child, | ||
}); | ||
|
||
final bool enabled; | ||
final Widget child; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
|
||
if(!enabled) return child; | ||
|
||
return ColoredBox( | ||
color: Colors.black, | ||
child: ShaderBuilder( | ||
assetKey: 'shaders/bloom.glsl', | ||
child: child, | ||
(context, shader, child) { | ||
return AnimatedSampler( | ||
(image, size, canvas) { | ||
shader | ||
..setFloatUniforms((value) { | ||
value.setSize(size); | ||
}) | ||
..setImageSampler(0, image); | ||
|
||
canvas.drawRect(Offset.zero & size, Paint()..shader = shader); | ||
}, | ||
child: child!, | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} | ||
|
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,104 @@ | ||
import 'dart:ui' as ui; | ||
|
||
import 'package:vector_math/vector_math.dart' hide Colors; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_shaders/flutter_shaders.dart'; | ||
|
||
class CRTShader extends StatelessWidget { | ||
const CRTShader({ | ||
super.key, | ||
required this.enabled, | ||
required this.child, | ||
}); | ||
|
||
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, 5)); | ||
}) | ||
..setImageSampler(0, pixelTexture) | ||
..setImageSampler(1, image); | ||
|
||
canvas.drawRect( | ||
Offset.zero & size, | ||
Paint()..shader = shader, | ||
); | ||
}, | ||
child: child!, | ||
); | ||
}, | ||
); | ||
}, | ||
), | ||
); | ||
} | ||
} | ||
|
||
class ImageBuilder extends StatefulWidget { | ||
const ImageBuilder( | ||
this.builder, { | ||
super.key, | ||
required this.assetImageProvider, | ||
}); | ||
|
||
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,2 @@ | ||
export 'bloom.dart'; | ||
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
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,61 @@ | ||
// specify the version of GLSL to use. | ||
#version 460 core | ||
|
||
// specify the name of the fragment shader. | ||
precision mediump float; | ||
|
||
// include the Flutter-provided "FlutterFragCoord" function. | ||
// this function returns the fragment's position in logical pixels in both in skia and impeller | ||
#include <flutter/runtime_effect.glsl> | ||
|
||
// declare the uniform inputs. | ||
uniform vec2 uSize; | ||
uniform sampler2D tTexture; | ||
|
||
|
||
out vec4 fragColor; | ||
|
||
const float blurSize = 1.0/3500.0; | ||
const float intensity = 0.35; | ||
|
||
|
||
vec4 fragment(vec2 uv, vec2 pos, inout vec4 color) { | ||
|
||
vec4 sum = vec4(0); | ||
vec2 texcoord = uv; | ||
int j; | ||
int i; | ||
|
||
for (i = -18; i < 18; i++){ | ||
float factor = (mod(i, 18) / 10.0 ) * 0.008; | ||
sum += texture(tTexture, vec2(texcoord.x + i * blurSize, texcoord.y * 40)) * factor ; | ||
sum += texture(tTexture, vec2(texcoord.x, texcoord.y + i * blurSize * 40)) * factor ; | ||
} | ||
|
||
color = sum+ texture(tTexture, texcoord); | ||
|
||
return color; | ||
} | ||
|
||
float getLuma(vec3 color) { | ||
vec3 weights = vec3(0.299, 0.587, 0.114); | ||
return dot(color, weights); | ||
} | ||
|
||
|
||
// the main function | ||
void main() { | ||
vec2 pos = FlutterFragCoord().xy; | ||
vec2 uv = pos / uSize; | ||
vec4 color; | ||
|
||
// fragColor = texture(tTexture, uv); | ||
// return; | ||
// | ||
|
||
|
||
fragment(uv, pos, color); | ||
|
||
|
||
fragColor = color; | ||
} |
Oops, something went wrong.