Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Performance comparison between SpriteRenderer and MeshRenderer with lighting

Discussion in '2D' started by theforgot3n1, Nov 3, 2021.

  1. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    188
    I wanted to know for certain what the performance differences between SpriteRenderers and MeshRenderers quads are for different configurations (normal maps included). I compared a scene with 4096 objects. The FPS of both scenarios were checked. The texture of the sprite was 64x64 and about 50% transparent.

    I use the Uber shader for sprites found at this git link. I modified it slightly so that it could handle secondary textures on sprites.

    Some configurations:
    • PC, Windows, Desktop, Unity 2020.3.21f1, Built-in Renderer
    • Sprites had Tight mesh type (no actual difference tho)
    • Both scenarios had normal maps rendered correctly
    With dynamic batching (one shared material):

    SpriteRenderers: 90 FPS
    MeshRenderers: 115 FPS

    Without dynamic batching (instanced materials):

    SpriteRenderers: 27 FPS
    MeshRenderers: 35 FPS

    I also tested the standard shaders (instanced materials)

    Sprites-Default for SpriteRenderer and Standard for MeshRenderer shader.

    SpriteRenderers: 45 FPS
    MeshRenderers: 55 FPS

    Standard shader for both Renderers.

    SpriteRenderers: 32 FPS
    MeshRenderers: 45 FPS

    It looks like MeshRenderers do better in this simple performance comparison. I don't really know why. It would make more sense for SpriteRenderers to do better, but alas. SpriteRenderers should be used when there is specific functionality that you can't get with MeshRenderers (fewer materials, sprite atlas, etc.). This link helps describe some.

    I have not seen anyone perform a specific performance difference check between SpriteRenderers and MeshRenderer quads. Now it's done. Hope this helps.
     
    Last edited: Nov 3, 2021
    markkmlam, Kokowolo and Lo-renzo like this.
  2. kennyy_

    kennyy_

    Unity Technologies

    Joined:
    Apr 7, 2021
    Posts:
    94
    Hi, thanks for taking the time to do the performance comparison. For my clarification, are you using built-in or URP to test the performance? If you are able to share your project, I'd be happy to do some performance profiling.
     
    theforgot3n1 likes this.
  3. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    188
    Hi kenny :) I am using the built-in renderer. I attached the Unity project. Profiling in this way is not something I do every day so if you can get more accurate results I'd be happy to see them.
     

    Attached Files:

  4. Giantbean

    Giantbean

    Joined:
    Dec 13, 2012
    Posts:
    141
    I find this interesting and wonder if the scene was ever looked at for further profiling. @kennyy_ I think these tests are something Unity should clarify and doing so would add important information to the community.

    It seems some points may have been missed in the tests or require clarification.

    1. Are you comparing single sprites VS Single materials on single planes or sprite sheets? For example, a 1024x1024 sprite sheet with a grid of 5x5 gives you 25 sprites but the same image left as a JPG and using a material that includes transparency would need to have 25 material copies with different offsets, right?

    2. Could the above be done with one .png material such as a gridded atlas and only take one material while making the planes or quads in Unity or would a grid of UV mapped planes need to be brought in from a modeling software for that to work? If done that way would the quads be more performant and have less draw calls?

    3. Could Tile maps be used to make a Sudo sprite sheet and how would its performance compare (I have not used tile maps so this is a shot in the dark)?

    4. Is there a difference in visual fidelity for any of these methods or physical scalability?

    Bonus Question: Has the Uber shader been updated for URP and even if it hasn't can @theforgot3n1 share the modification for secondary textures.


    Edit: In a quick test using 2022.3.5 with standard shader in fade or cutout (no Uber shader) the 9 sprites from a sprite sheet outperformed two images on planes or quads with or without prefabs. I'm not sure how the OP got higher FPS from meshes as each mesh takes another material and adds batches but maybe that's part of what the Uber shader helps with? I updated to URP and all frame rates dropped. I tried a few shaders and they generally looked worse and didn't perform as well as the standard shader or the sprite images on a canvas.
     
    Last edited: Jul 24, 2023
  5. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    188
    I'll try my best to answer, this was a while ago.

    1. No sprite sheets were used in the example in any way. Yes, you are correct that using sprite sheets with SpriteRenderer helps a lot vs using MeshRenderers with just 1 sprite per material. This is an advantage with spriterenderer.

    2. Are you asking if a MeshRenderer can use a sprite sheet? I don't know the answer to that, unfortunately.

    3. Tilemaps operate differently and have their own Renderer, the TilemapRenderer. Pretty sure using it as a sprite sheet itself would be very tricky.

    4. Probably no difference in visuals at least.

    5. No idea. I have never used URP other than played around.

    In response to your experimentation, how does the standard shader do when not using sprite sheets? That is, only testing 1 sprite? Do you get the same results as me?