Work on X3D version 4.0 (in specification and Castle Game Engine), glTF and X3D and more documentation

Posted on

Helmet: Gamma Correct / Gamma Correct + Tone Mapping / No Gamma or Tone Mapping

This post is not strictly about Castle Game Engine. It’s about X3D 4.0, which is going to be the next major version of the X3D international standard (see the current X3D standards).

X3D is a major building block of our engine. While you can use TCastleScene as a “black box” (just to load models and play animations), but sooner or later you will want to change something in the loaded model, using Pascal code. For example to tweak a material of texture parameter, or adjust what is collidable. You can even build an entire 3D scene from scratch by Pascal code. This is all possible because everything inside TCastleScene is an X3D node (just a Pascal class like TXxxNode) and you can create/modify X3D nodes at runtime, from Pascal. Examples of it are throughout our documentation (see Building and editing the scene, X3D overview, examples about 3D building, examples about 2D building).

The point of this introduction is that we care about X3D, we want X3D to be modern and expressive, because it allows to express more things in CGE. While we can (and do!) implement a lot of custom extensions to the X3D standard, but some things are just best if they can be added to the standard.

So I did that 🙂

Since a few months, I was working with the Web3D Consortium to add to the upcoming X3D 4.0 a number of modern rendering features. I wrote a pull request to the X3D specification with it all. The summary of this pull request is here: X3D version 4: New features of materials, lights and textures. A summary of this summary:

  • New X3D 4.0 Material node is much more powerful, allowing to adjust all parameters by textures. It will also have dedicated fields to specify normalmaps (for bump mapping) and occlusion (ambient occlusion textures).
  • New X3D node PhysicalMaterial allows to express a Physically-Based Rendering parameters. It is compatible with glTF, and in fact is the basis of our PBR handling in glTF.

  • New X3D node UnlitMaterial is probably self-explanatory 🙂 It allows to define unlit material in a clear way.

  • There is a lot of other stuff and details. Also, image-based lighting is coming, but probably not in X3D 4.0 but in X3D 4.1 (I simply didn’t have time to make it, even though I have initial sketch of spec and implementation too.)

Now the cool part: This is all already implemented in Castle Game Engine. And you already use it 🙂 When reading glTF, you are actually creating in memory a graph with PhysicalMaterial nodes. When reading Spine JSON, you are creating in memory a graph with UnlitMaterial nodes.

I have a number of examples of all the new X3D 4.0 features (in pbr subdirectory there). You can just open them with our view3dscene.

A draft of complete X3D 4.0 specification will be soon available for public. So you will be able to read all the details about the new nodes. And I did a presentation about it last Friday (July the 3rd, 2020), it was recorded and will be publicly available shortly 🙂 I’ll post about it here of course.

In related news, you probably noticed that I put a lot of work into perfect glTF support. I think glTF format is a great thing, and I want to support it 100%. To this end, we want to load everything in glTF into X3D nodes. I have prepared a documentation how does CGE convert glTF to X3D nodes. This should give you insight into various semi-internal things that happen when we read glTF. I wrote “semi-internal” because, while you will usually just treat glTF as a “black box” through TCastleScene, you can also tweak the resulting X3D nodes graph using Pascal code.

I think that in the end, we will have a perfect combination in our engine, by leveraging 2 big open standards: glTF and X3D, as a basis of our engine.

Oh, and if you have any questions about X3D (not specific to CGE), you can ask them on x3d-public mailing list where all people working on X3D listen 🙂

Comments on the forum ➤

Third-Person Navigation (with Avatar) component in Castle Game Engine

Posted on

third_person_camera_screen_2
third_person_camera_screen_3
third_person_camera_screen_4
third_person_camera_screen_6
fps_game_screen_5
fps_game_screen_6
fps_game_screen_7

We present a new Castle Game Engine component TCastleThirdPersonNavigation. You can use it easily with TCastleViewport to have a working 3rd-person navigation. This means that you control an avatar with keys (ASWD QE), and the mouse orbits around the avatar, who is displayed and animated in front of the camera.

Features:

  • You can move the camera around the avatar and control the avatar in various ways. All the inputs are configurable.
  • Avatar can run, crouch, with collisions, with gravity.

  • Camera follows avatar smoothly and avoids being blocked by walls.

  • Mouse can optionally also “aim” the avatar, which makes it easier to rotate the avatar. OTOH, it makes it harder to look at avatar’s front, e.g. at avatar’s face.

  • You can look closer/further at the avatar.

  • Avatar can have gravity enabled, so it can fall down and climb stairs correctly.

It is all documented in our API. There’s a lot of published properties to play with.

You can trivially use it with CGE editor. Just select a viewport and, using the menu, change the Navigation to be TCastleThirdPersonNavigation. Remember to also assign the Avatar property.

The full demo is in engine sources, in examples/third_person_camera. Just download the latest engine and open “examples/third_person_camera/” project in the CGE editor.

