Search code examples
javaopenglglsllwjglantialiasing

Anti Aliasing based on colors (not textures)


I was searching for an anti-aliasing algorithm for my OpenGL program (so I searched for a good shader). The thing is, all shaders want to do something with the textures, but I dont use textures, only colors. I looked at FXAA most of the time, so is there a anti-aliasing algorithm that just works with colors? My game, what this is for looks blocky like minecraft, but only works with colors and cubes of different size.

I hope someone can help me.

Greetings


Solution

  • Anti-aliasing has nothing specifically to do with either textures or colors.

    Proper anti-aliasing is about sample rate, which while highly technical can be thought of as doing extra work to make a better educated guess at some value that cannot be directly looked up (e.g. a pixel that is only partially covered by a triangle).

    Multisample Anti-Aliasing (MSAA) will work nicely for you, it will only anti-alias polygon edges and does nothing for texture aliasing on the interior of a polygon. Since you are not using textures you do not need to worry about aliasing inside a polygon.

    Incidentally, FXAA is not proper anti-aliasing. FXAA is basically a shader-based edge detection and blur image processing filter. FXAA will blur any part of the scene with sharp edges, whether it is a polygon edge or an edge due to a mapped texture. It indiscriminately blurs anything it thinks is an aliased edge and gets this wrong often, resulting in blurry textures.


    To use MSAA, you need:

    1. A framebuffer with at least 2 samples
    2. Enable multisample rasterization

    Satisfying (1) is going to depend on what you used to create your window (in this case LWJGL). Most frameworks let you select the sample count as one of the parameters at the time of creation.

    Framebuffer Objects can also be used to do this without messing with your window's parameters, but they are more complicated than need be for this discussion.

    (2) is as simple as calling glEnable (GL_MULTISAMPLE).