PDA

View Full Version : light projection matrix for shadows



andreasMank
04-13-2004, 01:06 AM
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???

thx

andreasMank
04-13-2004, 10:32 PM
.. 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 :) 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 :)

Mazy
04-13-2004, 10:40 PM
I usually just set the texturematrix with the standard commands ( like it was a camera)

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
// scale and bias becuse texture coords are from 0 to 1, not -1 to 1
glTranslatef(0.5,0.5,0.5);
glScalef(0.5,0.5,0.5);

// set up projection.
gluPerspective(FOV,aspect,zNear,zFar);

// and place the light
glMultMatrixf(lightposInv);

andreasMank
04-13-2004, 11:58 PM
.. but how can i get this matrix in my shader???

Mazy
04-14-2004, 12:12 AM
gl_TextureMatrix[0];

andreasMank
04-14-2004, 04:17 AM
is it more efficent to use the texture matrix than sendUniform..() ?? or why your are doing it this way??

Mazy
04-14-2004, 04:31 AM
I dont know whats more efficient, but i do know that its very easier to make fallbacks into the fixed pipe this way.

andreasMank
04-14-2004, 04:37 AM
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);

Mazy
04-14-2004, 04:56 AM
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_Position=ftransform();
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_Vertex; (objectspace, not viewspace casting);

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

andreasMank
04-14-2004, 11:11 PM
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 ..

Mazy
04-15-2004, 12:30 AM
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.

andreasMank
04-15-2004, 01:56 AM
.. 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 ..