KTX – mipmaps, ASTC, Docker – GitHub CLI, Compressonator, macOS fixes, node renames API, TCastlePlane.Size

Posted on

Invincible - Mark Grayson (3D model rendered using Castle Game Engine)

Here goes a list of recent Castle Game Engine improvements that I need to get off my chest πŸ™‚ Overall I’m very happy with the engine state lately — we’ve done good features, we have big things coming (like new physics), and have good base and can polish the experience in many places. This resulted in recent improvements a bit “all over the place” as I test and polish 1st-user experience with e.g. our examples.

If you’re looking for an introduction to the engine, watch engine tutorial on our YouTube channel and explore our examples.

Please support the engine development on Patreon! We want to do everything from our roadmap and more!

Engine improvements done lately:

  1. We now support reading mipmaps from KTX (Khronos Texture) files.

  2. Automatic texture generation can be instructed to generate mipmaps for textures. Mipmaps allow trilinear filtering that looks good when the texture may be seen from various distances (typically useful for textures on 3D models, but there are cases when it makes sense for 2D too).

  3. ASTC compression is done to KTX format and using AMD Compressonator.

    This is our general direction for the future: We like KTX format (open standard from Khronos), we like open-source Compressonator with lots of output options. We will push our automatic texture generation to utilize these 2 (Compressonator to KTX) consistently for everything where possible. Other formats (like DDS) or tools (like NVidia texture tools ver2, with a proprietary successor in ver3) will get lower priority.

  4. Our Docker image now contains AMD Compressonator (to generate textures) and GitHub CLI (to interact with GitHub from continuous integration jobs).

  5. We’ve done a number of macOS fixes. They all can be tested using macOS build available prominently on our main page. The macOS build is done automatically by Jenkins and contains the latest CGE. Fixes:

    • Fixed crashes when clicking on lists in editor,

    • Fixed error message about -psn_... at 1st run,

    • Added ability to set CGE location (useful if you run CGE editor from zip downloaded from the Internet, which will be the most common case here). This may also be useful on non-macOS platforms.

    • By default we package app bundle to zip. You can change it though.

  6. I’ve done some thinking and made a documented decision to not try to rename nodes to be unique when loading (glTF, X3D, others).

  7. Following the above decision, I extended TCastleSceneCore.Node and TX3DNode.FindNode methods. Simpler and allow to search by class criteria too. Deprecated some old alternatives.

  8. Last but not least, TCastlePlane.Size gets a trivial but compatibility-breaking fix: it is now treated as total size in both dimensions. This means that size = (10, 10) results in rectangle around (0,0,0) that has size 10, for example from X = -5 to X = 5, and from Z = -5 to Z = 5. This is consistent with TCastleBox.Size and more natural.

    Previous interpretation resulted in larger rectangles. Size = (10, 10) resulted in rectangle around (0,0,0) that has size 20, like from X = -10 to X = 10.

Screen for this post shows Invincible and Mark Grayson 3D models from SketchFab created by ASideOfChidori. As usual when I don’t have a perfect screen to illustrate the current news post, I go ahead and pick something cool that can be rendered by Castle Game Engine πŸ™‚ I did watch the Invincible lately and enjoyed it a lot. You can download the glTF file from SketchFab for free and play with it yourself, just drop it on a 3D viewport.

Comments on the forum ➀

Drag and drop in the editor improvements

Posted on

Drag and drop fun in CGE editor

A few improvements to the drag-and-drop experience in our editor:

  1. You can drag-and-drop from “Files” to “Hierarchy” panel. This will add a child to the currently selected item in the tree view.

  2. You can drag-and-drop images from “Files” to the central design area even when you’re not over a viewport. From such image, we will create TCastleImageControl. You can also drag-and-drop with Shift pressed to force creating a TCastleImageControl (instead of the default TCastleImageTransform) even when dragging over a viewport.

  3. You can drag-and-drop also .castle-user-interface files (will create a TCastleDesign that references them) or .castle-transform files (will create TCastleTransformDesign that references them). If you want to test it out, see e.g. examples/advanced_editor/advanced_loading_designs project.

  4. I also reported drag-and-drop bug with cursor on Lazarus GTK2 widgetset that affects us.

