Last active
April 24, 2017 20:09
-
-
Save manuel-delverme/a76f792bb3c2788413fb61ea67d684d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // cube definition | |
| attribute vec4 vCubePosition; | |
| attribute vec4 vCubeColor; | |
| attribute vec3 vFaceNormal; | |
| // color WHAT is this? | |
| varying vec4 fColor; | |
| // textures | |
| attribute vec2 v2TexturesCoord; | |
| varying vec2 fTexCoord; | |
| uniform vec3 theta; | |
| // Phong model | |
| uniform vec4 ambientProduct, diffuseProduct, specularProduct; | |
| uniform mat4 modelViewMatrix; | |
| uniform mat4 projectionMatrix; | |
| uniform vec4 lightPosition; | |
| uniform float shininess; | |
| void main() | |
| { | |
| // Compute the sines and cosines of theta for each of | |
| // the three axes in one computation. | |
| vec3 angles = radians( theta ); | |
| vec3 c = cos( angles ); | |
| vec3 s = sin( angles ); | |
| /* | |
| // Remeber: thse matrices are column-major | |
| mat4 rx = mat4( 1.0, 0.0, 0.0, 0.0, | |
| 0.0, c.x, s.x, 0.0, | |
| 0.0, -s.x, c.x, 0.0, | |
| 0.0, 0.0, 0.0, 1.0 ); | |
| mat4 ry= mat4( c.y, 0.0, -s.y, 0.0, | |
| 0.0, 1.0, 0.0, 0.0, | |
| s.y, 0.0, c.y, 0.0, | |
| 0.0, 0.0, 0.0, 1.0 ); | |
| mat4 rz = mat4( c.z, s.z, 0.0, 0.0, | |
| -s.z, c.z, 0.0, 0.0, | |
| 0.0, 0.0, 1.0, 0.0, | |
| 0.0, 0.0, 0.0, 1.0 ); | |
| */ | |
| vec3 pos = -(modelViewMatrix * vCubePosition).xyz; | |
| //fixed light postion | |
| vec3 light = lightPosition.xyz; | |
| vec3 L = normalize( light - pos ); | |
| vec3 E = normalize( -pos ); | |
| vec3 H = normalize( L + E ); | |
| vec4 NN = vec4(vFaceNormal,0); | |
| // Transform vertex normal into eye coordinates | |
| vec3 N = normalize( (modelViewMatrix*NN).xyz); | |
| // Compute terms in the illumination equation | |
| vec4 ambient = ambientProduct; | |
| float Kd = max( dot(L, N), 0.0 ); | |
| // vec4 diffuse = Kd * diffuseProduct; | |
| vec4 diffuse = diffuseProduct; | |
| float Ks = pow( max(dot(N, H), 0.0), shininess ); | |
| // vec4 specular = Ks * specularProduct; | |
| vec4 specular = specularProduct; | |
| if( dot(L, N) < 0.0 ) { | |
| specular = vec4(0.0, 0.0, 0.0, 1.0); | |
| } | |
| // Phong model | |
| fColor = ambient + diffuse + specular; | |
| fColor.a = 1.0; | |
| fTexCoord = v2TexturesCoord; | |
| // gl_Position = rz * ry * rx * vCubePosition; | |
| gl_Position = projectionMatrix * modelViewMatrix * vCubePosition; | |
| gl_Position.z = -gl_Position.z; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment