capedica
05-31-2005, 12:01 AM
Hi,
sorry to ask another question on shadow mapping but i'd like to know if i'm doing all correctly (because nothing goes right).
I'm following this tutorial:
Ampoff (http://www.ampoff.org/modules.php?name=Forums&file=viewtopic&t=15)
The shader code is this:
[VERTEX SHADER]
uniform mat4 tmatrix;
varying vec4 projCoord;
void main()
{
vec3 lightVect, trueNormal;
vec4 realPos = gl_ModelViewMatrix * gl_Vertex;
lightVect = normalize(gl_LightSource[0].position.xyz - realPos.xyz);
trueNormal = gl_NormalMatrix * gl_Normal;
projCoord = tmatrix * realPos;
gl_FrontColor = vec4(dot(lightVect, trueNormal) - 0.1);
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
[FRAGMENT SHADER]
uniform sampler2D shadowMap;
uniform sampler2D lightTex;
varying vec4 projCoord;
const vec4 ambient = vec4(0.13), boost = vec4(1.06);
void main()
{
vec3 projectiveBiased = (projCoord.xyz / projCoord.q);
projectiveBiased = (projectiveBiased + 1.0) * 0.5;
vec4 shadowValue = texture2D(shadowMap, projectiveBiased.xy);
// vec4 lightValue = texture2D(lightTex, projectiveBiased.xy);
//if(shadowValue.z < projectiveBiased.z)
// gl_FragColor = ambient;
//else
// gl_FragColor = boost * gl_Color * lightValue + ambient;
if(shadowValue.z < projectiveBiased.z)
gl_FragColor = vec4(0.3,0.3,0.3,1.0);
else
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}OK, this is what i'm doing:
- i take depth values from light view putting that in a depth texture;
- i calculate tmatrix in this way:
glPushMatrix();
glLoadIdentity();
glMultMatrix(lightProjectionMatrix);
glMultMatrix(lightViewMatrix);
glMultMatrix(InvCameraViewMatrix);
textureMatrix = glGet(GL_MODELVIEW_MATRIX);
glPopMatrix();
- i pass tmatrix and depth texture to shader and draw the scene.
Results are wrong, and when i move camera it seems that texture coordinates are not correctly calculated.
Am i doing something wrong?
Thank you very much.
sorry to ask another question on shadow mapping but i'd like to know if i'm doing all correctly (because nothing goes right).
I'm following this tutorial:
Ampoff (http://www.ampoff.org/modules.php?name=Forums&file=viewtopic&t=15)
The shader code is this:
[VERTEX SHADER]
uniform mat4 tmatrix;
varying vec4 projCoord;
void main()
{
vec3 lightVect, trueNormal;
vec4 realPos = gl_ModelViewMatrix * gl_Vertex;
lightVect = normalize(gl_LightSource[0].position.xyz - realPos.xyz);
trueNormal = gl_NormalMatrix * gl_Normal;
projCoord = tmatrix * realPos;
gl_FrontColor = vec4(dot(lightVect, trueNormal) - 0.1);
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
[FRAGMENT SHADER]
uniform sampler2D shadowMap;
uniform sampler2D lightTex;
varying vec4 projCoord;
const vec4 ambient = vec4(0.13), boost = vec4(1.06);
void main()
{
vec3 projectiveBiased = (projCoord.xyz / projCoord.q);
projectiveBiased = (projectiveBiased + 1.0) * 0.5;
vec4 shadowValue = texture2D(shadowMap, projectiveBiased.xy);
// vec4 lightValue = texture2D(lightTex, projectiveBiased.xy);
//if(shadowValue.z < projectiveBiased.z)
// gl_FragColor = ambient;
//else
// gl_FragColor = boost * gl_Color * lightValue + ambient;
if(shadowValue.z < projectiveBiased.z)
gl_FragColor = vec4(0.3,0.3,0.3,1.0);
else
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}OK, this is what i'm doing:
- i take depth values from light view putting that in a depth texture;
- i calculate tmatrix in this way:
glPushMatrix();
glLoadIdentity();
glMultMatrix(lightProjectionMatrix);
glMultMatrix(lightViewMatrix);
glMultMatrix(InvCameraViewMatrix);
textureMatrix = glGet(GL_MODELVIEW_MATRIX);
glPopMatrix();
- i pass tmatrix and depth texture to shader and draw the scene.
Results are wrong, and when i move camera it seems that texture coordinates are not correctly calculated.
Am i doing something wrong?
Thank you very much.