CHAPTER 10: OpenGL ES 2, Shaders, and... (^321)
glClearColor(gray,gray,gray, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//nightside
[self useProgram:m_NightsideProgram];
[m_Sphere setBlendMode:PLANET_BLEND_MODE_SOLID];
[m_Sphere execute:m_EarthNightTexture.name];
//dayside
[self useProgram:m_DaylightProgram];
[m_Sphere setBlendMode:PLANET_BLEND_MODE_FADE];
[m_Sphere execute:m_EarthDayTexture.name];
//atmosphere
glCullFace(GL_FRONT);
glEnable(GL_CULL_FACE);
glFrontFace(GL_CW);
frame++;
}
On the day side of the earth, I use the program m_DaysideProgram, while on the night
side, I use another one, called m_NightsideProgram. Both use the identical vertex shader,
as shown in Listing 10-10.
Listing 10-10. The Vertex Shader for Both the Day and Night Sides of the Earth
attribute vec4 position;
attribute vec3 normal;
attribute vec2 texCoord; //1
varying vec2 v_texCoord;
varying lowp vec4 colorVarying;
uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;
uniform vec3 lightPosition; //2
void main()
{
v_texCoord=texCoord; //3
vec3 eyeNormal = normalize(normalMatrix * normal);
vec4 diffuseColor = vec4(1.0, 1.0, 1.0, 1.0);
singke
(singke)
#1