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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user