JuceDemo's OpenGL Fragment Shader demo


#1

Minor typo in OpenGL “Changing Colour” Fragment Shader
Original
/* This is a live OpenGL Shader demo.
Edit the shader program below and it will be
compiled and applied to the model above!
*/

#define PI 3.1415926535897932384626433832795

varying vec2 textureCoordOut;
uniform float bouncingNumber;

void main()
{
float b = bouncingNumber;
float n = b * PI * 2.0;
float sn = (sin (n * textureCoordOut.x) * 0.5) + 0.5;
float cn = (sin (n * textureCoordOut.y) * 0.5) + 0.5;

vec4 col = vec4 (b, sn, cn, 1.0);
gl_FragColor = col;
}

  • suggested replacement

/* This is a live OpenGL Shader demo.
Edit the shader program below and it will be
compiled and applied to the model above!
*/

#define PI (4.0 * atan(1.0))

varying vec2 textureCoordOut;
uniform float bouncingNumber;

void main()
{
float b = bouncingNumber;
float c = 1.0 - bouncingNumber;
float n = b * PI * 2.0 * 4.0;
float m = c * PI * 2.0 * 5.0;
float sn = (sin (n * textureCoordOut.x) * 0.5) + 0.5;
float cn = (cos (m * textureCoordOut.y) * 0.5) + 0.5;

vec4 col = vec4 (b, sn, cn, 1.0);
gl_FragColor = col;
}

cs (perhaps) ought to be cos (rather than sin)