Jump to content
  • Advertisement
Sign in to follow this  
Paul Griffiths

Render cubemap texture to cubemap framebuffernot aligned

This topic is 656 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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.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
Advertisement

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.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));
            
 

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!