The examples/fps_game was also updated to show how to use 3rd-person navigation together with TPlayer and TLevel classes. Just uncomment SetupThirdPersonNavigation call in the sample code to have it working.

This work has been sponsored through Castle Game Engine Patreon. In particular thanks to Ramazan Geven and Robert Daniel Murphy for donating and requesting this feature! If you like what I’m doing — please support me on Patreon. Thank you!

Comments on the forum (1) ➤

FPC 3.2.0 released, compatible with CGE, Docker images updated

Posted on

FPC (Free Pascal Compiler) logo

Great news: New major version of FPC (Free Pascal Compiler), the compiler of our game engine, was just released. New features are documented here. You can get it e.g. from SourceForge or using latest fpcupdeluxe.

Castle Game Engine is of course 100% compatible with it. I was watching and testing FPC SVN branch leading to this release. So I encourage everyone to upgrade their FPC installations. As always, we recommend using CGE with the latest FPC stable.

Note: Following our supported versions docs, you can also use some older FPC versions (we will maintain compatibility with FPC >= 3.0.2). So you don’t have to upgrade, for now we promise to keep compatibility with FPC 3.0.x for the next CGE release.

Note: if for some reason you have to stick to the old Castle Game Engine 6.4, I maintain a v6.4-fixes branch with minimal CGE 6.4 changes to make it compile with FPC 3.2.0. Although I would encourage everyone to upgrade to latest CGE that will soon be released as CGE 7.0 with ton of new features.

Our Docker image has been updated to include FPC 3.2.0, and actually use it by default. See also Jenkins docs.

Comments on the forum ➤

Gamma Correction and Tone Mapping

Posted on

Helmet: Gamma Correct / Gamma Correct + Tone Mapping / No Gamma or Tone Mapping
Damaged Helmet: Gamma Corrected / Not Corrected
Specular Highlight: Gamma Corrected / Not Corrected
Teapot: Gamma Corrected / Not Corrected

Gamma Correction and Tone Mapping are now implemented in Castle Game Engine. They can be trivially controlled by global variables GammaCorrection (by default it is on for PBR materials) and ToneMapping.

Gamma Correction is a way of making lighting calculations more correct (see e.g. here and here for explanation; my analysis of various implementation is here).

Tone Mapping is just a fancy name for nice-looking color processing, that makes the final look more visually pleasing. It is independent from the gamma correction (technically), although they both “change the scene colors” so are often considered together. We now implement 3 tone mapping operators (based on glTF sample viewer): see TToneMapping. Note that you can easily do your own color processing (thus providing functionality equivalent to these tone-mapping operators) by using Effect node like in this example: tone_mapping.x3dv from demo models.

I wrote a new manual chapter about Gamma Correction documenting all of this, and my description of gamma correction in various engines was also extended.

Comments on the forum ➤

Easy property to make animation blending

Posted on

DefaultAnimationTransition in CGE editor

We introduced TCastleSceneCore.DefaultAnimationTransition property.

This is a really easy way to request animation cross-fading (blending) which makes changing animations look much smoother. Just set this to some non-zero value to have smooth animation change. It’s the time in seconds, often it’s reasonable to start with something small like 0.1.

This is also configurable in the CGE editor (as it’s a published property). Our “New Project” template 2d_game is using it.

And it’s available in resource.xml file for the creature. Our examples/fps_game/ is using it for the “knight” creature. Like this:

<model url="knight.gltf" pool="10" default_animation_transition="0.25">
  <idle   animation_name="Idle"    />
  <walk   animation_name="Walk"    />
  <attack animation_name="Attack"  />
  <die    animation_name="Die"     />
  <hurt   animation_name="Damaged" />
</model>

This also brings improved switching to the default state (like idle or walk) after Attack/Hurt. This makes animation change smoother for creatures using resource.xml, whether you use default_animation_transition or not.

Comments on the forum (2) ➤

Reading punctual lights from glTF

Posted on

3d_fps_game_template_2
3d_fps_game_template
blender screenshot 2020-06-07 00:12:50 selection
fps_game_screen_4
fps_game_screen_3

We can now read lights from the glTF file.

The lights have to follow glTF extension KHR_lights_punctual. It’s a popular extension supported e.g. by Blender -> glTF exporter. So you can just add lights in Blender, export to glTF, open in CGE, and the lights are there!

This works for “punctual” glTF lights, which are converted in a very straightforward fashion to X3D lighting nodes: PointLight, SpotLight, DirectionalLight.

Demos:

Comments on the forum ➤

Various API improvements (ShowUserInterfaceToQuit, SaveScreenToDefaultFile, orientation matching glTF by default) and build tool and editor improvements

Posted on

my-new-project-2d_screen_0

