Pro OpenGL ES for iOS

(singke) #1

CHAPTER 10: OpenGL ES 2, Shaders, and... (^331)
[m_Sphere setBlendMode:PLANET_BLEND_MODE_SOLID];
[m_Sphere execute:m_EarthNightTexture.name];
glActiveTexture() specifies what TU to use followed by a call to bind the texture.
Afterward, the program can be used to the desired effect.
The cloud-luv'n fragment should now look something like Listing 10-16 to perform the
actual blending.
Listing 10-16. Blends a Second Texture with Clouds on Top of the Others
precision mediump float;
varying lowp vec4 colorVarying;
varying lowp vec4 specularColorVarying;
uniform mat4 modelViewProjectionMatrix;
uniform mat3 normalMatrix;
uniform vec3 lightPosition;
varying vec2 v_texCoord;
uniform sampler2D s_texture;
uniform sampler2D cloud_texture; //1
void main()
{
vec4 finalSpecular=vec4(0,0,0,1);
vec4 surfaceColor;
vec4 cloudColor;
float halfBlue; //a value used to detect a mainly blue fragment.
surfaceColor=texture2D( s_texture, v_texCoord );
cloudColor=texture2D(cloud_texture, v_texCoord ); //2
halfBlue=0.5surfaceColor[2];
if(halfBlue>1.0)
halfBlue=1.0;
if((surfaceColor[0]<halfBlue) && (surfaceColor[1]<halfBlue))
finalSpecular=specularColorVarying;
if(cloudColor[0]>0.15) //3
{
cloudColor[3]=1.0;
gl_FragColor=(cloudColor
1.3+surfaceColor.4)colorVarying;
}
else
gl_FragColor=(surfaceColor+finalSpecular)*colorVarying;
}

Free download pdf