glsl09
09-17-2010, 04:55 AM
hi
i am trying to apply shadow mapping on the scene using glsl. but scene looks weird. there is no problem depth texture calculating because i tested it on the full screen quad. my code is below
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, depthTexture);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5f, 0.5f, 0.5f);
glScalef(0.5f, 0.5f, 0.5f);
glMultMatrixf(lproj); // light projection matrix
glMultMatrixf(lview); // light view matrix
glMultMatrixf(invView.m); // inverse view matrix
vertex shader code
varying vec4 shadowCoord;
varying vec4 texCoord;
void main()
{
gl_Position = ftransform();
vec4 pos = gl_ModelViewMatrix * gl_Vertex;
texCoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
shadowCoord = gl_TextureMatrix[1] * pos;
}
fragment shader code
varying vec4 shadowCoord;
varying vec4 texCoord;
uniform sampler2D diffuseTexture;
uniform sampler2D depthTexture;
void main()
{
vec4 color = texture2D(diffuseTexture, texCoord.xy);
float shadowFactor = texture2DProj(depthTexture, shadowCoord).r;
gl_FragColor = color * shadowFactor ;
}
what i made wrong. thanks in advence
i am trying to apply shadow mapping on the scene using glsl. but scene looks weird. there is no problem depth texture calculating because i tested it on the full screen quad. my code is below
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, depthTexture);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5f, 0.5f, 0.5f);
glScalef(0.5f, 0.5f, 0.5f);
glMultMatrixf(lproj); // light projection matrix
glMultMatrixf(lview); // light view matrix
glMultMatrixf(invView.m); // inverse view matrix
vertex shader code
varying vec4 shadowCoord;
varying vec4 texCoord;
void main()
{
gl_Position = ftransform();
vec4 pos = gl_ModelViewMatrix * gl_Vertex;
texCoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;
shadowCoord = gl_TextureMatrix[1] * pos;
}
fragment shader code
varying vec4 shadowCoord;
varying vec4 texCoord;
uniform sampler2D diffuseTexture;
uniform sampler2D depthTexture;
void main()
{
vec4 color = texture2D(diffuseTexture, texCoord.xy);
float shadowFactor = texture2DProj(depthTexture, shadowCoord).r;
gl_FragColor = color * shadowFactor ;
}
what i made wrong. thanks in advence