Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: shadow maps and fragment program

  1. #1
    Junior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    Vancouver, BC, Canada
    Posts
    118

    shadow maps and fragment program

    How do I use these together? As I understand it the way shadow maps work is by projecting the texture over the scene normally, but instead of using the colour value they compute it using Cv = textureCoord.r >= Cf ? 1 : 0.

    While my texture coordinates for s and t are valid it seems r is always 1 in my fragment program.. Actually r doesn't seem to be 1, it is far greater than 1. It seems I need to normalize it.

    How do I normalize my r coordinate if this is the case?

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2003
    Posts
    25

    Re: shadow maps and fragment program

    How did you project your vertices to the shadow map? Normally, you project them with following transformations:

    (s,t,r,q) = BiasMat * Projectionmatrix(LightSource) * Modelviewmatrix(LightSource)

    Projectionmatrix(LightSource) and ModelviewMatrix(LightSource) are the matrices you used to render the scene from the light source.

    0.5 0 0 0.5
    0 0.5 0 0.5 = BiasMat
    0 0 0.5 0.5
    0 0 0 0

    With this matrix you transform the coordinate system from window/screen space to texture space (is that the correct expression?).

    By doing these transformations correctly, you normally have a r-coordinate between 0 and 1. Maybe you forgot to do a homogeneous divide in your vertex program.


    [This message has been edited by mako (edited 07-31-2003).]

    [This message has been edited by mako (edited 07-31-2003).]

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2003
    Location
    USA
    Posts
    25

    Re: shadow maps and fragment program

    Originally posted by titan:
    How do I use these together? As I understand it the way shadow maps work is by projecting the texture over the scene normally, but instead of using the colour value they compute it using Cv = textureCoord.r >= Cf ? 1 : 0.

    How do I normalize my r coordinate if this is the case?
    The q-coordinate in (s,t,r,q) is not necessarily 1.0 when you receive it after interpolation in the fragment program. Try to divide (s,t,r,q) by q. It worked for me when I did shadow mapping and PCF in a fragment program.

    - SFRuckus

  4. #4
    Junior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    Vancouver, BC, Canada
    Posts
    118

    Re: shadow maps and fragment program

    Originally posted by SFRuckus:
    Try to divide (s,t,r,q) by q. It worked for me when I did shadow mapping and PCF in a fragment program.
    Of course. I don't know why I wasn't doing that. While this does give me a grey similar to the that of the texture I can't do the a valid compare of coordinate.z (after *(1/q)) with the result of the TXP function. Any idea what I could be missing?

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2003
    Location
    USA
    Posts
    25

    Re: shadow maps and fragment program

    Originally posted by titan:
    Of course. I don't know why I wasn't doing that. While this does give me a grey similar to the that of the texture I can't do the a valid compare of coordinate.z (after *(1/q)) with the result of the TXP function. Any idea what I could be missing?
    Here is what I do: shCoord holds projected and biased position of fragment (relative to the light). The shadow map is in texture[0].
    After
    Code :
    TEMP R;
    TXP  R.z, fragment.texcoord[0], texture[0], 2D;
    SLT  R.w, shCoord.z, R.z;
    I have R.w = 0 if in shadow and R.w = 1 otherwise.

Posting Permissions

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