From bd57f345ed9dbed1d81683e48199626de2ea9044 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 27 Jun 2025 10:18:39 -0700 Subject: Restructure project --- shaders/skyquad.vert | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 shaders/skyquad.vert (limited to 'shaders/skyquad.vert') 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 @@ +uniform mat4 CameraRotation; // From camera space to world space. +uniform float Fovy; +uniform float Aspect; + +layout (location = 0) in vec2 Position; + +out vec3 Ray; + +// We would typically normalize the vector, but there is no need to do so when +// sampling a cube map. +vec3 sky_ray(vec2 FilmPosition) +{ + //float d = 0.5 / tan(Fovy/2.0); + // return vec3((FilmPosition.x - 0.5) * Aspect, + // FilmPosition.y - 0.5, + // -d); + float d = 0.5 / tan(Fovy/2.0); + return vec3(FilmPosition, -d); +} + +void main() +{ + vec2 FilmPosition = Position * 0.5; // map [-1,1] -> [-1/2, +1/2] + Ray = mat3(CameraRotation) * sky_ray(FilmPosition); + // Set z to the background. + gl_Position = vec4(Position, 0.99999, 1.0); // z=1 -> send to background +} -- cgit v1.2.3