#opengl shadowmapping depth render

24 messages ยท Page 1 of 1 (latest)

lethal pond
#

its been days, im trying to render the depth buffer, but all i got is a black screen

ill send everything you need to know (i think) ive been trying to debug this for days now

#

some part in the main.cpp

programShadowMap.use();
glUniform1i(shadowUniLoc.sampleDepth, 20); // GL_TEXTURE20 for depth ID
glUseProgram(0);
#
while (!glfwWindowShouldClose(window)) {
    ...
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    //////////// rendering part ////////////
    rend.use();
    rend.clearPixels();

    //sky.draw();
    
    s_FBO.renderDepthShapeDebug(&rend);
    
    ...

    glfwSwapBuffers(window);
    glfwPollEvents();
}```
#

some of the renderer class

void Renderer::use() {
    if (currentRenderer != nullptr)
        currentRenderer->unuse();

    currentRenderer = this;
    framebuffer->use();
}

void Renderer::unuse() {
    currentRenderer = nullptr;
    FBO::setDefaultFBO();
}

void Renderer::render(program* prog, unsigned int ID_pixels) const {
    if (prog != nullptr) {
        prog->use();
    }
    else {
        programFB.use();
    }

    //glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glBindVertexArray(screenVAO);
    glDisable(GL_DEPTH_TEST);
    
    if (framebuffer->getSamples() > 1) {
        //std::cout << "over 1\n";
        int w, h;
        glfwGetFramebufferSize(glfwGetCurrentContext(), &w, &h);

        glBindFramebuffer(GL_READ_FRAMEBUFFER, getFBOmultisample_ID());
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, getFBO_ID());
        glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);

        //std::cout << "done cloned\n";
    }

    FBO::setDefaultFBO();
    glStencilMask(0xFF);

    if (ID_pixels != 0) {
        glActiveTexture(GL_TEXTURE20);
        glBindTexture(GL_TEXTURE_2D, ID_pixels);
    }
    else {
        // its implicitly 0 activate texture index so yeah
        glBindTexture(GL_TEXTURE_2D, getIDPixels());
    }

    glDrawArrays(GL_TRIANGLES, 0, 6);
    glBindTexture(GL_TEXTURE_2D, 0);

    glEnable(GL_DEPTH_TEST);
    glBindVertexArray(0);
}
rare vine
#

aa1

  • drawcall (event ID 15) - totally misses framebuffer area
  • drawcall (event ID 29) - the sampleDepth is not assigned at all
#

fix it.

#

first drawcall (event ID 15). VS output contains gl_Position as (0.0, 0.0, 0.0, 0.0) for every vertex. The vertex shader operates wrong. It could be data or algorithm itself or both. fix it

lethal pond
#
// version and definition (INSTANCE_RENDERING) is handled in the main code

#ifdef DEPTH_RENDER
    layout (location=0) in vec2 position;
#else
    layout (location=0) in vec3 position;
    layout (location=3) in mat4 offset;
#endif

uniform mat4 model;
uniform mat4 lightSpaceMatrix; // this is like view

out vec2 texcoord;

layout (location=1) in vec2 texcoordinate;

void main(){
    #ifndef DEPTH_TESTER
    texcoord = texcoordinate;
    #endif

    #ifndef DEPTH_RENDER
        #ifdef INSTANCE_RENDERING
            gl_Position = lightSpaceMatrix * (model*offset) * vec4(position, 1.0);
        #else
            gl_Position = lightSpaceMatrix * model * vec4(position, 1.0);
        #endif
    #else
        gl_Position = vec4(position, 0.0, 1.0);
        return;
    #endif

}
//#version 330 core

#ifndef DEPTH_TESTER
in vec2 texcoord;
uniform sampler2D sampleDepth;
out vec4 color;
#endif

void main(){
    #ifndef DEPTH_TESTER
        return;
    #endif

    #ifndef DEPTH_TESTER
    float depthValue = texture(sampleDepth, texcoord).r;
    color = vec4(vec3(depthValue), 1.0);
    #endif
}

i basically made 3 seperate program for it after seeing your suggestion

#

and it still put a black screen

#

texture and position looks good to me when i checked, but its somehow not putting the texture or the depth is tweaking

#

@rare vine

rare vine
#

I will not write shader/C++ code for you. Sorry. I suggest to make things step by step. Do not start next step of the algorithm until you will be absolutely sure that previous steps produce expected result. Validate results via RenderDoc. I already showed 3 clues which obviously wrong in current implementation. I do not know why they wrong - it's up for you to debug and fix.

lethal pond
#

im not asking u to write, just check it and see if theres a mistake to it

#

bc like im lost and cant find it

#

just read the new shadowFBO::renderDepthShapeDebug one, is it in the right order tho

rare vine
#

you are asking actually

lethal pond
#

u said u will not write

#

im not asking u to help me write it ๐Ÿ™

#

i just want u to like read if its in the wrong order or something

#

just in case

rare vine
#

grow up already. Try harder. Find issue. That's how programmer engineer should work.