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 8 of 8

Thread: caching computed values from fragment programs

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Adelaide, South Australia, Australia
    Posts
    839

    caching computed values from fragment programs

    Hello,

    I need to do some very crazy blending in a multi-pass rendering loop and trying to figure out a way to preserve blending coefficients between passes.

    I need to compute new blend coefficients in a fragment program that will be used in the next render pass. Ideally I'd like to be able to write this coefficient to the framebuffer so I can then read it back in the next iteration, compute a new value, and write it back.

    The problem is that fragment programs can't access the frame-buffer. The only way I can think of getting this functionality is to copy the alpha channel to a texture and using the texture as input to a fragment program, but I'd like to avoid the copying overhead when it seems so conceptually simple for a fragment program to source coefficients from the framebuffer.

    I investigated the possibility of writing values to a texture, but that doesn't seem to be possible either.

    Does anyone have any ideas on how I can cache data from one render-pass to the next?

    [edit: the other point is that I can't use render-to-texture (which would also save the copy) because it isn't yet supported under GLX. damn, eh?]

    thanks in advance,
    John

    [This message has been edited by john (edited 09-03-2003).]

  2. #2
    Member Regular Contributor
    Join Date
    Aug 2003
    Location
    France
    Posts
    299

    Re: caching computed values from fragment programs

    And same question, is there a way to have access to the Z-Buffer for the current fragment, or to the stencil buffer ?

    SeskaPeel.

    [edit] Actually, the only way I found at this point was to write to destination alpha, and use it in subsequent passes, by tweaking the blending equation to get what you want. I did not find a way to make it work for my current problem though.

    [This message has been edited by SeskaPeel (edited 09-03-2003).]

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: caching computed values from fragment programs

    Originally posted by SeskaPeel:
    And same question, is there a way to have access to the Z-Buffer for the current fragment, or to the stencil buffer ?

    SeskaPeel.
    Topic hijacking is impolite. Anyway, as I don't have anything to say regarding john's issue ...

    My copy of the ARB_fragment_program spec goes to great lengths explaining the interaction with depth. You get read access to depth via fragment.depth and write access via result.depth.

    Please don't tell me that my version of the spec is outdated and depth access has been subsequently removed ...

  4. #4
    Member Regular Contributor
    Join Date
    Aug 2003
    Location
    France
    Posts
    299

    Re: caching computed values from fragment programs

    Here is what I made so far :

    Code :
    // Pass 1
    glBlendFunc(GL_ONE, GL_ZERO) ;
    // Render scene
     
    // Pass 2
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE) ;
    glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE) ;
    // Render scene
    This way, you can cache a scalar value that is supposed to modulate your 2nd pass. I need a 4-uple to perform everything though ...

    The aim is to encode per pixel ambient / diffuse ratio in the frame buffer alpha channel, but I need the rgb value to modulate my diffuse pass too. I get those rgb and alpha value with bump + cubic diffuse, I'd like to compute it only once ...

    SeskaPeel.


    [This message has been edited by SeskaPeel (edited 09-03-2003).]

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

    Re: caching computed values from fragment programs

    fragment.depth is not the zbuffers value for that fragment position, its just the incomming fragments depth value.

    so, No, there is no way to access the zbuffers values, or the stencil buffers values from the fragment_program

  6. #6
    Member Regular Contributor
    Join Date
    Aug 2003
    Location
    France
    Posts
    299

    Re: caching computed values from fragment programs

    zeckensack -> you're being rude, and you have no reason to be. First, I tried to answer his question, and then I completed by another one, so this is no topic hijacking. Second, fragment.depth is definitely not the z-buffer value.

    SeskaPeel.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: caching computed values from fragment programs

    I didn't mean to be rude. I don't think "impolite" is an overly harsh word, though I'm not a native English speaker and may be wrong.

    Regarding framebuffer depth, yes, you're correct. result.depth appears to be write only, and is pre-test anyway. Sorry for that.

    Maybe it'll be sufficient if you copy-to-depth-texture and bind that to your fp to gain read access. That would be very slow with frequent updates though.

  8. #8
    Member Regular Contributor
    Join Date
    Aug 2003
    Location
    France
    Posts
    299

    Re: caching computed values from fragment programs

    Hum ... might be interesting. Actually I could copy to texture the whole first pass, and access this data in the second. There would be no update at all.

    But, ... how can I get correct s,t texture coordinates to look up in that frame buffer copied texture for the current fragment ?

    SeskaPeel.

Posting Permissions

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