Skip to content

Instantly share code, notes, and snippets.

@onedayitwillmake
Created August 7, 2012 19:12
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onedayitwillmake/3288507 to your computer and use it in GitHub Desktop.
Save onedayitwillmake/3288507 to your computer and use it in GitHub Desktop.
Rotating in GLSL
// Simple Lambertian lighting
// Mario Gonzalez
//
// Based on 'WebGL - A Beginners Guide'
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
uniform vec3 rotation;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat4 uNMatrix;
varying vec3 vNormal;
varying vec4 vPosition;
varying vec3 vEyeVec;
mat4 rotationX( in float angle ) {
return mat4( 1.0, 0, 0, 0,
0, cos(angle), -sin(angle), 0,
0, sin(angle), cos(angle), 0,
0, 0, 0, 1);
}
mat4 rotationY( in float angle ) {
return mat4( cos(angle), 0, sin(angle), 0,
0, 1.0, 0, 0,
-sin(angle), 0, cos(angle), 0,
0, 0, 0, 1);
}
mat4 rotationZ( in float angle ) {
return mat4( cos(angle), -sin(angle), 0, 0,
sin(angle), cos(angle), 0, 0,
0, 0, 1, 0,
0, 0, 0, 1);
}
void main( void ) {
vec4 vertex = vec4(gl_Vertex.xyz, 1.0);
vertex = vertex * rotationX(rotation.x) * rotationY(rotation.y) * rotationZ(rotation.z);
vertex = uMVMatrix * vertex;
vNormal = vec3( uNMatrix * vec4( gl_Normal, 1.0 ) );
vEyeVec = -vec3( vertex.xyz );
// * rotationX(uTimer*5.0)
gl_Position = uPMatrix * vertex;
vPosition = gl_Position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment