Pixel-Composer/shaders/sh_noise/sh_noise.fsh

48 lines
1.6 KiB
Plaintext
Raw Normal View History

2022-12-12 09:08:03 +01:00
//
// Simple passthrough fragment shader
//
varying vec2 v_vTexcoord;
varying vec4 v_vColour;
uniform vec2 dimension;
uniform float seed;
2023-04-07 21:25:27 +02:00
uniform int colored;
uniform vec2 colorRanR;
uniform vec2 colorRanG;
uniform vec2 colorRanB;
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
2023-01-09 03:14:20 +01:00
float random (in vec2 st, float seed) {
return fract(sin(dot(st.xy + seed, vec2(1892.9898, 78.23453))) * 437.54123);
2022-12-12 09:08:03 +01:00
}
2023-04-07 21:25:27 +02:00
float frandom (in vec2 st) {
float n0 = random(st, floor(seed) / 5000.);
float n1 = random(st, (floor(seed) + 1.) / 5000.);
return mix(n0, n1, fract(seed));
}
2022-12-12 09:08:03 +01:00
void main() {
2023-04-07 21:25:27 +02:00
if(colored == 0)
gl_FragColor = vec4(vec3(frandom(v_vTexcoord)), 1.0);
else if(colored == 1) {
float randR = colorRanR[0] + frandom(v_vTexcoord) * (colorRanR[1] - colorRanR[0]);
float randG = colorRanG[0] + frandom(v_vTexcoord + vec2(1.7227, 4.55529)) * (colorRanG[1] - colorRanG[0]);
float randB = colorRanB[0] + frandom(v_vTexcoord + vec2(6.9950, 6.82063)) * (colorRanB[1] - colorRanB[0]);
gl_FragColor = vec4(randR, randG, randB, 1.0);
} else if(colored == 2) {
float randH = colorRanR[0] + frandom(v_vTexcoord) * (colorRanR[1] - colorRanR[0]);
float randS = colorRanG[0] + frandom(v_vTexcoord + vec2(1.7227, 4.55529)) * (colorRanG[1] - colorRanG[0]);
float randV = colorRanB[0] + frandom(v_vTexcoord + vec2(6.9950, 6.82063)) * (colorRanB[1] - colorRanB[0]);
gl_FragColor = vec4(hsv2rgb(vec3(randH, randS, randV)), 1.0);
}
2022-12-12 09:08:03 +01:00
}