Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add glow stuff with flutter #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: "5aaf60d96c4cd00fe7f21594b5ad6a1b699c80a27420f8a837f4d68473ef09e3"
sha256: "0b2f2bd91ba804e53a61d757b986f89f1f9eaed5b11e4b2f5a2468d86d6c9fc7"
url: "https://pub.dev"
source: hosted
version: "68.0.0"
_macros:
dependency: transitive
description: dart
source: sdk
version: "0.1.5"
version: "67.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: "21f1d3720fd1c70316399d5e2bccaebb415c434592d778cce8acb967b8578808"
sha256: "37577842a27e4338429a1cbc32679d508836510b056f1eedf0c8d20e39c1383d"
url: "https://pub.dev"
source: hosted
version: "6.5.0"
version: "6.4.1"
archive:
dependency: transitive
description:
Expand Down Expand Up @@ -294,14 +289,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
macros:
dependency: transitive
description:
name: macros
sha256: a8403c89b36483b4cbf9f1fcd24562f483cb34a5c9bf101cf2b0d8a083cf1239
url: "https://pub.dev"
source: hosted
version: "0.1.0-main.5"
markdown:
dependency: transitive
description:
Expand Down Expand Up @@ -675,10 +662,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4
sha256: "0eaf06e3446824099858367950a813472af675116bf63f008a4c2a75ae13e9cb"
url: "https://pub.dev"
source: hosted
version: "5.5.1"
version: "5.5.0"
xml:
dependency: transitive
description:
Expand All @@ -696,4 +683,4 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.4.0 <4.0.0"
dart: ">=3.3.0 <4.0.0"
104 changes: 104 additions & 0 deletions source/shaders/glow-stuff/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
description: Glowing text, image and eve rive animations with a shader.
shader:
title: Glow stuff
description: A glowing effect that can plug into actual flutter layouts and create a mesmerizing effect
screenshot: space.png
video: scrolling.mp4
directory: shaders/glow-stuff/
---


```glsl
// Directional glow GLSL fragment shader.
// Based on the "Let it Glow!" pen by "Selman Ay" (https://codepen.io/selmanays/pen/yLVmEqY)
// Functioning example at: https://github.com/renancaraujo/glow_stuff_with_flutter
precision highp float;

// Float uniforms
uniform float width; // Width of the canvas
uniform float height; // Height of the canvas
uniform float sourceX; // X position of the light source
uniform float scrollFraction; // Scroll fraction of the page in relation to the canvas
uniform float density; // Density of the "smoke" effect
uniform float lightStrength; // Strength of the light
uniform float weight; // Weight of the "smoke" effect

// Sampler uniforms
uniform sampler2D tInput; // Input texture (the application canvas)
uniform sampler2D tNoise; // Some texture

out vec4 fragColor;

float sourceY = scrollFraction;
vec2 resolution = vec2(width, height);
vec2 lightSource = vec2(sourceX, sourceY);

const int samples = 20; // The number of "copies" of the canvas made to emulate the "smoke" effect
const float decay = 0.88; // Decay of the light in each sample
const float exposure = .9; // The exposure to the light


float random2d(vec2 uv) {
uv /= 256.;
vec4 tex = texture(tNoise, uv);
return mix(tex.r, tex.g, tex.a);
}

float random(vec3 xyz){
return fract(sin(dot(xyz, vec3(12.9898, 78.233, 151.7182))) * 43758.5453);
}

vec4 sampleTexture(vec2 uv) {
vec4 textColor = texture(tInput, uv);
return textColor;
}

vec4 occlusion(vec2 uv, vec2 lightpos, vec4 objects) {
return (1. - smoothstep(0.0, lightStrength, length(lightpos - uv))) * (objects);
}


vec4 fragment(vec2 uv, vec2 fragCoord) {
vec3 colour = vec3(0);

vec4 obj = sampleTexture(uv);
vec4 map = occlusion(uv, lightSource, obj);

float random = random(vec3(fragCoord, 1.0));;

float exposure = exposure + (sin(random) * .5 + 1.) * .05;

vec2 _uv = uv;
vec2 distance = (_uv - lightSource) * (1. / float(samples) * density);

float illumination_decay = 1.;
for (int i=0; i<samples; i++) {
_uv -= distance;

float movement = random * 20. * float(i + 1);
float dither = random2d(uv + mod(vec2(movement*sin(random * .5), -movement), 1000.)) * 2.;

vec4 stepped_map = occlusion(uv, lightSource, sampleTexture(_uv+distance*dither));
stepped_map *= illumination_decay * weight;

illumination_decay *= decay;
map += stepped_map;
}

float lum = dot(map.rgb, vec3(0.2126, 0.7152, 0.0722));

colour += vec3(map.rgb*exposure);
return vec4(colour, lum);
}

void main() {
vec2 pos = gl_FragCoord.xy;
vec2 uv = pos / vec2(width, height);
fragColor = fragment(uv, pos);
}

```


More explanation here: [tweet](https://x.com/reNotANumber/status/1599717360096620544).
Binary file added source/shaders/glow-stuff/scrolling.mp4
Binary file not shown.
Binary file added source/shaders/glow-stuff/space.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.