SVG graphic and perfomance

Hello community!
In my current project, I need to use a lot of game objects, each of which consists of a sprite renderer with an SVG sprite. At the moment I’m using the “Vector Graphics” unity package.
When there are not many objects on the screen, the FPS is good (~ 60 on android), but when there are a lot of objects on the screen, the fps drops to 20-30 :frowning: (tris/vert about 300k and batches about 60-70)
Is there any way to improve performance? Maybe there are some tricks I can use with SVG to improve performance? The same scene built from PNG images (standard sprites with atlas) has no performance issues, but as far as I know it is not possible to assemble SVG sprites into an atlas.
Also, I can’t reduce the geometric complexity of the shapes, because it’s very important to place objects next to each other, and if I decrease the geometric complexity, the boundaries of the shapes become irrelevant :frowning:
Any advice would be appreciated! I would be grateful for any theoretical data to help me get the best performance with SVG in Unity.

A first step would be to confirm specifically what is causing the performance lost in terms of is it something related to the SVG renderer directly ( doubtful, but maybe there is something dumb in the code that when moving a SVG sprite it updates the vertex list instead of a transform - not examined the code so don’t know), the draw count ( since SVG don’t batch I presume ) or the tri/vert counts of SVG .

Once you know specifically what is responsible you can focus on finding solutions, if any.

For example you might try batching together several SVG sprites into a single mesh, then provide a transform per sprite to the shader and transform specific vertices by the transform. An older method of doing this was to combine several meshes into a single ‘skinned mesh’, assign a bone per sprite and then use the animation class to move them.

You might want to reduce vertex counts by playing with the SVG importer settings. Turn on wireframe and visually inspect the results, whilst you say you need to retain the boundaries, you may see an option to re-model the svg that optimizes the complexity within the the shape.

One other thing to consider, I’m pretty sure from memory that the Vector graphics package does not create optimal triangulation, in so much that it uses a method that is faster but might be prone to generating long thin triangles which can be considerably less efficient when rendered. Might be worth turning on wireframe and visually checking your svg sprites to see if that might be an issue.

Other options to explore might be to implement a LOD type system for the SVG sprites, if you can get away with a less defined shape in some cases, then a lower LOD version could be used.

Unfortunately its difficult to give exact solutions as it likely comes down to the specifics of your project and use of SVG sprites within it, but hopefully this gives you a few starting points.

1 Like

How is performance if they’re raster sprites which are not atlassed?

My first thought would be to convert from SVG → sprite at load time. Just make a RenderTexture for each, render the SVG into that texture, and use the texture instead of the SVG. Then you’re rendering a textured quad instead of a few thousand tris of geometry for the same output.

Even if you’ve too many sprites to pre-render them all at load time (or if load times get too long), I’d play around with having a render texture per in-game object and only re-rendering from SVG to the texture when the object’s sprite changes.

That’s assuming that Unity’s SVG renderer isn’t advanced enough to already be doing this behind the scenes. But from memory it just generates geometry from the SVG.

1 Like

@Noisecrime @angrypenguin Thank you both for your answers, now I have new ideas for work! I’ll update this thread in case something becomes a suitable solution for my purposes.
@angrypenguin Could you clarify pls - RenderTexture is only a feature of Unity Pro?

@angrypenguin I think I found the answer - it’s included in the “personal” version too, so this question isn’t relevant)

Yeah, the Personal / Pro versions have had engine feature parity for years.