Speed problem

When using rect() in draw with 10 rects or various sizes (between 100 and 1000 pixels wide) i get:

  • 20 fps normally.
  • 60 fps if i set noSmooth() and noStroke().
    First it Is good to know.
    Second: coulnd this be improved? That huge loss of speed is not really mandatory, is it?
    It is not really a big problem for me, because i use always noSmooth() and noStroke() to keep the fps, but it might be annoying for some users?

@Jmv38 smooth() rects use a shader to anti-alias their edges. That means for every pixel of the smooth rect it has do to quite a lot of GPU computation.

It could be improved by optimising the shader (I’ll look into it). Another way would be to draw each smooth() rect as nine quads, using a custom edge texture gradient to control the anti-aliasing. Could potentially be faster but cause graphical artifacts.

Ok, thank you for the answer.
NB: You focus on noSmooth(), but noStroke() is important too. I think drawing 2 rects (a big one then a smaller one inside) would generate the same results, but be faster than the current way stroke works. Not verified though.

@Jmv38 that is correct, stroked rects use a shader as well — even without smoothing. It means evaluating a step() function for every pixel in the shader.

If we used the overlapping rectangle it would be faster, but it wouldn’t play nice with semi-transparent rectangles.

We chose flexibility over speed with the built in primitives. But at some point I will look at ways to optimise them.