Add fft
This commit is contained in:
@ -3,6 +3,7 @@ precision mediump float;
|
||||
out vec4 o;
|
||||
const float PI = 22./7.;
|
||||
layout(location = 0) uniform float syncs[7];
|
||||
layout(location = 8) uniform float fft_output[512]; // FFT_SIZE / 4
|
||||
float u_time = syncs[0];
|
||||
|
||||
vec3 render(vec2 uv, float time) {
|
||||
@ -23,5 +24,18 @@ vec3 render(vec2 uv, float time) {
|
||||
void main() {
|
||||
vec2 uv = gl_FragCoord.xy * 2. / vec2(1920,1080);
|
||||
vec3 col = render(uv, u_time);
|
||||
o = vec4(col,1.0);
|
||||
|
||||
// Determine FFT bin index for current x position
|
||||
int index = int(floor(uv.x*128.0));
|
||||
index = clamp(index, 0, 255);
|
||||
|
||||
// Get the FFT energy (clamped to avoid NaNs or overflow)
|
||||
float energy = clamp(fft_output[index], .0, 1.0);
|
||||
|
||||
float bar_height = energy;
|
||||
float fade = smoothstep(bar_height, bar_height + 0.02, 1.0 - uv.y);
|
||||
|
||||
vec3 color = vec3(fade);
|
||||
|
||||
o = vec4(color, 1.0);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// Generated with Shader Minifier 1.5.1 (https://github.com/laurentlb/Shader_Minifier/)
|
||||
#ifndef FRAGMENT_INL_
|
||||
# define FRAGMENT_INL_
|
||||
# define VAR_fft_output "l"
|
||||
# define VAR_o "f"
|
||||
# define VAR_syncs "v"
|
||||
|
||||
@ -10,20 +11,13 @@ const char *fragment_frag =
|
||||
"out vec4 f;"
|
||||
"const float m=22./7.;"
|
||||
"layout(location=0)uniform float v[7];"
|
||||
"layout(location=8)uniform float l[512];"
|
||||
"float n=v[0];"
|
||||
"vec3 s(vec2 f)"
|
||||
"{"
|
||||
"float m=v[4];"
|
||||
"return f.x>=m&&f.x<=m+.01?"
|
||||
"vec3(1):"
|
||||
"f.x>=0.&&f.x<=.01?"
|
||||
"vec3(abs(v[3]*2)):"
|
||||
"vec3(.1,.2,.3)*abs(v[1]*1.2);"
|
||||
"}"
|
||||
"void main()"
|
||||
"{"
|
||||
"vec2 m=gl_FragCoord.xy*2./vec2(1920,1080);"
|
||||
"f=vec4(s(m),1);"
|
||||
"float n=clamp(l[clamp(int(floor(m.x*128.)),0,255)],0.,1.);"
|
||||
"f=vec4(vec3(smoothstep(n,n+.02,1.-m.y)),1);"
|
||||
"}";
|
||||
|
||||
#endif // FRAGMENT_INL_
|
||||
|
||||
Reference in New Issue
Block a user