Search Unity

BIllboard shader better performance than using Cam lookAt or Cam forward?

Discussion in 'General Graphics' started by Zebbi, Sep 9, 2019.

  1. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    I'm trying to understand if it would be better to use a shader for billboard sprites (or if it's even possible) to have the sprite always face the camera. I've found a few examples:

    https://www.dfworkshop.net/projects/daggerfall-tools-for-unity/features/
    https://www.bitshiftprogrammer.com/2018/10/advanced-billboard-shader.html
    https://gist.github.com/josephbk117/2227128370097500d07c4dd894931429
    http://www.shaderslab.com/demo-33---bilboard-bush.html

    But I've been settling with either:

    Code (CSharp):
    1. transform.forward = -Camera.main.transform.forward;
    or
    Code (CSharp):
    1. transform.LookAt(Camera.main.transform.position, Vector3.up);
    Would it make more sense to use a shader solution for this?
     
  2. Zebbi

    Zebbi

    Joined:
    Jan 17, 2017
    Posts:
    521
    Or is this not really done with shaders?
     
  3. Romano

    Romano

    Joined:
    Nov 27, 2013
    Posts:
    76
    I'd also love to know the answer to this
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    You can’t really use a billboard shader on a sprite, because to use a billboard shader you need to know what local mesh orientation is forward, and where the center of the sprite is. With Unity’s sprite system you may not know either. Unity’s sprite system will batch sprites of the same material and sprite atlas together into a single mesh. So basically, you have to rotate the sprites from script.

    Now if you instead use quad meshes and manual instancing, you can use a billboard shader. In that case rotating on the GPU using a billboard shader is generally going to be a lot faster than doing it on the CPU. I say generally because it depends on if you’re CPU or GPU limited.
     
    yeonghokim and Romano like this.