Ab4d.SharpEngine beta 2 comes with many new samples

by abenedik 18. April 2023 09:30

The second official beta version of the new cross-platform 3D rendering engine has been published. You can get the new samples from: https://github.com/ab4d/Ab4d.SharpEngine.Samples (on GitHub also click on the Watch button to be informed of future changes).

The new version comes with many new samples that demonstrate a lot of functionality of the new engine. There are samples that demonstate cameras, mouse camera controller, materials, lights, different 3D objects and lines, model importers and animation. The following screenshot shows the samples running in a WinUI 3.0 application:

Ab4d.SharpEngine Vulkan samples in WinUI 3.0 application

You can see that the samples are organized in a similar way as the samples for Ab3d.PowerToys and Ab3d.DXEngine.

Because the engine can run on multiple platforms and UI frameworks, most samples are now defined in a common samples project (Ab4d.SharpEngine.Samples.Common). That project uses a generic UI provider that can create UI elements like Labels, CheckBoxes, ComboBoxes, Sliders, Buttons and other elements that are required for the sample. Then the project for the specific platform references that common project and provides rendering of the UI. This way the same sample code can be used for WPF, WinUI and Avalonia. The Avalonia sample works on Windows and without any change in code the same sample also runs on Linux and macOS (see screenshot with Rider IDE in the back):

Ab4d.SharpEngine Vulkan samples in Avalonia application running on Linux

Ab4d.SharpEngine Vulkan samples in Avalonia application running on macOS

There are also two special samples for Android. They show only a single 3D scene. Their purpose is to demonstrate two different ways on how to initialize the engine in Android. From there on, the code to create and manipulate the 3D scene is the same as for desktop operating systems. The following screenshot shows the engine running in Android:

Ab4d.SharpEngine sample in Android application

The current version does not support iOS yet. The problem there is that AOT (ahead-of-time) compilation that is required for iOS does not support function pointers (https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/function-pointers) that are used by the engine to communicate with Vulkan. It is interesting that for Android or desktop it is possible to use AOT compilation and there function pointers work without problems. If you have any recommendations on how to use function pointers on iOS, I would be glad to hear that. Otherwise, it seems that a special build of SharpEngine will be required for iOS. That build would use a different and less efficient way to call Vulkan functions (using standard delegates and UnmanagedFunctionPointer attribute). This needs some additional research so the support for iOS has been moved to the next version.

The major goal of this beta version was to provide new samples that demonstrate how to use the engine. But there were also many improvements behind the scene.

The most important is updated code for sharing the rendered 3D scene with WinUI and Avalonia. In this case the 3D scene that is rendered by Vulkan stays in the GPU memory and is shared by the WinUI or Avalonia. The code for WinUI now uses SwapChainPanel instead of SurfaceImageSource. This is faster and better supported - SurfaceImageSource had problems on older computers or computers with integrated Intel GPU. In Avalonia the previous code for sharing texture created OpenGL vertex and pixel shaders and rendered the shared Vulkan texture to an OpenGL context. This was very complex and did not work well on all platforms. The developers of the Avalonia UI were also aware that this was not done well, so we worked together to define a new interface that can be used for sharing an external texture with Avalonia (after some private discussions with the developers the following was issued: External GPU memory interop (OpenGL, Vulkan, DirectX). The new version of the engine uses that new interface. This works very well so that shared texture can be used on computers where the previous approach did not work. What is more, Avalonia currently uses OpenGL to render its user interface, but there already exists a build of Avalonia that uses Vulkan to render the interface. This will be publicly available in one of the future versions. This means that it will be even easier and faster to share the 3D scene created with Ab4d.SharpEngine because whole application could use the same Vulkan device.

If you have not tested the beta 1 version, I would like to encourage you to try the new beta version. If you know how to create a 3D scene by using Ab3d.PowerToys, then it should be easy to work with the new library because the general concepts are the same. There are some differences in object names, but when working with the new engine, you will quickly see that the new API is much more polished than when using the Ab3d.PowerToys and Ab3d.DXEngine. The problem with those two libraries was that they were based on WPF 3D object model. That object model was extended by Ab3d.PowerToys and later by Ab3d.DXEngine objects. Because of this in those two libraries there exists multiple ways to define 3D objects: based on GeometryModel3D, Visual3D and on SceneNodes from DXEngine. Now, the 3D objects are all derived from SceneNode. All object grouping is done by GroupNode (instead of Model3DGroup, ModelVisual3D, ContentVisual3D, SceneNode). Also, when using Ab4d.DXEngine you need to use some tricks (using SetDXAttribute method) to define advanced properties on WPF materials. Now all material properties are directly accessible.

As promised before, the work on Ab3d.PowerToys and Ab3d.DXEngine will not stop. There are already many improvements and fixes in the current development version. Now I will focus on providing some additional new features and then prepare a new release. So if you have any recommendations, it is now a great time to provide that.

Tags: , ,

SharpEngine