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 }