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/cubemap_filtering.vert | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 shaders/cubemap_filtering.vert (limited to 'shaders/cubemap_filtering.vert') 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 @@ +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; +} -- cgit v1.2.3