// GL Shading Language version 1.0 Vertex Shader // Orion Sky Lawlor, olawlor@acm.org, 2006/08/31 (Public Domain) // C++/vertex shader interface uniform float spin_x, spin_y, aspect; // Vertex/fragment shader interface: varying vec4 color; // Material diffuse color varying vec3 normal; // Surface normal // Input: gl_Vertex. Output: gl_Position. void main(void) { // Vertex positions come from the C program: vec4 v1 = gl_Vertex; mat4 m1=mat4(0.0); mat4 m2=mat4(0.0); mat4 m3=mat4(0.0); { float angle=spin_x*1.0*6.28; float c=cos(angle), s=sin(angle); //v2.z = cos(angle)*v1.z + -sin(angle)*v1.y; //v2.y = sin(angle)*v1.z + cos(angle)*v1.y; m1[0].x=1.0; m1[2].z=c; m1[2].y=s; m1[1].z=-s; m1[1].y=c; m1[3].w=1.0; } { float angle=spin_y*1.0*6.28; float c=cos(angle), s=sin(angle); //v3.z = cos(angle)*v2.z + -sin(angle)*v2.x; //v3.x = sin(angle)*v2.z + cos(angle)*v2.x; m2[1].y=1.0; m2[2].z=c; m2[2].x=s; m2[0].z=-s; m2[0].x=c; m2[3].w=1.0; } // Perspective matrix m3[0].x=aspect; m3[1].y=1.0; m3[2].z=0.1; m3[2].w=1.0; m3[3].w=1.9; /* Transform normal by same matrices as position, but skip the perspective step, and any translations (set w==0.0) */ //normal=normalize(vec3(m2*m1*vec4(gl_Normal,0.0))); /* Simple version: Just use fixed normals */ normal=normalize(gl_Normal); gl_Position = m3*m2*m1*v1; // gl_Position is where onscreen the vertex will be drawn. // We'll set color the same as input position color=gl_Color; }