In effect (summing up previous and new features):

You can drag-and-drop various files from “Files” to “Hierarchy” or central design area.

Enjoy, happy dragging and dropping πŸ™‚

Comments on the forum ➀

Bump mapping – updated documentation, example, defaults, everything is simpler now :)

Posted on

Steep parallax bump mapping in Castle Game Engine editor

We’ve made some small updates to how bump mapping (normal maps) work and wrote a nice simple documentation how to use bump mapping in our engine.

  1. Advised reading: bump mapping (normal maps) in Castle Game Engine.

  2. The default bump mapping is now bmBasic, this is much more natural than previous bmSteepParallaxShadowing.

  3. Using the parallax bump mapping is also easier now. Once you place the height map in the alpha channel of the normal map, just set TCastleRenderOptions.BumpMapping to something like bmSteepParallaxShadowing and optionally adjust TCastleRenderOptions.BumpMappingParallaxHeight. See the docs.

  4. Our old bump mapping example was completely reworked, to set up everything in the editor and is now much more straightforward. See examples/viewport_and_scenes/bump_mapping.

Comments on the forum ➀

Improvements around viewport projection, MainScene deprecated

Posted on

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.

Comments on the forum ➀

Fog component to easily design fog using editor or code

Posted on

Adding fog component
Making fog component active on viewport
Adjust fog parameters
Fog and background colors matching

Fog can be now added and configured using TCastleFog component. The component is also available in CGE editor, so you add and configure your fog without even writing any code.

The usage is simple:

  1. You add a fog component anywhere to the design using “Add Non-Visual Component -> Fog (TCastleFog)” in editor.

  2. You set it as active for given viewport by adjusting the TCastleViewport.Fog property.

  3. Adjust the fog parameters, like TCastleFog.Color and TCastleFog.VisibilityRange, as you wish.

  4. Optionally, you can adjust the background color to match the fog color. The fog looks most natural in this case. You can just adjust TCastleViewport.BackgroundColor and leave TCastleViewport.Background empty (nil) for a simple background color. See more about backgrounds.

I reiterated this in a simple manual chapter about fog.

The fog behavior in combination with Linear color space (gamma correction) also changed. Fog is now applied in final (sRGB) color space, this allows to match fog color perfectly to background color or UI easily.

Comments on the forum ➀

Video: Viewports, cameras and navigation in Castle Game Engine

Posted on

I’m happy to present a new video about Castle Game Engine that shows how to design 3D and 2D game world from scratch, by creating a viewport (with cameras, lights, some primitives, some navigation). We start from the “empty” template and explore what we can do in a viewport. The video goes into details about camera and navigation features, with a common theme “how to see what you want to see”.

We cover:

  • Building upon the “empty” template a simple 3D world with cameras, lights, primitives

  • Building upon the “empty” template a simple 2D world

  • Navigation in the editor using “Fly”, “Examine” and “2D” modes

  • Various helpful commands for navigate in the viewport, like Focus Selected (F), View All (Home), Top/Bottom/Front/Back/Right/Left (1/3/7 Ctrl+1/3/7) and more

  • Adding a navigation component to allow user to move around in the 3D world, customizing the move speed

  • Adjusting the camera translation and rotation in various ways

  • Using multiple cameras

  • Adding some children to the camera (like a weapon in FPS games or a headlight)

  • Making a camera be a child of something else (e.g. mount it at some vehicle or attach to some animated bone)

  • ProjectionFar automatic and manual adjustment

  • Finally, more friendly and obvious key shortcuts for various editing operations in editor (Ctrl+C, Ctrl+V, Ctrl+X, Delete, Ctrl+Z… they all do what you expect)

I hope you enjoy the video. Go ahead and download the engine for free and please support us on Patreon.

