I’m trying to implement Shadow Mapping with this tutorial ,
but I’m now at a loss because the projective texture breaks when I move the camera view.
And here’s some codes…
This is the second pass which renders the scene from the camera view.
And the UpdateViewMatrix() is the camera view routine which calls glMultMatrixf(g_CamViewMatrix).
Hi,
I’m the author of this tutorial !
Where do you store your projective matrix?
And can you post the code of the g_ProgObj program? I think the problem can be here.
In fact, I think my algo for computing the invCamViewMatrix only works when (g_LookAt.x, g_LookAt.y, g_LookAt.z) is the null vector : (0.0, 0.0, 0.0), just because I only invert the 3x3 upper-part of the camViewMatrix and I set the last column myself, assuming that this is a null vector !
You must write a little inverting function for doing this when this vector is non-null, and I think this should do the trick.
nice tutorial,
though I wonder if I can implement it with GL 1.3 ie no shaders…
while it looks like one can do everything manually, is it possible to generate the shadowmap tex coordinates for display lists ?
from my experience one cannot change tex coords outside of a display list, only using texGen, which likely couldnt do the job
or could one create a proper texcoord using eye_linear ??
edit: hmm kinda overlooked what the fragment program does, guess there is no real non shader workaround for that
CrazyButcher, check out this tutorial . It implements shadow mapping using only ARB_depth_texture and ARB_shadow extensions : ARB_depth_texture for storing the depth map texture and ARB_shadow for performing per-fragment comparison.
For computing projective coordinates, it uses glTexGen.
@ S&W : I was wrong, my code also works for any non-null (g_LookAt.x, g_LookAt.y, g_LookAt.z)! So the problem is not here. Just to be sure : have you modified this part of code ??? :
I can’t found any error in your code : all seems ok !!!
Are you using Catalyst 4.4 ? My demo doesn’t work with any older drivers.
Oh… and you must call :
glLightfv(GL_LIGHT0, GL_POSITION, pos);
with the GL_MODELVIEW_MATRIX set to the camViewMatrix.
GreK: FX5600.
The problem i have is that the lightsource seams to folow the camera around, i might be able to fix it myself but the code is a mess since i had to attach it to my own engine with a viritual staplegun.
Edit: silly me i forgot that i moved the getinverseviewmatrix fuction to my lightclass and i used the lightsource cordinates instead of the camera position coords, it sortof works now.
Well, I’ve succeeded in implementing with this tutorial .
But these are fixed functions,
so is it possible to use a texture matrix which generated by glEnable(GL_TEXTURE_GEN_S/T/R/Q) in GLSL shaders?
I think you can use the generated texture coordinates in a pure GLSL fragment program (i.e. a GLSL program without vertex shaders), but I never try to do so, so I can’t guarantee it.
The standard math library should define M_PI when you include <math.h>, but some versions of MSVC require that you #define _USE_MATH_DEFINES before including <math.h> for them to be defined. Typically, you’d set this in your precompiled header for the project.
A better value for M_PI is 3.14159265358979, which is as far as I’ve memorized – but the web will come through should you need more precision