Light projection matrix for shadows

how do i have to calculate a light projection matrix for an given light (vec4)??? … any easy way … or do i have to caluclate it by myself using something like the viewtransformation???


… not sure … perhaps there was no answer because of my kind of question … for all who, don’t know the answer like me some hours ago :slight_smile: there are to different way to get the light projection matrix … one using opengl and setting the camera direct to light postion and catching the matrix from stack … no sure how it works, but there are a lot of people, which say it would work … the other way is to calculte the matrix yourself … just remember your are searching for intersections of lines with a plane … i don’t want to explain it in detail, because the red book (p583) does it a better way i ever could do :slight_smile:

I usually just set the texturematrix with the standard commands ( like it was a camera)

// scale and bias becuse texture coords are from 0 to 1, not -1 to 1

// set up projection.

// and place the light

… but how can i get this matrix in my shader???


is it more efficent to use the texture matrix than sendUniform…() ?? or why your are doing it this way??

I dont know whats more efficient, but i do know that its very easier to make fallbacks into the fixed pipe this way.

sorry for getting on your nervs … but i tried it your way and theres nothing to see … im not sure whats going wrong … i thought i only have to do
somethink like this

in vert
gl_Position = gl_TextureMatrix[0] * gl_Vertex;

in frag
gl_FragColor = vec4(0.5,0.5,0.5,1.0);

didnt you said you want to cast a texture? then you should use the result from the texturematrix and the vertices to lookup in a texture, not position the vertices.

gl_TexCoord[0] = gl_TextureMatrix[0] * gl_Vertex; (objectspace, not viewspace casting);

gl_FragColor = texture2dProj(sampler,gl_TexCoord[0]);

my main target is to do something like a shadow mapper … therefore i have to create a depth map from the point of view of the light … i though it would be greate work for a shader … for creating this map i tough i have to transform each vertex with the light projection matrix … first i wanted to generate it myself in the shader … but this matrix is the same for each vertex … so i think its better getting it form gl and put it in the shader …

a shadow mapper does 2 things.

first you render the scene from the lights position, that has nothing to do with casting, just use the lights position as it was a camera, if you have a matrix for the light, just inverse that and set it as the first matrix instead of the cameramatrix, and render the depthvalues into a map ( either a real depthmap, or store the depth encoded in RGB)

second you use that texture, render from the cameraview, and use the castroutine described above to cast the texture from the light.

then you need a comparison method as well, but try to get that working first.

… yes this is how shadow mapping is working … sure … so lets go a step back … the goal is to write a skin shader for a human … ‘realtime skin rendering - ati paper’ first i’m rendering the diffuse lightning into an off-screen buffer … no problem … in the next step i want to add shadows in my offscreen texture … therefore i need the projection matrix from the lights poit of view … how and where can i get this matrix??? thats my question …

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.