# Project 2D texture onto a cubemap

I'm looking to take a 2D texture (previously rendered from the user's perspective), and overlay it overtop of a cubemap.

Since a cubemap has 6 textures, I need to run a shader over top of all 6, and use some formula for calculating the UV from a given view.

I'm at a loss for how to calculate this.

Here's an illustration

If the user were to spin around in 1 spot, they would build up full panoramic cubemap.

The intention is to reuse end-of-frame data to update a persistent cubemap that follows the user.

I know how to build manual cubemaps by rendering a scene 6 times, once on all axes, however in this case I wish to take an already rendered view and transplant it onto the correct spots on a cubemap.

I think I was going about this the wrong way. I didn't need to do some unruly math to convert spherical coordinates into UV coordinates for all 6 faces, I just needed to project the quad properly.

I made a fragment shader that simply passes through the texture it's provided, and the texture coordinates are just a quad's UV's (with no alterations).

#version 430 core
layout (location = 0) uniform sampler2D screenTexture;
layout (location = 0) out vec3 OutputColor;
in vec2 TexCoord;

void main()
{
OutputColor = texture(screenTexture, UV).rgb;
}


Recall my goal: to project what the user sees into a cubemap.

In the vertex shader, I position the quad at the far plane of the user's frustum, and then render it from the perspective of each of the 6 viewing angles of the cubemap.

void main()
{
TexCoord = (vertex.xy + vec2(1.0)) / 2.0;

// Strip the translation from the matrix
mat4 InvRotVMatrix = vMatrix_Inverse;
InvRotVMatrix[3][0] = 0;
InvRotVMatrix[3][1] = 0;
InvRotVMatrix[3][2] = 0;

vec4 WorldPos = (InvRotVMatrix * pMatrix_Inverse * vec4(vertex.xyz, 1));
gl_Position = Proj * View[View_Index] * WorldPos;
}