Billboard shader

The game I’m working on has 2D sprite characters on a 3D plane. Similar in appearance to ‘Don’t Starve’. The characters appearance is customizable, made up of several sprites layered over one another inside a parent game object. The billboarding up to this point has been done via a script on the parent game object.

I would like to switch to using a shader for the billboarding, so I can implement dynamic lighting for the characters. However I’m having an issue with some of the sprite positions relative to the parent game object. They no longer seem to move with the parent, and change based on perspective.

I’m wondering if there’s a shader based solution to this, or whether I should be looking into sprite merging or something else.

Any help would be greatly appreciated.

P.S. Shaders are pretty new to me and their scripting is still a bit beyond my understanding!

6259759--690496--1.JPG
6259759--690499--2.JPG
6259759--690502--character-gameobject.JPG

This is a bit late, but the answer is … use a script.

You can absolutely billboard objects using a shader, but Unity’s sprites don’t handle that well. They have no knowledge of the original object’s pivot, and if they’re at all batched (which if there are ever two sprites using the same sprite / sprite atlas & material they probably are) then they don’t even know where their pivot is since they’ll be part of a combined mesh.

You could do your own sprite meshes that don’t use any of Unity’s built in sprite rendering systems, construct the meshes at runtime from script, and store the pivot in the mesh’s vertex data to extract later. Or you can use a custom material where you set the pivot position on the material from script.

Or you can use a script to rotate the sprites, and that’ll probably be faster / cheaper.