Pixel-Composer/shaders/sh_cell_noise/sh_cell_noise.fsh

70 lines
1.8 KiB
Text
Raw Normal View History

2022-01-13 05:24:03 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
2022-01-13 05:24:03 +01:00
uniform vec2 position;
uniform float scale;
uniform int pattern;
2022-01-13 05:24:03 +01:00
uniform float time;
uniform float contrast;
uniform float middle;
uniform float radiusScale;
uniform float radiusShatter;
#define PI 3.14159265359
2023-02-23 07:02:19 +01:00
#define TAU 6.283185307179586
2023-07-21 12:40:20 +02:00
vec2 random2( vec2 p ) { return fract(sin(vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)))) * 43758.5453); }
2022-01-13 05:24:03 +01:00
2023-07-21 12:40:20 +02:00
float random (in vec2 st) { return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123); }
2022-01-13 05:24:03 +01:00
void main() {
vec2 pos = position / dimension;
vec2 st = v_vTexcoord - pos;
2022-01-13 05:24:03 +01:00
vec3 color = vec3(.0);
st *= scale;
float m_dist = 1.;
if(pattern == 0) {
vec2 i_st = floor(st);
vec2 f_st = fract(st);
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
vec2 neighbor = vec2(float(x),float(y));
2023-03-13 10:45:56 +01:00
vec2 point = random2(mod(i_st + neighbor, scale));
point = 0.5 + 0.5 * sin(time + 6.2831 * point);
2022-01-13 05:24:03 +01:00
vec2 _diff = neighbor + point - f_st;
float dist = length(_diff);
m_dist = min(m_dist, dist);
}
}
} else if(pattern == 1) {
for (int j = 0; j <= int(scale / 2.); j++) {
int _amo = int(scale) + int(float(j) * radiusShatter);
for (int i = 0; i <= _amo; i++) {
2023-01-25 06:49:00 +01:00
float ang = TAU / float(_amo) * float(i) + float(j) + random(vec2(0.684, 1.387)) + time;
float rad = pow(float(j) / scale, radiusScale) * scale * .5 + random(vec2(ang)) * 0.1;
vec2 point = vec2(cos(ang) * rad, sin(ang) * rad) + pos;
vec2 _diff = point - v_vTexcoord;
float dist = length(_diff);
m_dist = min(m_dist, dist);
}
}
}
2022-01-13 05:24:03 +01:00
color += m_dist;
vec3 c = middle + (color - middle) * contrast;
gl_FragColor = vec4(c, 1.0);
2022-01-13 05:24:03 +01:00
}