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

Thread: Faking gl_FragCoord?

  1. #11
    Member Regular Contributor
    Join Date
    Mar 2007
    Location
    California
    Posts
    396

    Re: Faking gl_FragCoord?

    I have experienced errors in pixel shaders that only went away when I eliminated reading from output variables. These problems only arose in certain shaders, and went away when I eliminated the reads. So it might be something that you won't notice until you are far into development.

    Thanks for the advice, this works:

    lightvolume.vert:
    Code :
    uniform vec2 buffersize;
     
    varying vec4 fake_FragCoord1;
     
    void main(void) {
    	gl_FrontColor = gl_Color;
    	vec4 pos = ftransform();
    	fake_FragCoord1=pos;
    	gl_Position=pos;
    }

    And then at the beginning of the pixel shader:
    Code :
    	vec3 fake_FragCoord;
    	fake_FragCoord.x = ((fake_FragCoord1.x/fake_FragCoord1.w)*0.5+0.5)*buffersize.x;
    	fake_FragCoord.y = ((fake_FragCoord1.y/fake_FragCoord1.w)*0.5+0.5)*buffersize.y;
    	fake_FragCoord.z = 0.5*fake_FragCoord1.z/fake_FragCoord1.w+0.5;

    So now my code works on AMD hardware. Never use gl_FragCoord unless you only target NVidia! The y component will be flipped on SOME AMD cards, with some drivers, sometimes only when rendering to an FBO. So even if it works on your test setup, you will have users complaining about upside-down images and other bad stuff.

  2. #12
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    781

    Re: Faking gl_FragCoord?

    Quote Originally Posted by Leadwerks
    Once you write to gl_Position, just assume you can never read back that value. You will get some really unpredictable glitches if you read from write-only variables.
    if (hardware can't read from output registers and shader reads from previously written output)
    then (shader compiler writes output to temp, reads from temp, moves temp to output)
    else (shader compiler is broken)

  3. #13
    Member Regular Contributor
    Join Date
    Mar 2007
    Location
    California
    Posts
    396

    Re: Faking gl_FragCoord?

    shader compiler is broken
    Happens all the time.

  4. #14
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    781

    Re: Faking gl_FragCoord?

    while (driver has bug)
    developer files bug

    while (vendor has active bugs)
    vendor fixes bug

  5. #15
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,290

    Re: Faking gl_FragCoord?

    iirc, the missing gl_FragCoord has been a bug in ATi's drivers for many moons already.

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

    Re: Faking gl_FragCoord?

    while (driver has bug)
    developer files bug

    while (vendor has active bugs)
    vendor fixes bug
    Say whatever you like, but ATi has no interest in fixing bugs that aren't in major OpenGL game products. So until Id or Blizzard start using glslang combined with FBOs and gl_FragCoord, I wouldn't hold my breath no matter how many times you file a bug report.

  7. #17
    Member Regular Contributor
    Join Date
    Mar 2007
    Location
    California
    Posts
    396

    Re: Faking gl_FragCoord?

    Actually, AMD told me this would be fixed in Catalyst 8.10, due out this month, but I wanted to go ahead and write a workaround for now.

  8. #18
    Member Regular Contributor
    Join Date
    Mar 2007
    Location
    California
    Posts
    396

    Re: Faking gl_FragCoord?

    Looks like this was indeed fixed in AMD drivers 8.10.

  9. #19
    Junior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Germany
    Posts
    205

    Re: Faking gl_FragCoord?

    But still not fixed for FireGL mobility cards; at least not for the current driver for the IBM W500 ThinkPad... :-(

Posting Permissions

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