Search Unity

2D Sprite Shape SRP Batching Support

Discussion in '2D' started by Marble, Sep 14, 2020.

  1. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    The sprite shape render node doesn't currently support SRP batching even if the assigned shader is compatible. The result is that each edge and fill is drawn separately, drowning performance with draw calls on scenes with many sprite shapes.

    Is compatibility planned? Is there a workaround in the near term, such as a way to bake static sprite shapes into a mesh for use with a renderer that is supported?
     
  2. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    Thanks for posting. We will consider adding support for this in a future version.
     
  3. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I second this, there should be some way to reduce the drawcalls on Sprite Shape. I also wonder if Sprite Shape is regenerating the mesh every frame? Or just when its shape has been changed? I am creating the Sprite Shapes in runtime ( only once during loading time ) and while it works, I have suspicion that performance hit would be heavy. I also don't know what this Bake() supposed to do. Is it meant only be used in Editor mode and cache geometry and save it in the scene?
     
  4. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I third this. We're ready to really utilize Sprite Shape in our game but we are developing for Switch and cannot afford the high amount of Draw Calls that using it will cost us!
     
  5. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    If we don't need to modify the shape per every frame update, we should be able to batch the similar sprite shapes that are using the same setup regardless if they are created during runtime or editor time. Ofcourse I can understand the sorting can interfere with the drawcalls but other than that they should be treated as the other sprites that are using the same material and the same atlas.

    Having said that, (I could be wrong but ) I am not even sure if SRP batching even works with 2DRenderer at the moment. I think ... it isn't at all. So maybe when 2DRenderer gets SRP batching it could happen?
     
  6. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    To add a question to the above, I want to know what happens to sprite shape rendering process in runtime. Does it regenerate its drawing mesh every time per frame? Or only when it is needed because their property changed such as curve points. And does it repect other usual culling such as frustrum culling?
     
  7. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    It doesn't work? That may explain why Frame Debugger is giving me nonsense...
     
  8. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    As far as I know SRP batching does not work with current 2DRenderer. Which is sad, but I am so eager to find out if it ever will, and if so it can increase performance. Right now, it only seems to do the "dynamic" batching which I think it is similar to old cpu batching used to work for the builtin pipeline.
     
  9. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    1. Drawing Mesh is not generated every Frame. SpriteShape Geometry is only generated when there is a change in Inputs (Spline, SpriteShape Parameters etc..) You can also save the generated geometry to be used in Runtime instead of being generated.
    2. Yes, SpriteShape Renderer as all other renderers are culled if not visible.
     
  10. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    1. SRP Batching is not compatible with 2D Renderer.
    2. Please use Atlas or SpriteSheets for sprites used in SpriteShape Profile, so that each SpriteShape is rendered in 2 draw calls regardless of the complexity of the SpriteShape or Vertex count. While we explore ideas to improve it further, please do note that Dynamic Batching has its limitations like 300 vertices etc.. (https://docs.unity3d.com/Manual/DrawCallBatching.html)
     
  11. alleballe90

    alleballe90

    Joined:
    Jan 9, 2017
    Posts:
    7
    any updates to the sprite shape batching issues?
     
    galford and Schazzwozzer like this.
  12. aoisky0216

    aoisky0216

    Joined:
    Oct 13, 2016
    Posts:
    1
    any updates to the SRP Batching with 2D Renderer?
     
  13. samanabo

    samanabo

    Joined:
    Mar 10, 2015
    Posts:
    51
    I would also like to know if the SRP Batcher is compatible with the 2D Renderer.
     
  14. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    In 2023.1 alpha the 2D Renderer was made compatible with SRP Batching.
    Whether this applies specifically to Sprite Shape I haven't yet tested, but it does work for Sprite Renderers at least.
     
  15. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    Yes, In Unity 2023.1.0a18 we have added SRP Batching support for SpriteRenderer, SpriteShapeRenderer and TilemapRenderer. Thanks.
     
    samanabo and aoisky0216 like this.
  16. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    361
    Will this be backported to Unity 2022.2 or 2022.3?
     
  17. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,474
    Unity Features are never backported, only bug fixes.