skybox.vp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #version 140
  2. uniform vs_uniforms
  3. {
  4. uniform mediump mat4 view_proj;
  5. uniform mediump mat4 world;
  6. };
  7. in highp vec3 position;
  8. out mediump vec3 var_texcoord0;
  9. void main()
  10. {
  11. /*
  12. * Transform the position vector using the world view projection matrix
  13. * and override the Z component with the W component. After the vertex
  14. * shader is complete the rasterizer takes gl_Position vector and performs
  15. * perspective divide (division by W) in order to complete the projection.
  16. * When we set Z to W we guarantee that the final Z value of the position
  17. * will be 1.0. This Z value is always mapped to the far Z. This means that
  18. * the skybox will always fail the depth test against the other models in
  19. * the scene. That way the skybox will only take up the background left
  20. * between the models and everything else will be infront of it.
  21. */
  22. mat4 wvp = world * view_proj;
  23. vec4 wvp_pos = wvp * vec4(position, 1.0);
  24. gl_Position = wvp_pos.xyww;
  25. /*
  26. * Use the original position in object space as the 3D texture coordinate.
  27. * This makes sense because the way sampling from the cubemap works is by
  28. * shooting a vector from the origin through a point in the box or sphere.
  29. * So the position of the point actually becomes the texture coordinate.
  30. * The vertex shader passes the object space coordinate of each vertex as
  31. * the texture coordinate and it gets interpolated by the rasterizer for
  32. * each pixel. This gives us the position of the pixel which we can use for
  33. * sampling.
  34. */
  35. var_texcoord0 = position;
  36. }