• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
mv348

FBO - Render to texture not working

3 posts in this topic

I am trying to implement cascaded shadow maps but I am having a strange issue with my FBO. As far as I can tell I am completely unable to write to the attached depth-texture. Even using glClear(GL_DEPTH_BUFFER_BIT) and trying various different clear values, I am unable to see any changes in the texture when I render it to the screen.

 

Here's a peek at some of my code:

bool CascadedShadowMap::Initialize(unsigned int WindowWidth, unsigned int WindowHeight)
{
m_width = WindowWidth;
m_height= WindowHeight;
 
    // Create the FBO
    glGenFramebuffers(1, &m_fbo);
 
    // Create the depth buffer
    glGenTextures(1, &m_shadowMap);
    glBindTexture(GL_TEXTURE_2D, m_shadowMap);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, 2 * WindowWidth, 2 * WindowHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, m_shadowMap, 0);
 
    // Disable writes to the color buffer
    glDrawBuffer(GL_NONE);
 
 
    GLenum Status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
 
    if (Status != GL_FRAMEBUFFER_COMPLETE) {
        vDebugOut("error initializing shadow map! -CasadedShadowMap.cpp");
 
return false;
    }
 
    return true;
}
 

The debug message is not printed so I know the frame buffer is complete. I also made sure the function is being called.

 

Here's where the texture should be cleared:

 
void vGraphics::fillShadowTextureDirectionalCascadedMap()
{
 
m_noFragmentShader->enable();
 
glPushAttrib(GL_VIEWPORT_BIT);
 
cascaded_shadow_map->BindForWriting();
 
cascaded_shadow_map->Clear();
 
// Rendering models commented out for now. Trying to get Clear() to work.
/* 
...
*/
 
glPopAttrib();
 
m_noFragmentShader->disable();
}
 

[/code]

The methods "BindForReading" and "Clear" shown above are implemented like so:
 

 
void CascadedShadowMap::BindForWriting()
{
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
}
 
void CascadedShadowMap::Clear()
{
glViewport(0, 0, 2* m_width, 2 * m_height);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST);
glDrawBuffer(GL_NONE);
glDisable(GL_DEPTH_CLAMP);
glClearDepth(0.25f);
glClear(GL_DEPTH_BUFFER_BIT);
}
 

 
As you can see I'm setting a lot of options to try to make absolutely certain that nothing will prevent the GBuffer from getting cleared. 
 
Now, just before my light pass, have:

m_dirLightShader->enable();
cascaded_shadow_map->BindForReading(7);
m_dirLightShader->setCascadedShadowUnit(7);

 
 
Here's the code for the two functions above.
 

void vDirectionalLightShader::setCascadedShadowUnit(GLuint textureUnit)
{
glUniform1i(m_unif_casc_shadow_map_id, textureUnit);
}
...
void  CascadedShadowMap::BindForReading(GLenum TextureUnit)
{
glEnable(GL_TEXTURE_2D);
    glActiveTexture(TextureUnit);
    glBindTexture(GL_TEXTURE_2D, m_shadowMap);
}

 
Now at the end of my fragment shader in my light pass (or "texture render pass" if you will):
 

 
float mapSample = (texture(gCascadedShadowMap, TexCoord).x);
 
FragColor =   vec4(mapSample,mapSample,mapSample,1);
 
}
 
Its worth noting that if I say:
cascaded_shadow_map->BindForReading(0); then the texture bound to texture unit 0 (I think its the Position map on my deferred rendering set up) displays perfectly fine. But using the texture unit that the texture CascadedShadowMap::m_shadowMap is bound to, produces a pure black screen, regardless of what I set the depth clear color to in CascadedShadowMap::Clear().
 
Any ideas would be most appreciated. Thanks!
Edited by mv348
0

Share this post


Link to post
Share on other sites

first thing i'd check is if the texture you are writing to is somehow still bound, on ANY texture unit

can't think of anything else

0

Share this post


Link to post
Share on other sites

I don't think thats it. I'm not using the texture for anything else.

 

(edit) Being doing more testing and it would appear that the depth clearing is being applied to my g-buffer (previously bound frame buffer) and not to the shadow FBO. I can't see why though, I am definitely binding the shadow FBO before clearing the depth buffer.

Edited by mv348
0

Share this post


Link to post
Share on other sites

Fixed a small bug - I forgot to reset the glClearDepth to 1.0f after setting it to 0.25f. But still not working. 

 

I think it has something to do with my gBuffer. My gBuffer has 4 color textures and a depth/stencil texture attached to its FBO. The shadow map FBO has only a depth texture attached. When I do my light pass I have my g-buffer fbo bound, and then I bind the shadow-map's shadow texture to an appropriate texture unit. It appears as if the gBuffer cannot "see" the shadow texture sitting in the unbound FBO. By my understanding I thought this would work but is there some technicality here that I'm not aware of?

0

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  
Followers 0