I was reading the Unity manual on trees and one of the claims made is as follows:
Unity uses optimisations (eg, billboarding for distant trees) to maintain good rendering performance...
I was planning on doing my own billboarding for a game I'm building anyway, so knowing that I'm going to gain a performance advantage is good to know. However, when I tried looking a little deeper at how billboarding is done in Unity, I found these sources:
http://wiki.unity3d.com/index.php?title=CameraFacingBillboard http://answers.unity3d.com/questions/20697/how-to-create-billboarding-planes.html http://answers.unity3d.com/questions/52656/how-i-can-create-an-sprite-that-always-look-at-the.html
Which all show that the way to do billboarding is to do a transform on the object each frame to make it face the camera. (I can't find much about billboarding in the official Unity documentation).
How does billboarding affect performance? Why would there be a performance boost if you have to transform "dense forests with thousands of trees" before each frame? Does unity have a native billboarding shader built in? If not, wouldn't billboarded sprites require, at the very least, the same amount of rendering power as other objects being drawn in a 3D scene?
Answer
In the more general sense, "Billboarding" means that an object in a 3d-scene (usually but not always a 2d-sprite) is always rotated to face the camera. A common use-case are spatial UI elements in a 3d scene. Take, for example, a real-time strategy game with a 3d engine where every unit has a health-bar below it. That health-bar would use billboarding to always be fully readable for the player no matter how they rotate the camera.
But in the specific context of performance optimization, Billboarding means that complex 3d models are rendered to 2d sprites and those sprites are then used in a billboarding manner. This means the object only needs to be rendered in full detail once and can then be inserted multiple times into the 3d scene as a simple textured square. This greatly improves rendering speed of a large number of identical, complex 3d objects (a forest of trees is the most obvious example).
However, it has a price: This shortcut becomes very visible on short distances where it becomes obvious that shadows and clipping are way off. That's why it is usually only used for very far-away objects while closer instances of the same object are properly rendered in 3d.
Also, when you only use one sprite for each object, it might look a bit strange when the object is seen from a different angle than the billboard-screenshot was taken, for example when you are flying far above the forest and you still see all the trees from the side. That's why billboarding systems often take screenshots from several directions of a 3d model and draw the one closest to the current view-angle when rendering.
Unity does have a billboarding system built in, but unfortunately only allows you to use it for the Tree component in conjunction with the Terrain component. When you don't use the Unity terrain and want to billboard something you can not generate through the SpeedTree system, then you will have to program it on your own.
No comments:
Post a Comment