We’ve done a number of improvements to blending and billboards, to support more use-cases, and to make some cases “just work out-of-the-box”.
Before we start, just download latest version of Castle Game Engine and open a new example examples/viewport_and_scenes/billboards_blending_in_3d. It will illustrate most features mentioned in this post clearly 🙂
Existing 3D sorting algorithms (
sort3DGround) now order by projecting shape point on the camera direction (instead of measuring the distance from shape point to camera position).
The end result of these 2 points is that if you use
TCastleBillboard, it will have perfect sorting even for extremely thin layers, like when loaded from Spine. Out of the box, i.e. default blending sorting and default billboard behavior are good.
This works as long as
TCastleBillboard.AxisOfRotationis zero or equal to camera up. The sorting is 100% reliably correct in this case.
TCastleBillboard.AxisOfRotationis +Y (default), then all you have to do is just to flip
sort3DVerticalBillboardsis a new option that sorts perfectly for billboards rotated around Y.
Blending in manual was extended to mention the new option.
TCastleBillboardtransformation algorithm was also improved. It is now faster, and it is applied without any delay (you will never observe artifacts caused by potential-1-frame-delay between changing camera and transforming billboards to account for it).
TCastleBillboardtransformation also accounts now for billboards instantiated many times. Whether you use TCastleTransformReference or Multiple viewports to display one world, all instances of the billboard will be now correctly oriented toward the camera.
In both new blending methods and billboard algorithms, I’m proud that I actually achieved a bit of code simplifications and optimizations. It’s nice when the better result is also just internally simpler, and the calculations involved are also simpler. E.g. sorting methods no longer transform 8 points of a box (they only transform 1). E.g. billboards get camera vectors in world space without any extra calculation (and these camera vectors correspond to current viewport).