Performance RegularPolygon vs Rectangle (Android)

Avatar
  • updated
  • Answered

I did a qucik test with a RegularPolygon vs Rectangle. The Polygon and Rectangle quads fill the same space (therefore the visible regular polygon is smaller) to make a fair comparison.

RegularPolygon left, Rectangle right.

Image 268

The performance difference is quite big for my android low end test device (Xiaomi Mi A1):

RegularPolygon on screen:

Image 269


Rectangle on screen:

Image 270

Is this expected? I'm using a lot of regular polygons due to their support for gradients.

As for settings:

Tested with Vulkan and OpenGLES3

Linear Color Space

No PP, No AntiAliasing

Shapes: Half4 output, Medium Local AA, medium Quad Interpolation Quality

Reporting a bug? please specify Unity version:
2020.2.5f1
Reporting a bug? please specify Shapes version:
3.0.0
Reporting a bug? please specify Render Pipeline:
URP
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Answered

this is expected, regular polygons use more complex math in the fragment shader to support an arbitrary number of sides, and it gets more expensive due to the rounded corners too, while the rectangle can take lots shortcuts since it knows it will ever only have 4 sides

Avatar
Johannes Deml

Just as a quick followup, if somebody finds this thread:

I had a day of performance optimizations for my project, and got some big improvements. Even though I can't say exactly what fixed the performance bottleneck, the test with the fullscreen Regular Polygon and fullscreen Rectangle run with a buttersmooth 60 FPS on my old OnePlus One.

So even though there is quite some overhead for Regular Polygons, also older smartphones are quite capable of handling them. Note, that you might hit problems with mobile fillrate (see https://shapes.userecho.com/en/communities/1/topics/208-low-fps-and-high-gpu-load-with-bunch-of-discs). And using Rectangles instead of Regular Polygons whenever possible is a good idea, since they need less performance and have no invisible area on the sides (see first screenshot).

TL;DR: Shapes can run rather well on mobile devices :)

Avatar
Johannes Deml
Quote from Freya Holmér

Out of curiosity - would you prefer the arbitrary linear/radial gradients that regular polygons support, or would you prefer the horizontal/vertical ones that the quad has?

I really like the arbitrary gradients from the regular polygons, since they are more flexible (I love that you also added an option to make them anchored to the world position).

My main usage for Shapes is some colored blocks

    Avatar
    Freya Holmér creator

    Out of curiosity - would you prefer the arbitrary linear/radial gradients that regular polygons support, or would you prefer the horizontal/vertical ones that the quad has?

    Avatar
    Johannes Deml

    Thanks for the reply,

    okay got it, that's what I thought, but I was still surprised by the huge difference. I will switch the elements that are Rects to Rectangle components, once it supports Gradients.

    Thank you for your hard work on the asset!

    Avatar
    Freya Holmér creator
    • Answer
    • Answered

    this is expected, regular polygons use more complex math in the fragment shader to support an arbitrary number of sides, and it gets more expensive due to the rounded corners too, while the rectangle can take lots shortcuts since it knows it will ever only have 4 sides