Pixel-Composer/shaders/sh_noise_strand/sh_noise_strand.fsh

60 lines
1.6 KiB
Plaintext
Raw Permalink Normal View History

2024-02-01 08:38:21 +01:00
#define TAU 6.28318530718
2024-02-01 05:26:02 +01:00
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
2024-02-01 05:26:02 +01:00
uniform vec2 position;
uniform float density;
uniform float seed;
uniform float slope;
2024-02-01 08:38:21 +01:00
uniform int axis;
uniform int mode;
2024-02-03 13:11:50 +01:00
uniform vec2 alpha;
2024-02-01 05:26:02 +01:00
2024-02-01 08:38:21 +01:00
uniform vec2 curve;
2024-02-01 05:26:02 +01:00
uniform float curveDetail;
2024-02-01 08:38:21 +01:00
uniform float curveShift;
2024-02-01 05:26:02 +01:00
uniform float thickness;
2024-02-03 13:11:50 +01:00
float random (in vec2 st) { return fract(sin(dot(st.xy + vec2(1., 6.), vec2(2., 7.))) * (1. + seed / 100.)); }
2024-02-01 05:26:02 +01:00
void main() {
vec2 ntx = v_vTexcoord * vec2(1., dimension.y / dimension.x);
vec2 tx = 1. / dimension;
vec2 ps = ntx + position;
2024-02-01 05:26:02 +01:00
float w = 0.;
vec2 dim = axis == 0? dimension : dimension.yx;
2024-02-01 08:38:21 +01:00
vec2 pos = axis == 0? ps : ps.yx;
2024-02-01 05:26:02 +01:00
float _t = min(tx.x, tx.y) / 2.;
float mt = 1. - _t;
2024-02-01 08:38:21 +01:00
float rp = dim.x;
2024-02-01 05:26:02 +01:00
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 = random(vec2(2., float(i))) - 0.5;
2024-02-03 13:11:50 +01:00
float _a = mix(alpha.x, alpha.y, random(vec2(float(i), 2.)));
2024-02-01 05:26:02 +01:00
2024-02-01 08:38:21 +01:00
float _c = mix(curve.x, curve.y, random(vec2(float(i), 3.)));
2024-02-01 05:26:02 +01:00
2024-02-01 08:38:21 +01:00
_x += _s * 2. * (pos.y - _y) * slope;
_x += sin((pos.y - _y) * curveDetail * dim.y / 4. + (curveShift * TAU/* * sign(_y - 0.5)*/)) * _c / dim.x * 2.;
2024-02-01 05:26:02 +01:00
2024-02-01 08:38:21 +01:00
if(mode == 0) {
float st = smoothstep(mt - thickness, mt + thickness, 1. - abs(pos.x - _x)) * _a;
w = max(w, st);
2024-02-01 08:38:21 +01:00
} else if(mode == 1) {
float st = smoothstep(mt - thickness, mt + thickness, 1. - max(0., pos.x - _x)) * (1. / float(amo));
w += st;
}
2024-02-01 05:26:02 +01:00
}
gl_FragColor = vec4(vec3(w), 1.);
}