hello, i would like some fresh ideas to help solve my issue.
so i have engine with deferred rendering, i already have implemented point lights with dual paraboloid shadows\pcf. they’re working fine.
but I’ve stumbled upon some unexpected issues trying to implement cone spotlights in similar way, but with single projective shadow map.
my depth texture setup is basic:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
float borderColor[4] = {1.0, 1.0, 1.0, 0.0};
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LESS);
glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT16, shadowResolution, shadowResolution, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, textureObject, 0);
and same setup works for point lights quite nice.
how i render objects to shadow map:
glColorMask(0, 0, 0, 0);
glBindFramebuffer(GL_FRAMEBUFFER, lightSource[f].frameBufferObject);
glClear(GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, lightSource[f].shadowResolution, lightSource[f].shadowResolution);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(97.5f, 1.0f, 1.0, lightSource[f].radius * 2.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glRotatef(-lightSource[f].rotation.x, 1, 0, 0);
glRotatef(-lightSource[f].rotation.y, 0, 1, 0);
glRotatef(-lightSource[f].rotation.z, 0, 0, 1);
glTranslatef(-lightSource[f].position.x, -lightSource[f].position.y, -lightSource[f].position.z);
lightSource[f].getMatrix();
for(unsigned i = 0; i < lightSource[f].affectedObjects.size(); i++)
Objects[lightSource[f].affectedObjects[i]].renderSpotlight(lightSource[f].Radius * 2.0);
glPopMatrix();
and the shader is, basically ftransform();
all the geometry is in the right place. issue is covered in depth value i get from generated shadow map.
so i try to use it like that, while rendering light cone:
vec3 position = modelMatrix * vec4(texture2D(positionSampler, gl_FragCoord.xy).xyz, 1.0);
float attenuation = distance(lightPos, position)/lightRadius;
vec3 coord = (lightMatrix * backPosition).xyz;
float len = length(coord.xyz);
coord /= len;
coord.xy = coord.xy * 0.5 + 0.5;
shadow = shadow2DProj(shadowMap, vec4(coord.x, coord.y, attenuation, 1.0)).x;
and see no shadow map effect. until i set attenuation to something about 0.99-1.0; obviously, it won’t produce correct depth comparison. but coord.xy values are correct. i guess it has something to do with perspective… tried differend manipulations with attenuation value\W component - no acceptable result. if i manually output linearized depth values from shadowmap - they are correct.