Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: light projection matrix for shadows

  1. #1
    Intern Newbie
    Join Date
    Apr 2004
    Posts
    45

    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???

    thx

  2. #2
    Intern Newbie
    Join Date
    Apr 2004
    Posts
    45

    Re: light projection matrix for shadows

    .. 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

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    596

    Re: light projection matrix for shadows

    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);

  4. #4
    Intern Newbie
    Join Date
    Apr 2004
    Posts
    45

    Re: light projection matrix for shadows

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

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    596

    Re: light projection matrix for shadows

    gl_TextureMatrix[0];

  6. #6
    Intern Newbie
    Join Date
    Apr 2004
    Posts
    45

    Re: light projection matrix for shadows

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

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    596

    Re: light projection matrix for shadows

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

  8. #8
    Intern Newbie
    Join Date
    Apr 2004
    Posts
    45

    Re: light projection matrix for shadows

    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);

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Oct 2001
    Posts
    596

    Re: light projection matrix for shadows

    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]);

  10. #10
    Intern Newbie
    Join Date
    Apr 2004
    Posts
    45

    Re: light projection matrix for shadows

    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 ..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •