Apr
6
2015

Doom Style Billboard Shader

doom_billboard_shader_unity5_1

Testing Doom style billboard shader, where you can look sprite from different angles, still not completely finished but enough for testing..

* Note: I have no idea how the doom billboards work, just looking for similar style

Related forum post: http://forum.unity3d.com/threads/relative-position-for-changing-2d-graphics-in-3d-environment.307086/

WebGL player:
*coming later*

Sources:
* Shader still has few problems (like overlapping other billboards, could be optimized/cleaned up etc), feel free to post improvements here or to github
* Unity 5.1 used
https://github.com/unitycoder/DoomStyleBillboardTest

Updates:
– 08.09.2015: Added animated frames test

Resources:
– Getting viewdir in shader: http://forum.unity3d.com/threads/viewdir-up-vector.173549/
– Should actually check how they do it in Unity Daggerfall : http://www.dfworkshop.net/?cat=17

Image#2: Dynamic batching seems to work

doomspritebatching1(click to view)


23 Comments + Add Comment

  • Just wondering, why not solve this with a script?

    Script properties:
    List of [ AngleRange -> Sprite ]
    Main Camera (camera to compare the “Forward” of with the object’s forward

    The script checks the angle between the camera’s forward and the object’s forward, and decides which sprite to use

    ~120 to -120 = Front (both objects are facing each other)
    cam=> /|\ obj

    ~ -120 to -60 = Side (left)
    cam=> \|/ obj

    -60 -> 60 = Rear
    cam=> obj=>

    That way we can even define much more refined angles (4, directions, 8 directions, 12 directions, etc..)

    • Yes, that would work nicely, just wanted to try it inside shader 🙂 and it should be faster with shader, if you have lots of objects

      • Thanks for the reply 🙂
        A shader is pretty cool indeed

  • Hi,

    we are interested in a fully working shader version of this: http://unitycoder.com/blog/2015/04/06/doom-style-billboard-shader/

    Also animation etc. would be important.
    Are you interested in this aswell and can we support you in any way (with a donation or soemthing like this)?

    Thank you.

    Regards
    André

    • ..You could donate extra ~2hrs per day, thx 🙂

      I do plan to update this more, but just no time yet..

      If anyone has ideas for anim support etc. do post here, even if its just reference links.
      Also, should check daggerfal & all those doom port shaders how they do it.

      One basic way to play “idle” animations per direction could be placing the frames below (in Y direction) and then display those frames at given speed..

  • Hey mGear I’ve been looking into making some doom styled billboard enemies in my game I’ve been looking at many options and from what I can tell using a shader would be best for performance related issues.

    However I’ve never experimented or played with making shaders before. Can this be used to make animated enemies or does it just only work for objects?

    I will of course not wait on your answer alone to figure this out, but just wondering if you have any recommendations for where I should go to learn more about making shaders/shaders for unity/improving on this shader.

    • I would first look how its done in that unity daggerfall package, since they seem to have animated billboard enemies.

      I think theres also some package in asset store for doom style sprites, cant remember the name though..

  • Billboard Shader
    “Includes a powerful geometry shader billboard system for rendering vast forests of retro-styled trees and other billboards. It even supports animated billboards like animals and flickering torches.”
    http://www.dfworkshop.net/daggerfall-tools-for-unity/features/

  • Not sure if you check this anymore but I will try. I’m trying to achieve this same thing as you do with the difference that I just need the billboard in shader, the rest I do trough a custom animation system.

    I wanted to ask if your shader is batched correctly when more than 1 of the same sprites are on screen or if every single new sprite will generate a new drawcall.

    I have beeen trying to solve this problem by ages and I would like to keep batching while having the billboard on a shader isntead of forcing things by script, which can be performance demanding with too mcuh stuff on screen.

    Thanks for your time.

    • Yes, it seems to batch with [x] Dynamic Batching enabled.

      tested just by duplicating the example billboard multiple times:
      http://unitycoder.com/blog/wp-content/uploads/2015/04/doomspritebatching1.jpg

      • Then thiss is perfect. Would you mind If I adapt your shader to work with Unity SpriteRenderer?

        One note, it seems in Deferred the dynamic batching is broken, not sure if is a unity 5 thing or has anything to do with the shader.

        • yeah go ahead. hmm.. yes batching seems to work only in Forward, would be nice to know why.

          tried:
          – Disable transparency from shader
          – Disable shadows and light
          – Set object scale to 1,1,1
          – Decrease Quality settings
          – Disabling most of the code from shader
          – Setting renderqueue : http://www.scrapsgame.com/scraps-performance-draw-call-batching/
          – DX11/DX9

          • Checking Daggerfall tools to see what they did to batch in deferred, honestly there is stuff there I never saw, it will be a trial and error work.

  • added animated frames test to github

  • Fixed several issues and added optimized shaders, see latest version here:
    https://github.com/unitycoder/DoomStyleBillboardTest

  • Hello, I tried the project with the newest Unity, and I got this problem.

    http://s785.photobucket.com/user/razor21xyz/media/braerbeab.png.html

    I am not sure what caused it, any clues how to fix?

    • Tested with 5.4b24, didn’t have the same problem.. maybe you can export unitypackage for testing.

      • I managed to fix this by a simple re-importing, thanks!

        Is there a further plan to improve this system?

        I rotated the front facing of the object, and it didn’t change the sprite’s view in relation to the object’s facing, which I find quite weird.

        And animation is currently very complicated to do, as there is no dynamic way to figure out how many frames do you have for each animation.

        For example, attack have 12 frames, and death have 6 frames.

        I hope this project will get more love and practical implementation method!

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.