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 ...
Get OpenGL ES 2 for Android now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.