The related documentation is:

The accompanying news post describing the new camera and navigation features is here.

Be sure to watch also our recent “Castle Game Engine Intro Tutorial – July 2022”. It’s a nice companion to this video, that shows more the “3D FPS game” and “2D game” contents, how to add more complicated stuff (like sprite sheets and glTF models) to your design, and how to do basic code operations (play a sound, handle button click, shoot a missile).

Comments on the forum ➀

Castle Game Engine Intro Tutorial – July 2022

Posted on

Enjoy a new tutorial about creating games with Castle Game Engine, covering all CGE essentials and demonstrating them on the latest engine version!

We cover:

  • Installation

  • Creating a new project from “3D FPS game” and “2D game” templates

  • Exploring the viewport, moving around, adding scenes, transforming scenes, lights, cameras (in 3D and 2D)

  • Building and running

  • Creating a sprite sheet (2D)

  • Manipulating light (3D)

  • Coding: Handling a button click

  • Coding: Playing a sound

  • Adding a new 3D object designed in Blender and exported to glTF

  • Coding: Shooting a missile – spawning a scene, with translation and moving direction synchronized with the player, coding a TCastleBehavior descendant

It demonstrates the latest version of Castle Game Engine that you can download, for free, right now!

Like it, subscribe, and please support us on Patreon to keep the engine development going.

Comments on the forum ➀

Huge update to cameras, navigation, viewports in 2D and 3D

Posted on

3D game template
2D game template
Headlight as camera child
3D viewport
2D viewport
Camera as child of animated bone
Inspector showing non-default props with different color

We’re proud to present a big upgrade to how cameras, navigation, and consequently all viewports work in Castle Game Engine. This is a result of over 3 months of work and we encourage everyone now to upgrade to the latest Castle Game Engine and try it out!

A video describing it all is also coming in the following weeks.

The documentation has been updated to reflect all the new features, in particular 3D viewport tutorial has been reworked, also 2D viewport (soon-to-be) tutorial, camera docs.

New features: Table of contents (this is a really long news post):

  1. Upgrades to design-time (in editor) camera and navigation
  2. Camera (TCastleCamera) is now a TCastleTransform descendant
  3. Navigation at run-time (like TCastleExamineNavigation, TCastleWalkNavigation) is easier to use
  4. Viewport editing improvements
  5. And more improvements that just happened along the way:)
  6. Upgrading

If you like this work, please support us on Patreon!

Upgrades to design-time (in editor) camera and navigation

  1. You can see camera “gizmos” in the editor, visualizing field of view (in both perspective and orthographic modes).

  2. Switch navigation method using the new Viewport menu between Fly, Examine and 2D. Key shortcut Ctrl+2 is useful to toggle between most often used Fly and 2D.

  3. Hold right mouse button to use mouse look (in Fly) or move (in 2D) or rotate (in Examine). Right mouse button in general means “activate design-time navigation”.

  4. In Fly mode: use also mouse wheel to change speed, AWSD / QE to move. (TODO: Soon mouse wheel will also do zoom in/out when right mouse button is not pressed. It will change speed only when right mouse button is pressed.)

  5. We have more goodies and key shortcuts for navigation in the Viewport menu. Key shortcuts are deliberately inspired with Blender, Godot and Unity functionality:

    • View all (Home)

    • Focus selected transform (F)

    • 6 major views (top, bottom, left, right, front, back) available by keys 1, 3, 7, Ctrl+1, Ctrl+3, Ctrl+7. You can use numpad or regular alphanumeric keys to access them.

    • Toggle perspective/orthographic using 5. (TODO: We want to synchronize the views better.)

    • Synchronize current view to the selected camera using 0.

    • Synchronize the selected camera to view using Ctrl+0.

  6. This all makes sense in both 3D and 2D. For 3D, you will usually use Fly navigation with perspective camera. For 2D, you will usually use 2D navigation with orthographic camera and Front view (shortcut 1).

  7. We show a preview of view from the selected camera in editor. You can pin it to keep observing from the camera, regardless of the currently selected item.

  8. Hold Shift when changing the UI or transform (to move, resize, rotate, scale) to avoid changing the selection. Previously this was bound to right mouse button, but now we want to leave right mouse button to only activate design-time navigation.

  9. Design-time camera and navigation settings are saved to the design file.

  10. The design-time camera and navigation are now independent from run-time (in your games) camera and navigation, which allowed us to make all these improvements.

  11. TODO: We have a few improvements still planned around this. In particular, we want to combine current UI selection/move with transform select/move/rotate/scale. It is not intuitive that right now you have to use different modes for UI and transforms.

