I want to create an equirectangular projection from six quadratic textures, similar to converting a cubic projection image to an equirectangular image, but with the separate faces as textures instead of one texture in cubic projection.
I'd like to do this on the graphics card for performance reasons, and therefore want to use a GLSL Shader.
I've found a Shader that converts a cubic texture to an equirectangular one: link
Step 1: Copy your six textures into a cube map texture. You can do this by binding the textures to FBOs and using glBlitFramebuffer()
.
Step 2: Run the following fragment shader. You will need to vary the Coord
attribute from (-1,-1) to (+1,+1) over the quad.
#version 330
// X from -1..+1, Y from -1..+1
in vec2 Coord;
out vec4 Color;
uniform samplercube Texture;
void main() {
// Convert to (lat, lon) angle
vec2 a = Coord * vec2(3.14159265, 1.57079633);
// Convert to cartesian coordinates
vec2 c = cos(a), s = sin(a);
Color = sampler(Texture, vec3(vec2(s.x, c.x) * c.y, s.y));
}