- Home /
Tree Billboards
I am using gameobjects as trees for various reasons. Is there a way I can create billboards like in the terrain tree system? Do I have to write a shader, or can I write a script instead? They don't have to fade smoothly or anything I just need the billboards.
Answer by _joe_ · Mar 28, 2015 at 05:36 PM
Simply use a quad (not a plane).
Create a new Material and drop on it your Texture. Make sure that you use .png textures that have transparency. Pick the "Particles/Alpha Blended" Shader.
Adding the Material on the Quad will show the effect needed.
Now to make the quad a billboard, write a script and drop it on the Quad. This script should have a transform.LookAt() (check the documentation) in the Update.
I was wondering how to make the Billboard texture at run-time is there an easy way to do this? And won't it give bad performance to run 5000 transform.LookAt's every second?
There is nothing such as "Billboard Texture". A billboard is a physical object in the scene, that has a cutout (transparency) texture applied on it.
Even using the Unity UI system and changing the Canvas mode to World Space will create Quads for every image added, my approach was the same.
LookAt is simply a Quaternion matrix operation that you will have to do. LookAt is there to simplify the task That's all.
As for performance, if you have 5000 billboards, the best approach is to filter the display based on distance (Near and Far Field of the Camera). Or simply check for the distance to the billboard, if it's farther than a certain number, simply disable the calculation.
Billboards follow the world tick time, so update is the perfect place to put them so you'll be ok running the script (even for multiple items).
If you want there is an other less "accurate" approach, you can, ins$$anonymous$$d of using Update, to run the LookAt inside a coroutine with a custom WaitForSeconds.
But of course this will be slower (yet more controlled). This control can allow you (just for the sake of performance) to increase the loop time if the object is far (faster calculation), or decrease it (faster) if the object is close to the camera. But of course Update is still the go to technique.
Hope that helps
With Billboard texture I meant the texture that the billboard is going to use. But I found a solution on Google for this. Thanks anyways for giving me a good starting point on the quads.