Improvements around viewport projection, MainScene deprecated

Simple castle demo model
Simple castle demo model in Blender

Recently I was making various improvements possible thanks to new viewport and camera handling. If you haven’t already, see our video about Viewports, cameras and navigation!

Improvements:

  1. Few fixes to automatic projection calculation. Long story short: you can probably leave TCastleCamera.ProjectionNear and TCastleCamera.ProjectionFar at zero in your projects, 2D and 3D. They should be always automatically calculated to nice values.

    1. Default perspective TCastleCamera.ProjectionNear doesn’t depend on world box (to not increase when some object flies/falls into infinity).

    2. Default perspective TCastleCamera.ProjectionFar is now ZFarInfinity, regardless of ShadowVolumesPossible (which were usually true). So there is no far clipping plane — easy to use. We were testing the perspective matrix with “z far at infinity” already a lot (as it was necessary for shadow volumes anyway), and there’s no perceived loss of Z-buffer precision because of it.

    3. Default orthographic TCastleCamera.ProjectionNear and TCastleCamera.ProjectionFar are much smarter now, looking at world bounding box.

    4. Optimized: Do not calculate useless ProjectionFarFinite, do not calculate ItemsBoundingBox when not necessary (never needed for perspective, not needed for orthographic when explicit).

  2. We have deprecated TCastleViewport.AutoCamera, TCastleRootTransform.MainScene, TCastleRootTransform.UseHeadlight. I consider it a significant gain for the engine — in particular TCastleRootTransform.MainScene was a thorn in my side for a long time, it was unnatural we needed to designate some scene as “main” to activate some engine features.

    Now you can achieve (almost) all their functionality through other means. See their docs for pointers. And the engine usage is simpler when you don’t need to be concerned about setting MainScene etc.

  3. Upgraded simple_3d_demo with new Blender models.

    New castle Blender model is also part of demo-models, see castle subdirectory.

  4. Upgraded fog_and_distance_culling to use glTF model and of course new TCastleFog component.

  5. Fixed crash in simple_3d_demo when accessing previews of data files with GeneratedCubeMap.

1 Like