Sign in to follow this  

Render cubemap texture to cubemap framebuffernot aligned

Recommended Posts

I'm rendering  a frameBuffer texture to another frameBuffer for multiple pass shadows.

The problem is it's not aligning correctly.

 

Heres my code:

glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO[totalLights]);
            glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            shaderMultipassShadows.Use();
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, depthCubemap[0]);

            glUniform1i(glGetUniformLocation(shaderMultipassShadows.Program, "depthMap"), 0);
            RenderQuad();
            glBindFramebuffer(GL_FRAMEBUFFER, 0);

 

 

geometry shade:

 

#version 330 core
layout (triangles) in;
layout (triangle_strip, max_vertices=18) out;

void main()
{
    for(int face = 0; face < 6; ++face)
    {
        gl_Layer = face; // built-in variable that specifies to which face we render.
        for(int i = 0; i < 3; ++i) // for each triangle's vertices
        {
            gl_Position = gl_in[i].gl_Position;
            EmitVertex();
        }    
        EndPrimitive();
    }
}

 

 

 

vertex shader:

 

#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 texCoords;

out vec2 TexCoords;

void main()
{
    gl_Position = vec4(position, 1.0f);
    TexCoords = texCoords;
}

 

 

 

#version 330 core

in vec2 TexCoords;
out vec4 FragColor;
uniform samplerCube depthMap;

void main()
{
    FragColor = textureCube(depthMap, vec3(TexCoords, 1.0f));
}

 

 

Thank you.

 

Share this post


Link to post
Share on other sites

Solved:

 

for (GLuint i = 0; i < 6; ++i)
            {
                glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO[totalLights] + i);
                glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

                shaderMultipassShadows.Use();
                glActiveTexture(GL_TEXTURE0);
                glBindTexture(GL_TEXTURE_2D, depthCubemap[0] + i);

                glUniform1i(glGetUniformLocation(shaderMultipassShadows.Program, "depthMap"), 0);
                RenderQuad();
                glBindFramebuffer(GL_FRAMEBUFFER, 0);
            }

Share this post


Link to post
Share on other sites

Im using this geometry shader code:

 

#version 330 core
layout (triangles) in;
layout (triangle_strip, max_vertices=18) out;

uniform mat4 shadowTransforms[6];

out vec4 FragPos; // FragPos from GS (output per emitvertex)
out vec2 TexCoords;
void main()
{
    for(int face = 0; face < 6; ++face)
    {
        gl_Layer = face; // built-in variable that specifies to which face we render.
        for(int i = 0; i < 3; ++i) // for each triangle's vertices
        {
            FragPos = gl_in[i].gl_Position;
            gl_Position = shadowTransforms[face] * FragPos;
            //TexCoords = vec2( 0.5, 0.5 );
            EmitVertex();
        }    
        EndPrimitive();
    }
 

 

 

And this code for the transforms;

 

// 0. Create depth cubemap transformation matrices
            std::vector<glm::mat4> shadowTransforms;
            shadowTransforms.push_back(glm::lookAt(glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)));
            shadowTransforms.push_back(glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-1.0, 0.0, 0.0), glm::vec3(0.0, -1.0, 0.0)));
            shadowTransforms.push_back(glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0, 1.0, 0.0), glm::vec3(0.0, 0.0, 1.0)));
            shadowTransforms.push_back(glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0, -1.0, 0.0), glm::vec3(0.0, 0.0, -1.0)));
            shadowTransforms.push_back(glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0, 0.0, 1.0), glm::vec3(0.0, -1.0, 0.0)));
            shadowTransforms.push_back(glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0, 0.0, -1.0), glm::vec3(0.0, -1.0, 0.0)));

            for (GLuint i = 0; i < 6; ++i)
                glUniformMatrix4fv(glGetUniformLocation(shaderMultipassShadows.Program, ("shadowTransforms[" + std::to_string(i) + "]").c_str()), 1, GL_FALSE, glm::value_ptr(shadowTransforms[i]));
            
 

If i play about with the eye matrixes the shadows get rendered in different positions but Idon't know the correct values.

Any ideas?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this