1 // Shader for basic, per-vertex lighting (vertex):
3 attribute mediump vec3 aPosition;
4 attribute highp vec3 aNormal;
5 attribute highp vec2 aTexCoord;
7 varying mediump vec2 vTexCoord;
8 uniform mediump mat4 uMvpMatrix;
9 uniform mediump vec3 uSize;
10 uniform mediump vec3 uObjectDimensions;
11 varying mediump vec3 vIllumination;
12 uniform mediump mat4 uModelView;
13 uniform mediump mat4 uViewMatrix;
14 uniform mediump mat3 uNormalMatrix;
15 uniform mediump vec3 uLightPosition;
19 mediump vec4 vertexPosition = vec4( aPosition * uObjectDimensions, 1.0 );
20 vertexPosition = uMvpMatrix * vertexPosition;
22 vec4 mvVertexPosition = uModelView * vertexPosition;
24 vec3 vectorToLight = normalize( mat3( uViewMatrix ) * uLightPosition - mvVertexPosition.xyz );
26 vec3 normal = uNormalMatrix * aNormal;
27 float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );
28 vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );
30 gl_Position = vertexPosition;