Skip to content

Instantly share code, notes, and snippets.

@paulhoux
Created June 22, 2014 20:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulhoux/d733781484b26c4e27aa to your computer and use it in GitHub Desktop.
Save paulhoux/d733781484b26c4e27aa to your computer and use it in GitHub Desktop.
Alternative shader for the AudioVisualizer sample. See: https://github.com/paulhoux/Cinder-Samples
#version 110
void main(void)
{
// calculate glowing line strips based on texture coordinate
const float resolution = 64.0;
const float center = 0.5;
const float width = 0.02;
float f = fract( resolution * gl_TexCoord[0].s + 2.0 * gl_TexCoord[0].t );
float d = abs(center - f);
float strips = clamp(width / d, 0.0, 1.0);
// calculate output color
gl_FragColor.rgb = gl_Color.rgb * strips;
gl_FragColor.a = 1.0;
}
#version 110
uniform float uTexOffset;
uniform sampler2D uLeftTex;
uniform sampler2D uRightTex;
void main(void)
{
// retrieve texture coordinate and offset it to scroll the texture
vec2 coord = gl_MultiTexCoord0.st + vec2(0.0, uTexOffset);
// retrieve the FFT from left and right texture and average it
float fft = max(0.0001, mix( texture2D( uLeftTex, coord ).r, texture2D( uRightTex, coord ).r, 0.5));
// convert to decibels
const float logBase10 = 1.0 / log(10.0);
float decibels = 10.0 * log( fft ) * logBase10;
// offset the vertex based on the decibels and create a cylinder
const float two_pi = 6.2831853;
float fade = gl_MultiTexCoord0.t;
float r = 100.0 + decibels;
vec4 vertex = gl_Vertex;
vertex.y = r * cos(gl_MultiTexCoord0.t * two_pi);
vertex.z = r * sin(gl_MultiTexCoord0.t * two_pi);
// pass (unchanged) texture coordinates, bumped vertex and vertex color
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ModelViewProjectionMatrix * vertex;
gl_FrontColor = gl_Color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment