aboutsummaryrefslogtreecommitdiff
path: root/shaders/cubemap_filtering.vert
blob: d0cf73fa9ad63d50452c3443ba20181aad839b7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
precision highp float;

#define PI 3.1415926535897932384626433832795
#define FOVY (90.0 * PI / 180.0)

uniform mat4 CameraRotation; // From camera space to world space.
uniform float Flip;

layout (location = 0) in vec2 vPosition;

out vec3 Ray;

// DEBUG
// out vec2 Texcoord;

// This is very similar to the skyquad vertex shader.
//
// The ray is not normalized because it isn't necessary for cubemap sampling.
//
// We also use a fixed fovy = 90 degrees because we want the frustum to pass
// exactly through each face of the cube. The aspect ratio is also just 1.
vec3 sky_ray(vec2 FilmPosition)
{
  float d = 0.5 / tan(FOVY/2.0);
  return vec3(FilmPosition, -d);
}

void main()
{
  vec2 FilmPosition = vPosition * 0.5; // map [-1,1] -> [-1/2, +1/2]
  FilmPosition *= Flip;
  Ray = mat3(CameraRotation) * sky_ray(FilmPosition);
  // TODO: Should disable depth test when rendering.
  gl_Position = vec4(vPosition, 0.99999, 1.0); // z=1 -> send to background

  // DEBUG
  // Texcoord   = FilmPosition + 0.5;
  // Texcoord.y = 1.0 - Texcoord.y;
}