X3D specification 4.0 draft, with Physically-Based Rendering materials supported by Castle Game Engine

Posted on

DamagedHelmet_0

Our engine uses X3D nodes to express everything that is rendered in 2D or 3D inside TCastleScene.

That is why, as I announced previously, I was working on X3D specification to incorporate some modern rendering features in X3D 4.0, in particular Physically-Based Rendering.

I’m happy to announce that the result of this work is now available publicly. It is X3D 4.0 2nd working draft. Despite the “draft” specification version, it is something we actually implement in CGE right now, and thus the X3D 4.0 draft specification serves also as a documentation for CGE. In particular see:

Comments on the forum ➤

Various improvements: project caption in editor, castle_indy package, CThreads, etc.

Posted on

Castle Game Engine editor - New Project dialog

Various important improvements done lately in Castle Game Engine:

  1. You can set project caption when creating a new project in CGE editor.

  2. Our CastleClientServer unit (for TCP/IP networking) has been moved to a new Lazarus package castle_indy that depends on indylaz package. This makes our connection to Indy cleaner, and fixes the client/server example compilation. This entire section of the manual was also improved.

  3. CGE applications (if you let the build tool to auto-generate your program file) on Unix now by default use CThreads, thus they can use TThread.

    This affects desktop Unix platforms, like Linux and FreeBSD.

    This means that

    1. asynchronous downloading (TCastleDownload with http, https) and
    2. music streaming (SoundEngine.LoadBuffer(.., slStreaming) with default OpenAL backend)

    … just work out-of-the-box. I suspect that more and more such features will appear in the future, so it makes more sense to make the default “threads work on Unix”.

    If you would like to disable CThreads for some reason, you can still do it by compiling with CASTLE_DISABLE_THREADS.

    FPC by default doesn’t use CThreads, to avoid linking with C library, to increase compatibility across Linux distros. But, as far as my experience goes, this argument is no longer relevant in 2020. I haven’t actually encountered any case when a binary FPC application cannot be transferred from one Linux to another due to CThreads API incompatibility. Reading one recent FPC bugreport about it I can conclude that the fear of “linking to C by default” is now more because of “unforeseen consequences”, not because of any proven visible problem that can occur on Linux in 2020. And that report is about FPC_USE_LIBC, while using CThreads should be a smaller issue.

    And note that CGE uses a few libraries that definitely change more rapidly than C library anyway (e.g. libpng, X, GTK, OpenGL…).

  4. remote_logging example was redesigned:

    1. Should work on all platforms nicely now, doesn’t need console
    2. Shows nice UI with animation (to show that all HTTP stuff doesn’t cause any interruption in the main thread)
Comments on the forum ➤

Weighted mesh (skinned mesh animation) in Spine

Posted on

Spine weighted mesh in view3dscene

We add support for a major Spine’s feature: weighted mesh. Spine is a great 2D animation software, and this feature allows to have use it for skinned animation. It was implemented by Trung Le (Kagamma) — thousand thanks!

See the demo movie:

The sample files are part of our demo models. Simply get this repository, and explore examples in spine/weighted_mesh subdirectory. You can open the JSON files using view3dscene or any other engine tool to view scenes.

Details (from the pull request):

  • Support for weighted mesh, by interpolating values between bone timelines.
  • Make weighted mesh work with deform timeline.

  • Additional frames for better transition, this will make animation more accurate in certain situation (rotation and non-linear interpolation types) in exchange for longer load time and more memory consumption.

  • Non-linear interpolation type (Bezier curve) for weighted mesh (both bone timeline and deform timeline).

  • Add deprecated warning to skinnedmesh attachment.

Limitations:

  • Due to the way we handle weighted mesh (by baking every transformations, including bones, into TCoordinateInterpolatorNode), we cannot have a mix of weighted mesh attachments and other types of attachment in the same slot.

Comments on the forum ➤

Pas2js with generics rocks (and makes Castle Game Engine for WebGL possible)

Posted on

pas2js-generics
pas2js-webgl1
pas2js-webgl2

pas2js can translate modern Object Pascal to JavaScript, making it possible to run Pascal code in a WWW browser. In the past, pas2js didn’t support generics, which made porting CGE to it troublesome, as we use generics a lot.