A number of improvements all across the engine:

  1. ApplicationProperties.ShowUserInterfaceToQuit. Useful to hide that “Quit” button on mobile. Used by the editor new project templates for 2D and 3D games.

  2. Saving screenshot to the best location, automatically determined: Container.SaveScreenToDefaultFile, lower-level SaveScreenPath. This is important as you cannot assume that your application can write to the current directory when installed. This featue is also already used by the editor new project templates (press F5 in 2D and 3D games).

  3. Viewport.TransformUnderMouse represents the current TCastleTransform under the mouse. It’s easier to use than lower-level Viewport.MouseRayHit.

  4. The default orientation (important if you use TCastleTransform.Direction property to rotate your models) changed from otUpYDirectionMinusZ to otUpYDirectionZ. The new default makes us work out-of-the-box intuitively with glTF models.

    I wrote a lot of text why this change, although breaking compatibility, makes sense on our page documenting upgrade process from CGE 6.4. See also manual about it.

    If you use TCastleTransform.Direction and want to restore compatibility, just set TCastleTransform.DefaultOrientation := otUpYDirectionMinusZ; somewhere early (like in the Application.OnInitialize callback).

  5. Our build tool now does output filtering to hide many useless FPC warnings that occur when using Generics.Collections. This is better than disabling these warnings through FPC command-line options, this way e.g. compiler will still warn about instantiating abstract classes.

  6. view3dscene gets a new command-line option --project, automatically used by the editor if you double-click on a scene file in your project. In effect, the castle-data:/ protocol will also work as URL for textures etc. inside X3D, glTF and other files.

  7. CGE editor has now context menu when you right-click on files section at the bottom. You can open file manager, delete the file, refresh the directory.

  8. For PointLight / SpotLight, radius < 0 means “infinity”. This is useful to convert glTF lights, that may have range equal 0 to mean infinity. So we just convert 0 to -1.

  9. New glTF tests:

Comments on the forum ➤

New useful project templates in the Castle Game Engine editor

Posted on

1_new_project
2d_1
2d_2
2d_3
3d_1
3d_2
view_1
view_2

If you click on “New Project” in the Castle Game Engine editor now, it will propose 4 useful templates:

  • Empty
  • 2D game

  • 3D FPS game

  • 3D model viewer

I advise everyone, new and old engine user, to check out these templates. You can get the latest engine version from our main page, as usual. Just unpack and run bin/castle-editor executable. (Or you can get the source code from GitHub).

I tried hard to make these templates small but also very useful as a starting point.

They show how to use most important engine features (design viewports, scenes, basic UI in the editor), advise using TUIState to split your code into states, show how to react to basic input (clicking on game field to do something).

Note that “3D FPS game” doesn’t use the item/creatures logic from the CastleCreatures unit, documented in the manual about utilities for typical 3D games. Instead the 3d_fps_game presents much simpler (but also more flexible to extend) approach to implement creature AI, by dealing directly with TCastleScene.

Comments on the forum ➤

Activity Recognition on iOS

Posted on

Activity Recognition on iOS

I have implemented a service that allows to easily query about the current user activity (walking, running, cycling etc.) on an iPhone.

Services are ways to enhance your applications with additional code that has platform-specific implementation and may link with 3rd-party library. See more about iOS services and Android services. You declare them in CastleEngineManifest.xml and then just build your application using our build tool.

We now have a new iOS service called activity_recognition. A demo is inside the examples/mobile/activity_recognition subdirecory of the engine source. The demo is cross-platform, however it will not report any activity on other platforms than iOS for now.

The Pascal API is documented in CastleActivityRecognition unit (in particular see TActivityRecognition class).

Comments on the forum ➤

We have a new joysticks database in Castle Game Engine, and we need YOU to help us test it

Posted on

Joystick

Hello everyone!

We have a big and important, but simple request. We’ve reworked the handling of the joysticks and gamepads in Castle Game Engine, with a lot of new features that include serious improvement of joysticks API, access to a huge joysticks database by SDL2 with hundreds of joysticks definitions, autodetection of joysticks, detection of connection/disconnection of joysticks, etc.

However, because we have very limited access to hardware, we are unable to test how well those new features work. And therefore we need your help to test if everything is working as expected on different hardware joysticks/gamepads.

You can download and build “joystick” project from “examples” in this fork: https://github.com/eugeneloza-clean/castle-engine. It is not yet merged into CGE master, but of course it will be — that’s why we ask you to help with testing!

Ready precompiled binaries for Windows 64 bit and Linux 64 bit are here.

If you have access to a hardware joystick or gamepad, please use this tool and tell us (e.g. using forum):

  1. Your joystick name and operation system (Linux or Windows)
  2. Name your joystick was detected in Castle Game Engine

  3. If your joystick was correctly autodetected. If not, can you find your joystick in the list of joysticks and try using it?

  4. Did the axes and buttons on your joystick corresponded to the axes and buttons displayed in the tool? Note, that the names of the buttons and exact joystick layout may be different, but right stick must be right and upper button must be the upper one.

Thanks a lot!

And thanks a lot to Eugene Loza for developing it all!

Comments on the forum (9) ➤