diff options
author | 3gg <3gg@shellblade.net> | 2025-06-27 10:18:39 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-06-27 10:18:39 -0700 |
commit | bd57f345ed9dbed1d81683e48199626de2ea9044 (patch) | |
tree | 4221f2f2a7ad2244d2e93052bd68187ec91b8ea9 /shaders/cubemap_filtering.vert | |
parent | 9a82ce0083437a4f9f58108b2c23b957d2249ad8 (diff) |
Diffstat (limited to 'shaders/cubemap_filtering.vert')
-rw-r--r-- | shaders/cubemap_filtering.vert | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/shaders/cubemap_filtering.vert b/shaders/cubemap_filtering.vert new file mode 100644 index 0000000..d0cf73f --- /dev/null +++ b/shaders/cubemap_filtering.vert | |||
@@ -0,0 +1,39 @@ | |||
1 | precision highp float; | ||
2 | |||
3 | #define PI 3.1415926535897932384626433832795 | ||
4 | #define FOVY (90.0 * PI / 180.0) | ||
5 | |||
6 | uniform mat4 CameraRotation; // From camera space to world space. | ||
7 | uniform float Flip; | ||
8 | |||
9 | layout (location = 0) in vec2 vPosition; | ||
10 | |||
11 | out vec3 Ray; | ||
12 | |||
13 | // DEBUG | ||
14 | // out vec2 Texcoord; | ||
15 | |||
16 | // This is very similar to the skyquad vertex shader. | ||
17 | // | ||
18 | // The ray is not normalized because it isn't necessary for cubemap sampling. | ||
19 | // | ||
20 | // We also use a fixed fovy = 90 degrees because we want the frustum to pass | ||
21 | // exactly through each face of the cube. The aspect ratio is also just 1. | ||
22 | vec3 sky_ray(vec2 FilmPosition) | ||
23 | { | ||
24 | float d = 0.5 / tan(FOVY/2.0); | ||
25 | return vec3(FilmPosition, -d); | ||
26 | } | ||
27 | |||
28 | void main() | ||
29 | { | ||
30 | vec2 FilmPosition = vPosition * 0.5; // map [-1,1] -> [-1/2, +1/2] | ||
31 | FilmPosition *= Flip; | ||
32 | Ray = mat3(CameraRotation) * sky_ray(FilmPosition); | ||
33 | // TODO: Should disable depth test when rendering. | ||
34 | gl_Position = vec4(vPosition, 0.99999, 1.0); // z=1 -> send to background | ||
35 | |||
36 | // DEBUG | ||
37 | // Texcoord = FilmPosition + 0.5; | ||
38 | // Texcoord.y = 1.0 - Texcoord.y; | ||
39 | } | ||