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: ARB Fragment Program

  1. #1
    Junior Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Michigan, USA
    Posts
    188

    ARB Fragment Program

    Okay, please do not flame this post.

    I have been studying the ARB fragment program extensions, but I could not figure out how to do this. I need to interpolate position and normal
    for each pixel. The idea is I need to execute
    an equation involving position + normal. Basically, I need to "shoot" a ray from each pixel of a model to an invisible plane, and the determine the intersection point. I can then use this in a lookup function to generate a color.

    I can do this easily in a vertex program, but not so in a fragment program. I know I can pass the normal in the color of each vertex, and let the system interpolate that normal. But I need the position prior to rasterization.

    Am I asking for the impossible. Thanks in advance.

  2. #2
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: ARB Fragment Program

    What position prior to rasterization? Do you mean world space info? You could pass this in and have it interpolated. Just pass the vertex position info to the fragment program by asigning it to an additional interpolated parameter prior to multiplication by the modelview & projection.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Michigan, USA
    Posts
    188

    Re: ARB Fragment Program

    I am confused. How would you do that. The vertex position should be multiplied by the model-view, and for each pixel interpolated. That is for tthe pixel, just prior to rasterization, the x,y,z.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Posts
    748

    Re: ARB Fragment Program

    I fail to see where the problem is. Transform your position and your normal in the vertex shader, and pass them in two of the texture coordinates interpolators. You'll get the interpolated values per pixel - all's left for you is to renormalize the normal if needed (its length can be invalid in the pixel shader since it's linearly interpolated) and to sample your lookup texture.

    Y.

  5. #5
    Junior Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Michigan, USA
    Posts
    188

    Re: ARB Fragment Program

    Well, I was looking for some code as you just described, but I cannot find it. Can you please post a a couple of lines showing how to do this.

    Thank you very much.

  6. #6
    Intern Contributor
    Join Date
    Feb 2002
    Location
    Vienna Austria
    Posts
    99

    Re: ARB Fragment Program

    MOV result.texcoord[0] position;
    MOV result.texcoord[1] normal;

    where position is the position you want to have interpolated along the triangle and normal the normal.

    to access those in the fragment program you simlpy have to access them there through fragment.texcoord[0] and fragment.texcoord[1] respectively

  7. #7
    Junior Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Michigan, USA
    Posts
    188

    Re: ARB Fragment Program

    Now, the precision will be 3 @ 32 bit. That is for tex coordinates s t r, each will be a 32 bit float. From what I can tell this is not true.

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Sep 2000
    Location
    SWEDEN
    Posts
    718

    Re: ARB Fragment Program

    Yes, texture coordinates are interpolated at float precision, though not necessarily 32 bits. Just try it, and you'll find it works.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Michigan, USA
    Posts
    188

    Re: ARB Fragment Program

    I tried a variation on your suggestion. The result was not good. I passed in the tex coordinate like so

    glEnable(GL_TEXTURE_3D);
    for i = 1 to 3
    glTexCoord3f( (norm[i][0]+1.0)/2.0,(norm[i][1]+1.0)/2.0,
    (norm[i][2]+1.0)/2.0);
    glVertex3fv( vert[i] );

    Then in my fragment program, I access the normal from TEXCOORD0

    and multiplied by 2, subtracted 1

    And the results showed the same "quality" as if I had passed the norms into glColor3f

    Ie

    glColor3f( (norm[i][0]+1.0)/2.0,(norm[i][1]+1.0)/2.0,
    (norm[i][2]+1.0)/2.0);

    and the used COLOR0 instead of tex coord 0.

    This seems to imply that tex coordinates are 8 bit values. Is this true? If so, then how does you method do any better? Thanks.

  10. #10
    Junior Member Regular Contributor
    Join Date
    Jun 2003
    Location
    Virginia
    Posts
    215

    Re: ARB Fragment Program

    I don't think you have to pass only unsigned values, so the scale and bias are unnecessary.

Posting Permissions

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