326 CHAPTER 10: OpenGL ES 2, Shaders, and...^
Figure 10-4. Earth seen from space as it reflects the sun
Naturally we are going to have to write our own specular reflection shader (or in this
case, add it to the existing daylight shader).
Swap the old vertex shader for Listing 10-14, and swap the fragment shader for the one
in Listing 10-15. Here I precalculate the specular information along with normal diffuse
coloring, but the two are kept separate until the fragment shader. The reason is that not
all parts of the earth are reflective, so the land masses shouldn’t get the specular
treatment.
Listing 10-14. Vertex Shader for the Secular Reflection
attribute vec4 position;
attribute vec3 normal;
attribute vec2 texCoord;
varying vec2 v_texCoord;
varying lowp vec4 colorVarying;
varying lowp vec4 specularColorVarying; //1
uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;
uniform vec3 lightPosition;
uniform vec3 eyePosition;
void main()
{
float shininess=100.0;
float balance=.75;
vec3 normalDirection = normalize(normalMatrix * normal); //2
vec3 eyeNormal = normalize(eyePosition);
vec3 lightDirection;
float specular=0.0;
v_texCoord=texCoord;
eyeNormal = normalize(normalMatrix * normal);