Sound Ripple (drawn with GLSL)
コードはこちら。Atomの拡張機能、VEDAで動かしました。
/*{ "audio": true}*/
precision mediump float;
uniform float time;
uniform vec2 resolution;
uniform sampler2D texture;
uniform sampler2D spectrum;
uniform sampler2D samples;
uniform float volume;
#define M_PI 3.1415926535897932384626433832795
float plot(vec2 st, float pct){
return smoothstep( pct-0.01, pct, st.y) -
smoothstep( pct, pct+0.01, st.y);
}
float n12(float k) {
return fract(k*128495.6431137957832384 + 5.25474236 ) ;
}
float n13(float k) {
return fract(k*2318.87288143654 + 24.9793926 ) ;
}
float plot_r(vec2 st, float pct, float nz){
float w = nz + 0.01;
return smoothstep( pct-w, pct, length(st)) -
smoothstep( pct, pct+w, length(st) ) ;
}
float spot(vec2 p, float r, float nz) {
float d = length(p);
return smoothstep(0.,d,r+nz);
}
float circle(in vec2 _st, in vec2 _o1, in float _radius, float _noiz) {
vec2 d = _st - _o1;
float w = _radius * _noiz;
return 1. - smoothstep(_radius - w , _radius + w, dot(d,d)*(7.)) ;
}
float circled(in vec2 _st, in vec2 _o1, in float _radius, float _noiz) {
vec2 d = vec2(_st.x*4.2984, _st.y*1.824) - _o1;
float w = _radius * _noiz;
return 1. - smoothstep(_radius - w , _radius + w, dot(d,d)*(7.)) ;
}
vec2 tile(in vec2 _st, in float _m, in float _n) {
vec2 p = _st ;
return vec2(fract(p.x*_m), fract(p.y*_n)) ;
}
void main (void) {
vec2 uv = gl_FragCoord.xy / resolution.xy;
float asp = resolution.x / resolution.y;
uv -=0.5 ;
uv.x *= asp;
vec2 p = uv;
float t1 = time*0.05;
float ti1 = floor(cos(fract(time*0.05))*3. +2.);
float ti2 = floor(fract(time*0.05)*4.);
float t = time;
float wave = texture2D(
samples,
vec2( length(uv),uv.y )
).r;
float d = wave*5. ;
vec4 freq = texture2D(
spectrum,
uv
) ;
float div_y = floor(d*3.);
float div_x = floor(d*3.);
p = tile(p, div_x, div_y) ;
vec2 o1 = vec2(0.2*sin(4.*t1)+0.3, cos(t*2.)*0.7+1.0);
vec2 o2 = vec2(0.35, 0.222);
vec2 o3 = vec2(cos(ti1)*0.3, sin(ti2)*0.6);
float sc = dot(freq, freq) ;
vec3 sc3 = vec3(
floor(uv.x*div_x)/div_x + freq.x ,
freq.y + floor(uv.y*div_y),
freq.z*freq.a*freq.a
) ;
vec3 col = circle(p, o1, d, n12(length(p-o1)*0.0125) ) * sc3 ;
col += circled(p-o2, o3, d*0.25, n13(length(p-o3)*0.125) ) * sc3 ;
gl_FragColor = vec4(col , 1.);
}
いいなと思ったら応援しよう!
面白かった、ためになったと感じた方にサポートいただけると励みになります。いつか展示会やイベントをやるための積立金として、あるいは飢死直前金欠時のライフラインとして使わせていただきます。