June 2013
Intermediate to advanced
346 pages
8h 42m
English
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 ...
Read now
Unlock full access