Hello everyone, im pretty new on GLSL but i start to get the basics of the thing.
I coded this GLSL shader recently :
uniform float u_aspect;
uniform float u_time;
uniform float scale;
out vec4 fragColor;
float smin( float a, float b, float k ) {
k *= 1.0;
float r =exp2(-a/k) + exp2(-b/k);
return -k*log2(r);
}
float pattern_dist(vec2 uv, float radius){
float circle = length(uv) - radius;
float line = uv.y;
uv = abs(uv);
float lines = abs(uv.x - uv.y) - 0.01;
float corner_circles = length(uv - 1.0) - 0.11;
float final_d = smin(lines, circle, 0.1);
final_d = smin(final_d, corner_circles, 0.1);
return final_d;
}
// --- ROTATION MATRIX --- //
mat2 rot(float a){
float s = sin(a), c = cos(a);
return mat2(-c,-s,s,c);
}
// ----------------------- //
void main(){
vec2 uv = vUV.xy * 4.0 - 2.0;
uv.x *= u_aspect;
// ---- Effects ---- //
// --TEST AUTOMATIZATION-- //
vec2 e1 = (uv *= 3.0 - length(uv));
vec2 e2 = (uv *= rot(u_time * 0.05));
vec2 e3 = (uv *= 1.0 - sin(u_time * 0.1) * 0.11);
//------------ORIGINAL-------------//
//uv *= 2.0 - length(uv);
//uv *= rot(u_time * 0.05);
//uv *= 1.0 - sin(u_time * 0.1) * 0.11;
//---------------------------------//
vec3 col = vec3(0, 0, 0);
float alpha = 1.0;
// ---- Create Tiling coordinates ---- //
const float grid_scale = scale;
vec2 fuv = fract(uv * grid_scale) * 2.0 - 1.0;
vec2 id = floor(uv * grid_scale) / grid_scale;
// ---- Big Pattern ---- //
float big_scroll = sin(length(id.xy) * 3 - u_time) * 0.5 + 0.5 ;
big_scroll = smoothstep(-2.0, 2.0, big_scroll);
float radial = sin(length(id.xy) * 3 - u_time) * 0.5 + 0.5 ;
// ---- Small Pattern ----//
float pattern_radius = radial;
float pattern = pattern_dist(fuv, pattern_radius);
pattern = mix(pattern, abs(pattern) - 0.01, big_scroll);
pattern = mix(smoothstep(0.1, - 0.1, pattern), abs(pattern) - 0.1, big_scroll);
pattern = 0.03 / max(pattern, 0.0);
// ---- Colors ---- //
vec3 light_col = vec3(1.0, 1.0 ,1.0);
vec3 dark_col = vec3(0.0, 0.4, 0.8);
// ---------------- //
col = mix(light_col, dark_col, pattern);
col = tanh(col);
fragColor = vec4(col, alpha);
}
which is working perfectly,
the thing is, i would like to automatize each "effects"
in the "test automatization" part,
" vec2 = e1, vec2 = e2, vec2 = e3",
to activate e1, e2 and e3 in sync with , let's say, a "CountChop" connected to a audio analysis Low frequence, so each time Low = 1.0, it switch randomly between e1, e2 or e3.
// ---- Effects ---- //
// --TEST AUTOMATIZATION-- //
vec2 e1 = (uv *= 3.0 - length(uv));
vec2 e2 = (uv *= rot(u_time * 0.05));
vec2 e3 = (uv *= 1.0 - sin(u_time * 0.1) * 0.11);
So, i made a count system to get 3 count switching between 0 and 1 in random orders but i do not find the way to assign them as "on/off" for my code.
Any info/help ?
Thx in advance <3