Search Unity

Question How to prevent sprite batching OR display sprites without using sprite renderer?

Discussion in '2D' started by BasicallyGames, Aug 19, 2020.

  1. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    91
    My game uses a custom shader graph that lights objects differently depending on their location in 3D space (My game is first person and 3D, but since I'm working with sprites I figured this was the best section to ask this in). For 3D objects this works fine, however with sprites I'm encountering some issues that seem to be due to Unity's automatic sprite batching.

    Basically, if there's only one instance of a sprite nearby, the lighting works perfectly. However, if two or more of the same sprite are near each other, the object position information is lost due to the batching and the sprites become dark (Or rather, they change to whatever the lighting would be at (0,0,0), which is usually dark) since the shader does not know where the location is anymore.

    So is there *really* no way to stop Unity from automatically batching sprite renderers together? It seems like if I could stop that from happening it would basically make my sprites work perfectly. I've considered the option of just using quads and displaying my sprites on those, but then I'd need to convert all my sprites to materials, I wouldn't be able to use sprite sheets, I wouldn't be able to size them based on PPU, etc. It would just cause a lot of annoying problems.

    If it's literally impossible to disable sprite batching, is there any way I could work around it in my shader, or another method of displaying sprites that doesn't use batching? I'm certain there's a solution to the problem that doesn't require me to turn all my sprites into quads, but I just need some help figuring out what.

    Thanks in advance for any help!
     
  2. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    91
    Bump. I'm now also trying a billboard shader (I've been using a script for all my billboarded sprites up to this point, which obviously isn't efficient) and now I'm also experiencing issues with that. Whenever two or more sprites are batched together, they start rending somewhere completely incorrect.
     
    Last edited: Aug 20, 2020
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,438
    BasicallyGames likes this.
  4. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    91
    Thanks! I figured out I could generate my shader graph's code by right clicking on the master node, and was able to add this to the shader. It seems to be working as intended now!