Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: FSAA implemented as a fragment shader

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14

    FSAA implemented as a fragment shader

    Hi,

    I would like to know if it would be theseable to write a fragmentshader that performs fullscreen antialiasing.

    Performance is not an issue. I am writing a comparison about antialiasing methods and I would like to have actual code for the different methods. If this is not really doable in opengl, I'll move along to supersampling using the accumulation buffer.

    My basic idea is to render into a bigger sized sperate framebuffer. Then let the fragmentshader fill my geometry with color. Then have a second fragment shader read the fragment's colors and compare it to its neighbours, calculation intermediate colors. And lastly blitting the sperate framebuffer to the smaller windowmanager's framebuffer.

    Is there a way to access the fragment's colors? Or do I have to completly render my scene and access the pixels through gl_readPixels()?

  2. #2
    Member Newbie
    Join Date
    Dec 2013
    Posts
    45
    First of all, full-screen anti-aliasing and supersample anti-aliasing are the same thing.

    Second, the only proper way to do true supersample anti-aliasing is (as far as I know) to turn it on in your driver settings. You COULD emulate it by rendering to a texture and then doing a second render pass that renders a square over the entire screen, and then samples the texture in the fragment shader. If you are on OpenGL 4.2, you could use Image Load Store in your second pass to directly access texels without going through the sampling hardware.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,650
    No, not really. The latter is one possible implementation of the former. Along with MSAA, FXAA, MLAA, GPAA, GBAA, SDAA, etcetc.

    Second, the only proper way to do true supersample anti-aliasing is (as far as I know) to turn it on in your driver settings.
    For the system (window) framebuffer possibly, but for off-screen multisample render targets you can request through the OpenGL API that SSAA-based rendering be enabled. The GL lingo for this is per-sample shading (see ARB_sample_shading), as opposed to per-pixel shading (which is what you get with MSAA or when the render target is single sampled).

  4. #4
    Member Newbie
    Join Date
    Dec 2013
    Posts
    45
    I may well be wrong, but I was under the impression that MSAA, SSAA, FXAA, etc are all distinct. Of course Wikipedia isn't always the best source, but here's where I got the idea that FSAA and SSAA are synonymous.

    For the system (window) framebuffer possibly, but for off-screen multisample render targets you can request through the OpenGL API that SSAA-based rendering be enabled. The GL lingo for this is per-sample shading (see ARB_sample_shading), as opposed to per-pixel shading (which is what you get with MSAA or when the render target is single sampled).
    I wasn't aware of that, I stand corrected. For the OP, here is a link to more info on multisample framebuffers.

    In light of that, would the best way to do this be to render to a multisample FBO and then blit it to the main framebuffer?

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,650
    Quote Originally Posted by sektion31 View Post
    Is there a way to access the fragment's colors? Or do I have to completly render my scene and access the pixels through gl_readPixels()?
    You can do either. If you render to an offscreen multisample framebuffer (with SSAA, MSAA, or whatever), then you can read back the individual subsamples with texelFetch() in a fragment shader to get a single sample texture you can easily read back.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,650
    Quote Originally Posted by chbaker0 View Post
    I may well be wrong, but I was under the impression that MSAA, SSAA, FXAA, etc are all distinct.
    Yes, in terms of algorithms. Though you can combine these algorithms together when performing FSAA .

    Of course Wikipedia isn't always the best source, but here's where I got the idea that FSAA and SSAA are synonymous.
    Yeah, I think that article is slightly confused. FSAA (unlike the rest) isn't a specific algorithm. It stands for "full screen antialiasing", so it encompasses all algorithms which implement some form of full-screen antialiasing.

    For instance, here's the output of NVidia's FSAA mode list dump, which can be applied to GLX windows:

    Code :
    > nvidia-settings --query=fsaa --verbose
    ...
        Valid 'FSAA' Values
          value - description
            0   -   Off
            1   -   2x (2xMS)
            5   -   4x (4xMS)
            7   -   8x (4xMS, 4xCS)
            8   -   16x (4xMS, 12xCS)
            9   -   8x (4xSS, 2xMS)
           10   -   8x (8xMS)
           11   -   16x (4xSS, 4xMS)
           12   -   16x (8xMS, 8xCS)
           14   -   32x (8xMS, 24xCS)

    Here you can see that some of these FSAA modes use MSAA, and some use a combination of it with CSAA or SSAA

  7. #7
    Member Newbie
    Join Date
    Dec 2013
    Posts
    45
    That makes sense, thank-you for the correction.

  8. #8
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Well i did mean "traditional" supersampling (rendering at higher resolutions), when i wrote FSAA. So i wasnt using the terms correctly.
    I wanted to distinguish between higher resolution super sampling and "shifted scene" supersampling. So far I havent found a different name for the later.

    Quote Originally Posted by Dark Photon View Post
    You can do either. If you render to an offscreen multisample framebuffer (with SSAA, MSAA, or whatever), then you can read back the individual subsamples with texelFetch() in a fragment shader to get a single sample texture you can easily read back.
    thanks for the hint. this was what i was looking for!
    so far i managed to render to and read back from a texture, but I came across two questions:

    1. How do texelFetch() and texture() differ? The official description says the later is for texels and the former is for a single texel. But both methods return gvec4. So how does texture() return multiple texels? Or what exactly does it return?
    2. For my prove of concept I fed gl_FragCoord to texelFetch, to get an exact copy of a texture. This works, but isn't texelFetch ought to get absolute coordinates, instead of texelFetch's relative coordinates?

    ok, so the next thing will be to actually implement a supersampling algorithm.

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,650
    Quote Originally Posted by sektion31 View Post
    Well i did mean "traditional" supersampling (rendering at higher resolutions), when i wrote FSAA. So i wasnt using the terms correctly.
    I wanted to distinguish between higher resolution super sampling and "shifted scene" supersampling. So far I havent found a different name for the later.
    Ok. Not sure if there's a standard name, but when I've tripped over it it's called MultiPass Accumulation Buffer AA. Conceptually very similar, but you don't take the hit of storing all the supersamples, and filtering is done progressively as-you-go. But you do take the hit of passing the geometry down the pipe multiple times.

    How do texelFetch() and texture() differ? ... how does texture() return multiple texels? Or what exactly does it return?
    Think of texelFetch() as bypassing texture filtering. You address a specific sample in a specific texel, and that's what you get. texture() honors texture filtering and wrapping modes, potentially sampling a number of texels, and filters (averages) them down to give you an average texel value.

    isn't texelFetch ought to get absolute coordinates, instead of texelFetch's relative coordinates
    Not sure I understand. For a screen-size texture, you can address individual pixels/texels directly through gl_FragCoord, which are absolute relative ot the resolution of the window (presuming your viewport fills your window): (0,0)..(xres,yres):

    texelFetch( tex, ivec2( gl_FragCoord.xy ), ... )

  10. #10
    Junior Member Newbie
    Join Date
    Jul 2013
    Posts
    14
    Quote Originally Posted by Dark Photon View Post
    Ok. Not sure if there's a standard name, but when I've tripped over it it's called MultiPass Accumulation Buffer AA. Conceptually very similar, but you don't take the hit of storing all the supersamples, and filtering is done progressively as-you-go. But you do take the hit of passing the geometry down the pipe multiple times.
    It sounds interesting, but I havent heard of games using it. I wonder why. Mabybe its more difficult with higher AA modes than 2x. Haven't had a closer look yet.

    Quote Originally Posted by sektion31
    isn't texelFetch ought to get absolute coordinates, instead of texelFetch's relative coordinates
    Quote Originally Posted by Dark Photon View Post
    Not sure I understand. For a screen-size texture, you can address individual pixels/texels directly through gl_FragCoord, which are absolute relative ot the resolution of the window (presuming your viewport fills your window): (0,0)..(xres,yres):
    texelFetch( tex, ivec2( gl_FragCoord.xy ), ... )
    eh. bad typo... I meant: isn't texelFetch ought to get absolute coordinates, instead of gl_FragCoord's relative coordinates. Thats how I understand the opengl reference:
    gl_FragCoord contains the window-relative coordinates of the current fragment

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 7
    Last Post: 06-06-2018, 06:35 AM
  2. Replies: 4
    Last Post: 08-03-2017, 01:01 PM
  3. Replies: 7
    Last Post: 09-15-2015, 04:00 AM
  4. Replies: 1
    Last Post: 08-02-2015, 07:45 PM
  5. Can depth peeling be implemented without any shader?
    By elect in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-10-2013, 08:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean