Give this a try…
/*
{
"IMPORTED" : [
],
"CATEGORIES" : [
"Automatically Converted",
"Shadertoy"
],
"DESCRIPTION" : "Automatically converted from https:\/\/www.shadertoy.com\/view\/lly3DG by Flyguy. Drawing shapes on an oscilloscope using stereo sound as X\/Y inputs. Similar to the works done by Jerobeam Fenderson: \nhttps:\/\/www.youtube.com\/user\/jerobeamfenderson1",
"PASSES" : [
{
"TARGET" : "BufferA",
"PERSISTENT" : true,
"FLOAT" : true
},
{
}
],
"INPUTS" : [
]
}
*/
/*
Drawing on an oscilloscope in XY mode using stereo sound.
Screenshot of the sound on a basic XY scope simulator: http://i.imgur.com/SxskO1E.png
Music using the same technique by Jerobeam Fenderson: https://www.youtube.com/user/jerobeamfenderson1
Some XY oscilloscope demos:
Youscope - https://youtu.be/s1eNjUgaB-g
Oscillofun - https://youtu.be/o4YyI6_y6kw
Beams of Light - https://youtu.be/lVdWxKZVYC0
*/
//Timing constants (seconds)
#define T_FRAME 0.0167 //Frame duration (0.0167s = ~60fps)
#define T_LINE 0.0020 //Duration of a 1-unit long line
float tau = atan(1.0)*8.0;
float gShapeTime = 0.0;
mat4 gModel = mat4(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);
vec2 cossin(float x)
{
return vec2(cos(x), sin(x));
}
//Single point projection
vec2 Project(vec3 p0)
{
vec3 vanish = vec3(0.0,-2.0,0.0);
p0 -= vanish;
return length(vanish) * p0.xz / p0.y;
}
//Transformation functions
mat4 Translate(vec3 v)
{
return mat4(vec4(1,0,0,v.x), vec4(0,1,0,v.y), vec4(0,0,1,v.z), vec4(0,0,0,1));
}
//Angle-axis rotation
mat4 Rotate(vec3 u,float a)
{
float c = cos(a);
float s = sin(a);
u = normalize(u);
vec4 c0 = vec4(c + (u.x*u.x) * (1.0-c), (u.y*u.x) * (1.0-c) + (u.z*s), (u.z*u.x) * (1.0-c) - (u.y*s),0.0);
vec4 c1 = vec4((u.x*u.y) * (1.0-c) - (u.z*s), c + (u.y*u.y) * (1.0-c), (u.z*u.y) * (1.0-c) + (u.x*s),0.0);
vec4 c2 = vec4((u.x*u.z) * (1.0-c) + (u.y*s), (u.y*u.z) * (1.0-c) - (u.x*s), c + (u.z*u.z) * (1.0-c),0.0);
//return mat4(mat3(c0,c1,c2));
return mat4(c0, c1, c2, vec4(0.0));
}
mat4 Scale(vec3 v)
{
return mat4(vec4(v.x,0,0,0), vec4(0,v.y,0,0), vec4(0,0,v.z,0), vec4(0,0,0,1));
}
//2D line waveform
vec2 Line(vec2 p0, vec2 p1, float td, float t)
{
float tl = td * distance(p0, p1);
t -= gShapeTime;
gShapeTime += tl;
if(t >= 0.0 && t < tl)
{
return mix(p0, p1, t/tl);
}
return vec2(0);
}
//3D Projected line
vec2 Line3d(vec3 p0, vec3 p1, float td, float t)
{
p0 = (vec4(p0,1.0) * gModel).xyz;
p1 = (vec4(p1,1.0) * gModel).xyz;
p0.xy = Project(p0);
p1.xy = Project(p1);
return Line(p0.xy, p1.xy, td, t);
}
vec2 mainSound( float time )
{
float ft = mod(time, T_FRAME);
gModel *= Scale(vec3(0.25));
gModel *= Rotate(vec3(0, 0, 1), time);
gModel *= Rotate(vec3(0, 1, 0), time);
gModel *= Rotate(vec3(1, 0, 0), time);
gModel *= Translate(vec3(0.4 * cossin(1.0 * time), 0.4 * sin(0.6 * time)));
vec3 cube[8];
cube[0] = vec3(-1,-1,-1);
cube[1] = vec3( 1,-1,-1);
cube[2] = vec3(-1, 1,-1);
cube[3] = vec3( 1, 1,-1);
cube[4] = vec3(-1,-1, 1);
cube[5] = vec3( 1,-1, 1);
cube[6] = vec3(-1, 1, 1);
cube[7] = vec3( 1, 1, 1);
vec2 sout = vec2(0);
sout += Line3d(cube[0],cube[1], T_LINE, ft);
sout += Line3d(cube[1],cube[3], T_LINE, ft);
sout += Line3d(cube[3],cube[2], T_LINE, ft);
sout += Line3d(cube[2],cube[0], T_LINE, ft);
sout += Line3d(cube[4],cube[5], T_LINE, ft);
sout += Line3d(cube[5],cube[7], T_LINE, ft);
sout += Line3d(cube[7],cube[6], T_LINE, ft);
sout += Line3d(cube[6],cube[4], T_LINE, ft);
sout += Line3d(cube[0],cube[4], T_LINE, ft);
sout += Line3d(cube[5],cube[1], T_LINE, ft);
sout += Line3d(cube[2],cube[6], T_LINE, ft);
sout += Line3d(cube[7],cube[3], T_LINE, ft);
return vec2( sout );
}
/*
Drawing on an oscilloscope in XY mode using stereo sound.
Screenshot of the sound on a basic XY scope simulator: http://i.imgur.com/SxskO1E.png
Music using the same technique by Jerobeam Fenderson: https://www.youtube.com/user/jerobeamfenderson1
Some XY oscilloscope demos:
Youscope - https://youtu.be/s1eNjUgaB-g
Oscillofun - https://youtu.be/o4YyI6_y6kw
Beams of Light - https://youtu.be/lVdWxKZVYC0
*/
//Projected line
float Line3d(vec3 p0,vec3 p1,vec2 uv)
{
p0 = (vec4(p0,1.0) * gModel).xyz;
p1 = (vec4(p1,1.0) * gModel).xyz;
p0.xy = Project(p0);
p1.xy = Project(p1);
vec2 dir = normalize(p1.xy - p0.xy);
uv = (uv - p0.xy) * mat2(dir.x, dir.y, -dir.y, dir.x);
float d = distance(uv, clamp(uv, vec2(0.0), vec2(distance(p0.xy, p1.xy), 0.0)));
return smoothstep(4.0/RENDERSIZE.y, 0.0, d);
}
void main() {
if (PASSINDEX == 0) {
}
else if (PASSINDEX == 1) {
vec2 res = RENDERSIZE.xy / RENDERSIZE.y;
vec2 uv = (gl_FragCoord.xy / RENDERSIZE.y) - (res / 2.0);
uv *= 2.0;
float time = TIME;
gModel *= Scale(vec3(0.25));
gModel *= Rotate(vec3(0, 0, 1), time);
gModel *= Rotate(vec3(0, 1, 0), time);
gModel *= Rotate(vec3(1, 0, 0), time);
gModel *= Translate(vec3(0.4 * cossin(1.0 * time), 0.4 * sin(0.6 * time)));
vec3 cube[8];
cube[0] = vec3(-1,-1,-1);
cube[1] = vec3( 1,-1,-1);
cube[2] = vec3(-1, 1,-1);
cube[3] = vec3( 1, 1,-1);
cube[4] = vec3(-1,-1, 1);
cube[5] = vec3( 1,-1, 1);
cube[6] = vec3(-1, 1, 1);
cube[7] = vec3( 1, 1, 1);
vec3 cout = vec3(0);
cout += Line3d(cube[0],cube[1], uv);
cout += Line3d(cube[1],cube[3], uv);
cout += Line3d(cube[3],cube[2], uv);
cout += Line3d(cube[2],cube[0], uv);
cout += Line3d(cube[4],cube[5], uv);
cout += Line3d(cube[5],cube[7], uv);
cout += Line3d(cube[7],cube[6], uv);
cout += Line3d(cube[6],cube[4], uv);
cout += Line3d(cube[0],cube[4], uv);
cout += Line3d(cube[5],cube[1], uv);
cout += Line3d(cube[2],cube[6], uv);
cout += Line3d(cube[7],cube[3], uv);
cout *= vec3(0.1,0.8,0.1);
gl_FragColor = vec4(cout, 1.0);
}
}
``