2
\$\begingroup\$

I am attempting to render 40,000 sprites: a grid of 200x200 with each grid node having a sprite renderer. All the way zoomed out I get about ~20 frames per second.

What would be the best way to optimize this? Eventually I want to have an even larger grid. The grid has to be changeable — I need to be able to change the ground/floor for that specific grid node.

Screen shot of me frames/grid

\$\endgroup\$
3
  • \$\begingroup\$ Before I comment, have you profiled this? If so, have you demonstrated to yourself that it is in fact a rendering issue throughput and not something else? \$\endgroup\$
    – Water
    May 6, 2017 at 16:12
  • \$\begingroup\$ @Water yes, as you can see here imgur screenshot that rendering takes about 35ms \$\endgroup\$
    – Timo
    May 6, 2017 at 17:02
  • \$\begingroup\$ I've previously shared a method for rendering a tile map on a single quad. It uses a 1 pixel per tile index texture to control which tile graphic is shown in each grid cell (which you can modify using SetPixels methods or by drawing into it as a RenderTexture). By drawing the map all in one pass, the cost varies based only on the amount of screen space covered, no matter how many tiles you draw. Would something like that help in your case? \$\endgroup\$
    – DMGregory
    May 7, 2017 at 4:16

3 Answers 3

1
\$\begingroup\$

You will have to generate and manage your own tile grid mesh(es) by putting all your tile graphics into one large texture (atlas) and updating the UV coordinates in the generated meshes when those tiles have to change.

You'll want to split your map into smaller tilemap meshes to allow Unity to do Frustum Culling on groups of tiles while not having to process frustum culling over 40,000 objects.

For example, creating meshes of 50x50 tile subsections will reduce the number of objects Unity has to check for frustum culling down to 16 (4x4, * 50x50 = 200x200) instead of 40,000 individual objects.

Addendum: Unity team has been working on a TileMap feature for about 2 years now. If and when this becomes available in non-beta it may be a better solution than rolling your own. But as of today it is not available for production use.

\$\endgroup\$
0
\$\begingroup\$

Modern graphics APIs allow you to use a technique called instanced rendering. This is the go-to technique when you want to render a lot of the same thing. You basically tell the GPU to render something x amount of times and use a shader to decide where and what to do with them.

You can access this in Unity too: https://docs.unity3d.com/Manual/GPUInstancing.html

\$\endgroup\$
-1
\$\begingroup\$

Try setting it to a really low resolution and applying a lot of anti-aliasing on a recursive way, so having several layers of anti-aliasing concatenated. I usually do that when I do audio reactive visuals on limited CPU and graphics card power on my MacBook.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I totally not see how this could improve the user's issue. Perhaps you could explain why this magic would help? \$\endgroup\$
    – Vaillancourt
    May 7, 2017 at 0:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .