Hey,
Back again for what is likely just a trivial error. I am doing some basic & standard Shadow Map rendering.
- geometry only pass writing to a FBO depth_buffer
- second pass comparing fragment depth in light space against the depth_buffer
Problem: I'm nearly positive that I am either (a) not actually writing to depth_buffer or (b) failing to bind it to the second pass fragment shader correctly for reading
Shadow Map Initialization
glGenFramebuffers(1, &shadowmap_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, shadowmap_framebuffer);
glGenTextures(1, &shadowmap_texture);
glBindTexture(GL_TEXTURE_2D, shadowmap_texture);
glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT32, shadowmap_size,shadowmap_size, 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowmap_texture, 0);
// No color output in the bound framebuffer, only depth.
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
// check that our framebuffer is ok
ASSERT( glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE );
glBindFramebuffer(GL_FRAMEBUFFER, 0);
First-Pass shadow render
I've completely eliminated everything except the depth clearing just to sanity check things
c++ side code:
glBindFramebuffer(GL_FRAMEBUFFER, shadowmap_framebuffer);
glViewport(0,0,shadowmap_size,shadowmap_size);
glClearColor(0.f,0.f,0.f,1.f);
glClearDepthf(1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0,0,screenInfo.Width,screenInfo.Height);
Second-Pass depth read
relevant c++ side code
glActiveTexture( GL_TEXTURE3 );
glBindTexture( GL_TEXTURE_BUFFER, shadowmap_texture );
fragment shader
#version 440
layout(binding=3) uniform sampler2DShadow shadowMap;
in vec4 ex_ShadowCoord;
out vec4 outColor;
void main()
{
//shadow
//let's just read something that should be valid
//and also which should definitely pass. If the shadowMap is being cleared to 1.f
//then a lookup with a z == 0.0 should always return 1.0 from texture(...)
vec3 lookupVec = vec3(0.5,0.5,0.0);
float depth = texture( shadowMap, lookupVec );
float visibility = mix( 0.5, 1.0, depth );
//
// VALIDATE shadowMap
//
vec3 color = vec3(0.0,0.0,0.0);
if ( depth == 0.0 )
color.r = 1.0;
else if ( depth == 1.0 )
color.b = 1.0;
else
{
color.r = 1.0;
color.g = 1.0;
}
outColor = vec4( color, 1.0 );
}
Everything is drawing completely RED which means that the texture(...) call is failing at least how I understand it should work. That suggests to me that it's mostly likely not bound correctly (based on prior errors I've made) or perhaps less likely it's not getting written to ever.
I've otherwise validated that the rest of the pipeline is correct (ex_ShadowCoord is coming in correctly and I have full coverage of the scene being rendered)