Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Additional Per-Vertex Data for SpriteRenderer?

Discussion in '2D' started by ZenTeapot, Apr 20, 2022.

  1. ZenTeapot

    ZenTeapot

    Joined:
    Oct 19, 2014
    Posts:
    65
    Is it possible to assign additional per-vertex data streams when using SpriteRenderer? I've done the alternative method of using MeshRenderer to fake it but it's a royal pain in the ass.
     
  2. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    648
    ZenTeapot likes this.
  3. ZenTeapot

    ZenTeapot

    Joined:
    Oct 19, 2014
    Posts:
    65
    Thanks! That seems to be exactly what I'm looking for. Will try.
     
  4. ZenTeapot

    ZenTeapot

    Joined:
    Oct 19, 2014
    Posts:
    65
    After some testing I notice that this adds extra data to the sprite instance data. Whe I have multiple sprite renderer on different objects that referene the same sprite, to allow for different extra data, I must cache the sprite inside the object script. It works but it really strains the GPU for some reason, a lot worse than my previous MeshRenderer version. Any way to solve this problem?
     
  5. ZenTeapot

    ZenTeapot

    Joined:
    Oct 19, 2014
    Posts:
    65
    After further investigation I don't believe batching is the main reason, but still the slow down is very obvious. I expect there to be some slow down but this seems too much to be right. Maybe behind the scene cpu to gpu memory stuff is messed up this way?

    Local sprite instance caching enabled, gpu is really slow. cpu is mostly waiting for it.
    Picture1.png

    sprite caching disabled.
    Picture2.png
     
    Last edited: Apr 26, 2022
  6. ZenTeapot

    ZenTeapot

    Joined:
    Oct 19, 2014
    Posts:
    65
    Attaching the relevant code. Though not complete, should be pretty clear what I'm trying to achieve.
    upload_2022-4-26_17-22-8.png
     
  7. ZenTeapot

    ZenTeapot

    Joined:
    Oct 19, 2014
    Posts:
    65
    Bunmp. A critical performance blocker. Please help.
     
  8. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    648
    What exactly is the issue ? Are you doing this for every sprite, each frame ? Are they packed into Atlas ?
    Could you please submit a simplified repro project for this with some info to reproduce the issue ? That would really help us identify any potential issue.