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 13

Thread: depth value in a fragment program

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    depth value in a fragment program

    Sorry if this is a trivial question (and I am quite sure it is), but I am asking it anyway (and doing this here as the advanced forum I guess it would rather belong to seems inaccessible).

    How do I obtain the depth value of a fragment in an NV_fragment_program (NV, not ARB!!!!)? I tried f[WPOS].z as it is proposed in the specs but this simply doesn't work.. f[WPOS].z always seems to be 1.0.

    So, what is going wrong?

    thx
    Jan

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: depth value in a fragment program

    It should just work.
    "What's going wrong" is not an advanced question if you don't explain what the heck you're doing.
    What are you drawing at which coordinates while it's 1.0?
    How do you know it's always 1.0?
    What's your hardware?
    More fragment code please.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: depth value in a fragment program

    ok.. I wroten an higly advanced fragment program for testing purposes:

    MUL H1, f[WPOS].zzzz, 0.5;
    MOV o[COLH], H1;

    this makes *every* fragment have the color grey. If I use 0.1 instead of 0.5, it becomes nearly dark, if I use 0.9, it becomes nearly white, which obviously means that every fragment gets colored with the number in the first line of code, which means that f[WPOS].zzzz is 1/1/1/1.

    hardware obviously is Geforce FX (or does NV_fragment_program run on ati?), 5700 non-ultra to be more specific.

    Thanks
    Jan

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,453

    Re: depth value in a fragment program

    And what's the geometry setup?
    Matrices, vertex programs, primitves rendered?

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: depth value in a fragment program

    does this matter? as everything looks perfectly fine (if not using this fp but the right one) and depth buffering seems to work just perfect, I thought everything would be ok with geometry setup. it is triangle strips rendered with display lists and a vertex program is used for transformation (and several other things). But as I said if everything looks a) fine and b) the same as when not using vp and fp, and c) depth buffering works fine, I guess in general, the program is ok. So I have no idea what could be wrong.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,576

    Re: depth value in a fragment program

    does this matter?
    Yes! The depth value comes from interpolating the post-transformed vertex positions. The matrices and vertex data, therefore, are vital for solving the problem.

    For example, if your depth happened to actually be 1.0, you don't have a problem.

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: depth value in a fragment program

    yes of course but I find it strange that in a totally normal looking scene, the f[WPOS].z value of *all* fragments of the ground seem to be 1.0. The scene looks like this:
    http://de.geocities.com/westphj2003/refl.html

    and as you see, depth buffering seems to work and not all fragments have the same z coordinate. But nonetheless, if I use my test fp above, the whole ground gets entirely grey/white/black, namely the number I use in the MUL statement. So I think this is strange, or I am missing something obvious.

  8. #8
    Intern Contributor
    Join Date
    Jul 2001
    Location
    Santa Clara, CA
    Posts
    84

    Re: depth value in a fragment program

    What near/far plane values are you using?

    Window space Z values are very non-linear, and will often look like white if you copy them to color.

    Originally posted by JanHH:
    yes of course but I find it strange that in a totally normal looking scene, the f[WPOS].z value of *all* fragments of the ground seem to be 1.0. The scene looks like this:
    http://de.geocities.com/westphj2003/refl.html

    and as you see, depth buffering seems to work and not all fragments have the same z coordinate. But nonetheless, if I use my test fp above, the whole ground gets entirely grey/white/black, namely the number I use in the MUL statement. So I think this is strange, or I am missing something obvious.

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Apr 2003
    Posts
    680

    Re: depth value in a fragment program

    near: 1.0
    far: 15000.0

  10. #10
    Junior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    France
    Posts
    129

    Re: depth value in a fragment program

    see how depth buffer evolve with distance: http://www.sgi.com/software/opengl/a...es/node25.html
    when you got distant objects, they'll all look the same in term of color (that is, near 1.0)

    you should maybe do a more discriminative test (like: color=(depth>.8?1:0)) or, if you can, rectify the non linearity of depth buffer (however it's maybe not so easy).

    Anyway let me know results of your investigations, I'll have soon to use depth in my fragment shader and I would be interested to know if you encounter other difficulties


    [This message has been edited by divide (edited 03-17-2004).]

Posting Permissions

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