Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 05 Oct 2011
Offline Last Active Dec 06 2014 01:10 PM

Topics I've Started

How many dedicated Shaders to use?

06 December 2014 - 01:12 PM

So I've read its best to write dedicated shaders for specific purposes rather than bloat them with too many conditionals. And it makes sense. But I look at how many options are possible and it quickly becomes overwhelming:


1. Normal mapping

2. GPU Tesselation / Displacement mapping

3. Shadow mapping

4. Animation/Skinning


I could go with or without the each of these for any particular shader, resulting in 16 possible shaders. When you consider I have to write shaders for shadow passes for different types of lights (point, spot, directional, etc). the number of shaders quickly becomes ridiculous.


What's a smart way to cluster these and keep it reasonable?



Trouble reading from depth-texture

28 July 2013 - 09:46 PM

In my last post I stated that I was having trouble with rendering to a depth texture. But I believe the following has demonstrated that the render to texture is successful and the issue is I can't read from the texture after the rendering is complete. 


I used glReadPixels to check if my depth texture is being cleared. I used the following after calling glClear:
glBindFramebuffer(GL_READ_FRAMEBUFFER,  m_fbo);
float depth;
glReadPixels(0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
printf("depth value is %f",depth);
The print message outputs whatever clear depth I've set before calling glClear (with the fbo bound as the draw buffer), so I at least now know that the depth texture IS being written to. The problem is I just can't get my shaders to read from it! Here is where the texture is sampled:

float mapSample = (texture( gCascadedShadowMap, TexCoord).x);
FragColor =   vec4(mapSample,mapSample,mapSample,1);

I am well aware of the usual faintness of the depth-texture rendering, that's why I'm using glClear() with a depth value of around 0.5. I should be seeing a mid-gray screen when I render, but instead I just see blackness. If I set other textures to gCascadedShadowMap, however, it draws the texture to the screen correctly.
Any help or ideas would be greatly appreciated!

FBO - Render to texture not working

20 July 2013 - 05:35 PM

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);
    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
    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()
// Rendering models commented out for now. Trying to get Clear() to work.


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

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:


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)
    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!

Stencil shadow volumes - a thing of the past?

08 June 2013 - 05:16 PM

After realizing the benefits of stencil shadow volumes for handling point-light shadows, I have been determined to add them to my own graphics engine. Days have turned into weeks and weeks into months. I can easily cast beautiful, clean shadows behind an occluder; but the self shadowing always suffers from ugly artifacts. 


I thought I'd found my solution to cast smooth silhouette edges here, but issues involving z-fighting and the per-polygon nature of these calculations always ensure self-shadowing issues crop up. Countless tweaks and special case handling haven't gotten me out of the woods.


Even if I can get this working, I have more concerns. How well will GPU tessellation and displacement mapping work with stencil shadow volumes? Can I realistically expect to get the smoothness of shadow maps with these per-polygon calculations?


Moreover, all the literature I find on stencil shadow volumes seems to be at least 6 years old.. and it has me wondering are they just not practical anymore?


The only possibility I can see is if you used a hybrid: shadow-maps to handle self shadowing, and projected stencil shadow volumes elsewhere. But I wonder if you might as well go for all-shadow maps in that case.


If there are any proponents of stencil shadow volumes here, I'd love to know how you handle these concerns because if I switch to only shadow maps, I'll have to throw away a lot of work! :(


Per-polygon self shadowing problem with stencil shadows

04 May 2013 - 08:07 AM

I'm facing a somewhat obvious problem with shadow volumes that I somehow failed to anticipate. I just wanted a few tips and suggestions on how to deal with it.
We love shadow-volumes because they provide perfect resolution shadows with none of the aliasing artifacts that are characteristic of shadow maps. But the only case where this fails is on the occluder itself. Since the silhouette edge is calculated on a per-polygon basis, the self shadowing can appear jagged.
I couldn't get a clear screenshot so I just drew up a pic.
Attached File  silhoette-jaggies.jpg   33.36KB   33 downloads
What are some common ways to deal with this? 
So far my ideas are:
1. Blur the shadow a lot.
2. Use very high polygon models with stencil shadows
3. Use gpu tesselation to make polygons finer
4. Use a hybrid system with a shadow-map to handle self shadowing.
1 works a bit but still creates noticable artifacts.
2 is very limiting
3 is maybe a good idea but complicated as it involves not only subdividing the mesh, but also keeping track of adjacent vertices for silhouette edge calculation
4 seems like a good idea except the main reason i'm using stencil shadows is that shadow maps are not greatly suited for point lights.
Ideas and suggestions would be most appreciated! smile.png