diff options
Diffstat (limited to 'shaders/skyquad.vert')
-rw-r--r-- | shaders/skyquad.vert | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/shaders/skyquad.vert b/shaders/skyquad.vert new file mode 100644 index 0000000..c0c46e6 --- /dev/null +++ b/shaders/skyquad.vert | |||
@@ -0,0 +1,27 @@ | |||
1 | uniform mat4 CameraRotation; // From camera space to world space. | ||
2 | uniform float Fovy; | ||
3 | uniform float Aspect; | ||
4 | |||
5 | layout (location = 0) in vec2 Position; | ||
6 | |||
7 | out vec3 Ray; | ||
8 | |||
9 | // We would typically normalize the vector, but there is no need to do so when | ||
10 | // sampling a cube map. | ||
11 | vec3 sky_ray(vec2 FilmPosition) | ||
12 | { | ||
13 | //float d = 0.5 / tan(Fovy/2.0); | ||
14 | // return vec3((FilmPosition.x - 0.5) * Aspect, | ||
15 | // FilmPosition.y - 0.5, | ||
16 | // -d); | ||
17 | float d = 0.5 / tan(Fovy/2.0); | ||
18 | return vec3(FilmPosition, -d); | ||
19 | } | ||
20 | |||
21 | void main() | ||
22 | { | ||
23 | vec2 FilmPosition = Position * 0.5; // map [-1,1] -> [-1/2, +1/2] | ||
24 | Ray = mat3(CameraRotation) * sky_ray(FilmPosition); | ||
25 | // Set z to the background. | ||
26 | gl_Position = vec4(Position, 0.99999, 1.0); // z=1 -> send to background | ||
27 | } | ||