Pixel-Composer/shaders/sh_noise_bubble/sh_noise_bubble.fsh

50 lines
1.3 KiB
Text
Raw Normal View History

2024-02-03 13:11:50 +01:00
#define TAU 6.28318530718
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
2024-02-03 13:11:50 +01:00
uniform float density;
uniform float seed;
uniform vec2 scale;
uniform vec2 alpha;
uniform int mode;
2024-02-04 07:33:42 +01:00
uniform int render;
2024-02-03 13:11:50 +01:00
uniform float thickness;
float random (in vec2 st) { return fract(sin(dot(st.xy + vec2(1., 6.), vec2(2., 7.))) * (1. + seed / 100.)); }
void main() {
vec2 ntx = v_vTexcoord * vec2(1., dimension.y / dimension.x);
vec2 tx = 1. / dimension;
vec2 ps = ntx;
2024-02-03 13:11:50 +01:00
float w = 0.;
vec2 dim = dimension;
2024-02-03 13:11:50 +01:00
vec2 pos = ps;
float _t = min(tx.x, tx.y) / 2.;
float rp = dim.x;
int amo = int(density * rp);
for (int i = 0; i < amo; i++) {
float _x = random(vec2(float(i), 1.));
float _y = random(vec2(1., float(i)));
float _s = mix(scale.x, scale.y, random(vec2(2., float(i))));
float _a = mix(alpha.x, alpha.y, random(vec2(float(i), 2.)));
float dst = 1. - distance(pos, vec2(_x, _y));
2024-02-04 07:33:42 +01:00
float st;
2024-02-03 13:11:50 +01:00
2024-02-04 07:33:42 +01:00
if(mode == 0) st = smoothstep(1. - max(_t, thickness), 1., 1. - abs(dst - (1. - _s))) * _a;
else if(mode == 1) st = smoothstep(1. - _s - thickness, 1. - _s + thickness, max(0., dst)) * _a;
if(render == 0) w = max(w, st);
else if(render == 1) w += st;
2024-02-03 13:11:50 +01:00
}
gl_FragColor = vec4(vec3(w), 1.);
}