View Full Version : light projection matrix for shadows
04-13-2004, 02: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???
04-13-2004, 11: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 :)
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
04-14-2004, 12:58 AM
.. but how can i get this matrix in my shader???
04-14-2004, 05:17 AM
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.
04-14-2004, 05: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
gl_Position = gl_TextureMatrix * gl_Vertex;
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 = gl_TextureMatrix * gl_Vertex; (objectspace, not viewspace casting);
gl_FragColor = texture2dProj(sampler,gl_TexCoord);
04-15-2004, 12:11 AM
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.
04-15-2004, 02: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 ..
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.