Ok, I have a simulation I am trying to make. The entire simulation is drawn by circles (with gl_Point) and rectangles (gl_triangles with indices).

It would be great to add some anti aliasing especially as there scale is usually rather small.

My problem is I have seen some formulas that smooth step the edges of a shape, however I do not know how to properly consider scale.

Each sprite will have different scale to it, each rectangle will have a different width / height ratio, not to mention I am not yet passing in texture coords because they have been so far un-necesary. And this will run on multiple screen resolutions.

I guess I have two questions:

  1. Is it possible to anti-alias a rectangle in a fragment shader without knowing the UV of each fragment since I am not yet passing them in? Even if it was possible how would I account for different ratios of rectangles?
  2. What math can I use to ensure that no matter the device resolution, or shape size that the anti aliasing effects a maximum of 2 pixels (or whatever) from the edge of the shape?

1 Answer 1


Well you can render at higher resolution and sample down thhis is called FSAA and should just work without much change to render code. FSAA has the benefit of not having a conflation problem whereas smoothing does.

  1. No, something has to emit this info.

  2. You take the derivate (the gfx card does this for you) of the surface varying to determine how far the step would take you in your pixel. if its over the edge then you antialias.

  • $\begingroup$ How much higher resolution should I upscale it $\endgroup$
    – J.Doe
    Jul 7, 2016 at 20:22
  • $\begingroup$ Usually 4 is fine but read this first opengl.org/wiki/Multisampling you dont actually need to store those extra pixels $\endgroup$
    – joojaa
    Jul 7, 2016 at 20:24
  • $\begingroup$ I hope that is compatible with opengl es 2.0. It seems almost nothing is. My fear is that my app uses an accumulation buffer so I never clear the buffer that is drawn on, i simply fade it then draw a new frame. Oviously a bigger FBO means slower loading time. Hopefully the extension is supported making that a non issue. $\endgroup$
    – J.Doe
    Jul 7, 2016 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.