This weekend I tested recent pas2js support for generics, in particular with containers from the Generics.Collections unit. I tested 4 examples from my book about modern Pascal. …And the result is that everything just works! 🙂

This means that pas2js supports generics at a level we need for Castle Game Engine, so in general should be able to handle CGE Pascal code. Pas2js also supports WebGL rendering since a long time, since it can just call JavaScript API in a browser.

All this means that we have everything we need to port Castle Game Engine to WebGL! That is, your games could be recompiled to just run in a WWW browser. No installation, no extra steps for the user. Anyone can open your WWW page and the game works, with Pascal code being translated into simple JavaScript that browser can efficiently execute.

I will work on this feature intensively after CGE 7.0 release.

Comments on the forum ➤

Pull request to X3D 4.0 to add Physically-Based Rendering and other improvements – merged!

Posted on

steampunk_gltf

I’m proud to announce that my pull request to introduce a lot of new features to X3D 4.0 is now merged into the “master” branch of the X3D 4.0 specification. It introduces new rendering features that we already use in CGE:

  • PhysicalMaterial node

  • UnlitMaterial node

  • lots of (Phong) Material node upgrades

  • consistent RGB/grayscale texture treatment

  • Appearance.backMaterial (and deprecation of TwoSidedMaterial)

All these changes are now on their way to the soon-to-be-published new X3D 4.0 public draft. And then to X3D 4.0 official release, after (I hope!) countless people will review it and point out all the errors I did 🙂

Companion documents / tests:

  1. My summary of these changes.

  2. Test files for this feature are in the my x3d-tests repository, in pbr/ subdirectory. I plan to work on them more — add some more, add reference screenshots, add XML encoding versions etc.

  3. Almost all specified things are implemented in our Castle Game Engine and can be tested by view3dscene right now.

  4. The reasons behind various decisions in the PBR specification are documented here.

  5. We have documentation on how various glTF concepts map to X3D, and how Castle Game Engine does it.

Comments on the forum ➤

Asynchronous (non-blocking) downloading using TCastleDownload class, and other HTTP communication features

Posted on

asynchronous_download screenshot

The new class TCastleDownload allows to download data over http and https asynchronously, without blocking the main thread of the application. This means that you can trivially continue rendering and game logic, while some resource are being downloaded over the network.

I made a demo in examples/network/asynchronous_download/. It demonstrates multiple simultaneous downloads, and underneath a glTF animation is playing with smooth 60 FPS without any breaks.

The class supports all CGE URLs, like file, http, https, castle-data and more.

Manual chapter about networking was updated to reflect all new possibilities.

Features:

  • The download can be observed (looking at Status, DownloadedBytes, TotalBytes).
  • When it’s finished, look at Contents (if success) or ErrorMessage (if error, that is Status = dsError).

  • We can read MIME type from server (can be used throughout our engine to designate file type).

  • It’s actually a full-featured HTTP(S) web request. You can specify HttpMethod, like GET, POST, PUT etc. For POST, you can provide form data as PostData. Arbitrary HTTP headers can be specified using AddHeader.

More examples:

This feature was done thanks to your support on Patreon. It was requested by Peardox. Many thanks! If you like what I’m doing, please support our engine.

Comments on the forum ➤

Engine improvements: easy methods to check collisions, raycast, fixed bold in editor, image-based lighting started

Posted on

screenshot 2020-07-18 00:55:00 selection
environment_light_various_gltf_sample_viewer_setups_0
environment_light_cubemap_composed_0

I have a few cool announcements about CGE features this weekend 🙂 Let’s start with a summary of new things done lately:

  1. Fixed bold / non-bold display in CGE editor for Single properties. Bold in object inspector should always mean “different than default” intuitively.

  2. I have started implementation of the EnvironmentLight X3D node, to perform image-based lighting. This is a work-in-progress. The eventual goal is to add such light to CGE, and to X3D 4.1, and to make it consistent with glTF image-based lighting extension. See X3D 4 plans and initial EnvironmentLight tests.

  3. The run command of our build tool is now more useful on Windows. It shows the log, just like on all other platforms (desktop Unix, mobile…). So using castle-engine run on command-line is now very useful on Windows.

    Note that for most users, I would advise just using Run command in CGE editor. This also outputs log nicely.

  4. Additions and fixes to CastleTransform API:

Comments on the forum ➤

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) ➤