1 attribute highp vec3 aPosition;
2 attribute highp vec2 aTexCoord;
3 attribute highp vec3 aNormal;
4 varying mediump vec2 vTexCoord;
5 varying mediump vec3 vIllumination;
6 varying mediump float vSpecular;
7 uniform mediump vec3 uSize;
8 uniform mediump mat4 uMvpMatrix;
9 uniform mediump mat4 uModelView;
10 uniform mediump mat3 uNormalMatrix;
11 uniform mediump mat4 uObjectMatrix;
12 uniform mediump vec3 uLightPosition;
16 vec4 vertexPosition = vec4(aPosition*min(uSize.x, uSize.y), 1.0);
17 vertexPosition = uObjectMatrix * vertexPosition;
18 vertexPosition = uMvpMatrix * vertexPosition;
20 //Illumination in Model-View space - Transform attributes and uniforms
21 vec4 vertPos = uModelView * vec4(aPosition.xyz, 1.0);
22 vec4 lightPos = uModelView * vec4(uLightPosition, 1.0);
23 vec3 normal = normalize(uNormalMatrix * aNormal);
25 vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );
26 vec3 viewDir = normalize(-vertPos.xyz);
28 vec3 halfVector = normalize(viewDir + vecToLight);
30 float lightDiffuse = dot( vecToLight, normal );
31 lightDiffuse = max(0.0,lightDiffuse);
32 vIllumination = vec3(lightDiffuse * 0.5 + 0.5);
34 vec3 reflectDir = reflect(-vecToLight, normal);
35 vSpecular = pow( max(dot(reflectDir, viewDir), 0.0), 4.0 );
37 vTexCoord = aTexCoord;
38 gl_Position = vertexPosition;