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 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: tests i can use before fragment program

  1. #11
    Junior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Germany
    Posts
    205

    Re: tests i can use before fragment program

    An rough front-to-back rendering order of your objects could also help a little bit without the need to add the additional z-only pass...

    @dorbie: what hardware/driver/vendor has problems with GL_EQUAL and early z-reject? And what about GL_LEQUAL?

  2. #12
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: tests i can use before fragment program

    I'm not dorbie, but I'm assuming you meant to ask me: LEQUAL is fine on all hardware. We're told that EQUAL reduces acceleration on at least the Radeons (I forget about the others).
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

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

    Re: tests i can use before fragment program

    It's a hardware issue. You can't do early out without (ab)using early z and stencil testing on anything except the GeForce 6800 series.

  4. #14
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: tests i can use before fragment program

    Originally posted by zed:
    from looking at the spec it seems perpixel fragment programs come before alpha,stencil,depth,scissor test etc.
    basically since my fragment programs are pretty expensive (less than 5fps for a 640x480 window) im wondering if theres anyway i can bypass the fragment test if a certain condition is met, eg only perform on pixels whose screenalpha's are greater than 0.5.

    though i believe what i want aint possible
    so my next best bet is to discard the fragment as soon as possible in the shader
    whats the best way of doing this

    FWIW i would assume this would be, stuck right at the start of the shader
    if ( a > b )
    discard;

    BUT on my gffx5200 66.00drivers runs a lot slower than
    if ( a < b )
    {
    ..
    ..
    }

    cheers zed
    First, one thing to note regarding the < and > operators. Try to avoid using >, use >= instead whenever possible. Same with <=, avoid it and use < instead whenever possible. This is because < maps directly to SLT and >= maps to SGE (which is essentially just SLT with reversed operands). Other comparisons require more instructions.

    Regarding early-outing from a fragment shader, take a look at this demo:
    http://www.humus.ca/?page=3D&id=50

    Basically, I draw the compare function to alpha in a first pass, and use alpha testing to set stencil to 1 for selected pixels. In the next pass early stencil rejection throws away the fragments, which saves loads of fragment processing.

    In this case I'm using the light radius as the determining factor, anything outside the light radius will be rejected, but you can use any rejection critera.

  5. #15
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: tests i can use before fragment program

    cheers humus, yeah from further research it seems if (..) statements (unless they are constant bool's) are useless on gffx's for early out. im gonna have to implement something like u suggest on your site involving extra passes

    >>if possible "discard" as much as you can in the vertex program.>>

    oh yeah to clarify this aint possible is it? ie it doesnt matter what happens in the vertex program the result will always get passed to the pixel shader

  6. #16
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: tests i can use before fragment program

    From the documents, it says that discard is for fragment shaders only. The compiler should flag an error if you use in a vertex shader.

    I don't see how a video card would handle a "discard" on the vertex processor anyway.
    It would be like killing a polygon and any polygon that is sharing that vertex.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  7. #17
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: tests i can use before fragment program

    Ah, something for future hardware. Discard on vertices to perform polygon reduction in realtime.

Posting Permissions

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