O'Reilly logo

OpenGL ES 2 for Android by Kevin Brothaler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding a Skybox Shader Program

Let’s continue by creating a vertex shader for our skybox. Create a new file in your raw resource folder called skybox_vertex_shader.glsl, and add the following contents:

Skybox/res/raw/skybox_vertex_shader.glsl
 
uniform mat4 u_Matrix;
 
attribute vec3 a_Position;
 
varying vec3 v_Position;
 
 
void​ main()
 
{
 
v_Position = a_Position;
 
v_Position.z = -v_Position.z;
 
 
gl_Position = u_Matrix * vec4(a_Position, 1.0);
 
gl_Position = gl_Position.xyww;
 
}

First we pass on the vertex position to the fragment shader, as seen on the first line inside main, and then we invert the position’s z component on the next line; this gives the fragment shader a position that will be interpolated across each face of the cube so ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required