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 🙂
New features:
-
Existing 3D sorting algorithms (
sort3D
,sort3DOrigin
,sort3DGround
) now order by projecting shape point on the camera direction (instead of measuring the distance from shape point to camera position). -
By default
TCastleBillboard
adjusts to camera direction, not vector from camera to billboard origin. (One can get old behavior by settingTCastleBillboard.MatchCameraDirection
=false
.)The end result of these 2 points is that if you use
TCastleScene
withTCastleBillboard
, 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.AxisOfRotation
is zero or equal to camera up. The sorting is 100% reliably correct in this case. -
Moreover, if
TCastleBillboard.AxisOfRotation
is +Y (default), then all you have to do is just to flipTCastleViewport.BlendingSort
tosort3DVerticalBillboards
.sort3DVerticalBillboards
is a new option that sorts perfectly for billboards rotated around Y.Blending in manual was extended to mention the new option.
-
The
TCastleBillboard
transformation 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).The
TCastleBillboard
transformation 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).
thread hijack, Michalis, did you see TDisk2DNode again - #2 by Arioch ?
I did now, and answered there I’m still catching up with my backlog after vacation at the beginning on July.