Camera (TCastleCamera) is now a TCastleTransform descendant.

This has a lot of implications making cameras more powerful:

  1. Camera can have children, like any other TCastleTransform. For example:

  2. Camera can be a child of some other transformation. For example:

    • You can attach camera to a car or some character that is moving.

    • You can attach camera to a bone, even animated bone, exposed using ExposeTransforms. Camera can be animated this way.

  3. You can have multiple cameras in your viewport.

  4. Set TCastleViewport.Camera to choose the current camera used for rendering. It can even be nil, in which case no rendering is done. Camera Exists (as well as Exists of camera parents) also matter, non-existing cameras cannot render.

  5. This is backward compatible. When reading old designs, we add the camera to Viewport.Items automatically.

Navigation at run-time (like TCastleExamineNavigation, TCastleWalkNavigation) is easier to use.

  1. Just add navigation instance to a viewport, like any other UI control.

  2. Navigation also reacts naturally to Exists.

Viewport editing improvements

  1. Undo (Ctrl+Z) now preserves design-time camera and navigation.

  2. More useful default viewport 2D/3D setups.

  3. Improved new project “2D game” template: nice design-time camera, show spritesheets.

  4. Improved new project “3D FPS game” template: nice design-time camera, show skybox, show animations in editor, show lights in editor, show headlight as camera child.

  5. Better and more natural key shortcuts – Ctrl+Z, Ctrl+C, Ctrl+V, Delete.

  6. Added Cut Component (Ctrl + X)

  7. Added Save Selected… (save selected component to a design file)

  8. Better handling of behaviors (TCastleBehavior descendants) in editor: selecting behavior shows bbox of parent transformation, F on behavior focuses parent transformation too.

And more improvements that just happened along the way:)

  1. In 2D ProjectionNear, ProjectionFar can be, and usually should be, just 0 to autocalculate. This is just like it already was in 3D. I expect that in majority of applications you can just leave both ProjectionNear and ProjectionFar at default zero.

  2. Inspector (F8) shows non-default values with different colors.

  3. We now have TCastleControl.AutoFocus. See focus (receiving key input) on TCastleControl.

  4. Optimization (and fix for some edge-cases) in how vectors are deserialized (set all components at once, not one by one)

  5. Better TCastleExamineNavigation customization with Input_Rotate, Input_Move, Input_Zoom.

Upgrading

We put a lot of effort to make this change as backward-compatible as it reasonably can, including reading old designs. But this is a big change in how cameras work, both in editor and at run-time and under the hood. You should note that some things work differently:

  1. Because camera is now part of Viewport.Items:

    • Viewport.Items.Clear now removes also camera. Use Viewport.Items.ClearExceptCameras to leave TCastleCamera existing.

    • Viewport.Items transformation now affects the camera. Get/set camera using GetWorldView / SetWorldView to apply camera position/direction/up in world-coordinates, regardless of parent (including Viewport.Items) transformation.

  2. Some deprecated things around navigation have been removed. In particular Viewport.NavigationType no longer exists. Instead of Viewport.NavigationType := ntExamine now do Viewport.InsertFront(TCastleExamineNavigation.Create(SomeOwner));.

  3. More about backward compatibility in this post.

  4. If you have any questions, just ask on Discord or forum. We will help to upgrade πŸ™‚

Comments on the forum ➀