I’m trying to do shadow mapping with a color buffer, so instead of using GL_COMPARE_R_TO_TEXTURE I’m doing things myself. I’ve got everything working with depth textures and GL_COMPARE_R_TO_TEXTURE, but I can’t seem to get it to work when I do it myself. I’ve posted both shaders below, and they’re very similar. The depth-component texture works, but the RGBA texture doesn’t generate shadows.
I’m writing the following as depth to the color buffer:
vec4 mvp_Vertex = gl_ModelViewProjectionMatrix * gl_Vertex;
frag_Depth = mvp_Vertex.z/mvp_Vertex.w;
Here is the relevant part of the shader using color buffers
uniform sampler2D frag_Shadowmap;
uniform vec2 frag_Dimensions;
varying vec4 frag_Vertex;
varying vec3 frag_Normal;
varying vec4 frag_ShadowCoord;
float ShadowMap(sampler2D shadowmap, vec4 texCoord) {
if (frag_ShadowCoord.q < 0.0) return 1.0;
float depth = texture2D(shadowmap, texCoord.st/texCoord.q).x;
return float( depth <= texCoord.p / texCoord.q );
}
And the same code using depth buffers
uniform sampler2DShadow frag_Shadowmap;
uniform vec2 frag_Dimensions;
varying vec4 frag_Vertex;
varying vec3 frag_Normal;
varying vec4 frag_ShadowCoord;
float ShadowMap(sampler2DShadow shadowmap, vec4 texCoord) {
if (frag_ShadowCoord.q < 0.0) return 1.0;
float depth = shadow2D(shadowmap, texCoord.stp/texCoord.q).x;
return depth;
}