Created
December 7, 2023 15:13
-
-
Save 0b5vr/dde91145391381c54ebaa8955fb2c2f9 to your computer and use it in GitHub Desktop.
BonzomaticのFFTを丁寧に使う
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (c) 2023 0b5vr, MIT License | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
#version 410 core | |
#define saturate(x) clamp(x,0.,1.) | |
#define linearstep(a,b,t) saturate( ( (t)-(a) ) / ( (b)-(a) ) ) | |
const float LOG10 = log( 10.0 ); | |
uniform float fGlobalTime; // in seconds | |
uniform vec2 v2Resolution; // viewport resolution (in pixels) | |
uniform float fFrameTime; // duration of the last frame, in seconds | |
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq | |
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients | |
uniform sampler1D texFFTIntegrated; // this is continually increasing | |
uniform sampler2D texPreviousFrame; // screenshot of the previous frame | |
uniform sampler2D texChecker; | |
uniform sampler2D texNoise; | |
uniform sampler2D texTex1; | |
uniform sampler2D texTex2; | |
uniform sampler2D texTex3; | |
uniform sampler2D texTex4; | |
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything | |
float fetchFFT( float x ) { | |
float xt = exp2( mix( -9.0, -1.0, x ) ); // 47Hz - 12,000Hz in log scale | |
float v = texture( texFFTSmoothed, xt ).x; | |
v = 20.0 * log( v ) / LOG10; // value to dB | |
v += 24.0 * x; // +3dB/oct | |
return v; | |
} | |
void main( void ) { | |
vec2 uv = gl_FragCoord.xy / v2Resolution; | |
float v = linearstep( -40.0, 0.0, fetchFFT( uv.x ) ); | |
float shape = step( uv.y, v ); | |
out_color = vec4( vec3( shape ), 1.0 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment