Last major version of Ab2d.ReaderSvg and ZoomPanel published

by abenedik 17. December 2021 11:01

I would like to inform you that the last major version of Ab2d.ReaderSvg and ZoomPanel libraries have been published.

With this release both libraries have got special builds for .Net 5.0 and .Net 6.0. Also, both libraries are available as NuGet packages. Note that the version that is distributed through NuGet uses a different licensing mechanism than the version that is installed by the evaluation or commercial version installer. The same assembly from NuGet can be used for evaluation and commercial usage. The commercial usage can be activated by calling the SetLicense method. The code for that method can be obtained from the User Account web page.

With the support for the latest .Net versions and NuGet both libraries are updated to the latest standards. 

The Ab2d.ReaderSvg library also got some additional new features that improve reading some more complex svg files that use "use" or "marker" elements. See the changelog for more info.

Both libraries are used by many customers in many commercial products. In the last years, they have received many new features and fixes. This makes then are very mature.

The development at AB4D company is focused on 3D products. Therefore, the 2D products (including Ab2d.ReaderSvg and ZoomPanel) will get only limited support. Also, there are no major new versions planned. The future development will cover only simpler or critical issues or be based on custom development.

Tags:

ReaderSvg | ZoomPanel

New major versions for 3D libraries released

by abenedik 26. November 2021 10:08

I am happy to inform you that new major versions for Ab3dPowerToys and Ab3d.DXEngine libraries have been released. 

The Ab3d.DXDXEngine has reached version 5.0. This is the 21st release of the library. The Ab3d.PowerToys library has climbed even higher and has reached version 10.0, having the 34th release of the library. The high number of releases is even more impressive when checking the actual change logs (see https://www.ab4d.com/PowerToys-history.aspx and https://www.ab4d.com/DXEngine-history.aspx). The long list of new features and changes that were often requested by the users shows that the libraries have become very mature and that they can be used for many different types of business, technical and scientific applications with 3D graphics. To make the numbers even more interesting, the build number of the new version is set to 8000. Because the build number is calculated as the number of days since 1st January 2000, this means that this release has happened on the 8000th day of the new Millenium (on 26th November 2021).

The highlights of the new versions are:

  • New Model viewer sample.
  • Rendering two-sided materials in one render pass.
  • Triangles sorting for transparent meshes.
  • Updated assimp importer that can read 3D models from almost any file format.
  • Added FitIntoView method for FreeCamera.

 

The first great new added value of the new version is a new Model viewer sample:

DXEngine Model Viewer

This sample does not provide any new feature but demonstrates many features of the Ab3d.PowerToys and Ab3d.DXEngine libraries. And because almost any application with 3D graphics requires object loading, mouse selection, wireframe and solid object rendering and showing object hierarchy, the sample is an excellent source of code snippets that you can use in your applications.

You can also use the sample to inspect the 3D models that are loaded from many file formats with Assimp importer. As shown in the following screenshot, it is possible to show mesh normals, position indexes and triangle orientations for the selected model:

DXEngine Model Viewer

Additional information can be obtained when an object without children (a GeometryModel3D) is selected. Then clicking on the "Show info" button will show the details about the mesh with a generate c# code that defines the mesh (creating arrays for all positions, normals, texture coordinates and triangle indices).

I am sure that you will find the new Model viewer interesting. Now let me provide some information about new features. Let me start with some background knowledge.

In 3D graphics the most fundamental building block of a 3D object is a triangle. And each triangle has its front and its backside. By default the front side of the triangle is the side where the vertices are defined in counter-clockwise order. The backside is the other side where the vertices are defined in clockwise order (see more here https://www.khronos.org/opengl/wiki/Face_Culling). In 3D graphics you can assign one material to the front side of the triangles and another material to the back side of the triangles. When using a GeometryModel3D object, the front material is assigned to the Material property, and the backface material is set to the BackMaterial property.

Many times the 3D models are solid and closed so we cannot see inside the 3D model. In those cases we can render only the front sides of the triangles and skip rendering the backsides. This reduces the number of rendered pixels by half. For example, 3D box and 3D sphere are solid and closed models and therefore the graphics card does not need to render the inner sides of the triangles. But when rendering a 3D plane, opened cylinder or any other model with holes, the graphics card needs to render both front and back triangles (both Material and BackMaterial properties need to be set). This is needed because the user can rotate the camera to see the other side of the plane or inside the model. The other case when we need to render both sides is when the object uses semi-transparent material. There the user can see the inner side of the 3D model. The models that use the same material for both the front and back sides are described as using a two-sided material. Two-sided materials are used many times for all the objects in technical 3D graphics.

Usually, the rendering of two-sided materials is done in two passes. First, the backside of the material is rendered, then the front side is rendered. When rendering the backside, the DirectX rasterizer state needs to be changed to prevent culling (skipping) the backside. Also, the code in the shader needs to invert the normal vector so that the lighting calculations are correct. This means that rendering models with two-sided material requires two DirectX draw calls and therefore takes twice as much time as rendering models with single-sided materials (actually, there is also an additional performance penalty because of rasterizer state changes).

The new version of Ab3d.DXEngine can use the DirectX SV_IsFrontFace semantics (https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-semantics) that is used in the shader to check if the front side or the backside of the triangle is being rendered. This information is needed to invert the normal in the case of backside rendering. Also, the backside culling needs to be disabled in the DirectX rasterizer state. This allows the new version of Ab3d.DXEngine to render two-sided materials in one rendering pass. This means that 3D scenes where all 3D models have two-sided materials will be rendered twice as fast as before.

When using DXEngine's materials (supported by StandardMaterial, VertexColorMaterial, PhysicallyBasedMaterial and WpfMaterial), the two-sided rendering can be enabled by setting the IsTwoSided property to true. When using WPF 3D objects, then two-sided rendering will be used when the Material and BackMaterial on the GeometryModel3D are set to the same material instance. This will set the IsTwoSided property to true in the DXEngine's WpfMaterial that is created from the WPF's material. 

It is possible to prevent this new functionality by changing the static DXViewportView.UseTwoSidedMaterialsForSolidObjects and DXViewportView.UseTwoSidedMaterialsForTransparentObjects fields. As seen from the field names, there are different settings for solid and for transparent objects. By default, solid two-sided objects are rendered in one rendering pass (UseTwoSidedMaterialsForSolidObjects is true). But by default, transparent objects are still rendered in two passes (UseTwoSidedMaterialsForTransparentObjects is false) - first rendering the back material and then the front material. This is needed to preserve the rendered result as it was before. It is possible to set the UseTwoSidedMaterialsForTransparentObjects to true, but then it is recommended to set the new DefaultTransparentDepthStencilState field to DepthRead (from DepthReadWrite). This will render transparent objects in one render pass and correctly render the inner side of the objects. See the new "TwoSided materials" sample for more info.

DXEngine Model Viewer

 

The next new feature of the engine is the support for sorting individual triangles in a mesh. This may be required when showing semi-transparent meshes that have complicated geometry, as for example the following torus knot:

DXEngine Model Viewer

On the left the screenshot shows the object without sorted triangles. Red arrows mark the parts that are not correctly visible through the mesh. Green arrows indicate the correctly rendered pars of the object. Note, if the object would be rotated to the other side, then the correctly visible parts would change.

The new version of Ab3d.DXEngine has a highly optimized triangle sorting code that works on low-level triangles and positions data (WPF's MeshGeometry3D objects are not used because they are very slow). The code changes the data in the index buffer. After sorting is done on the CPU, then the changed index buffer needs to be sent to get GPU. Those two processes can take some time, so you should consider using triangle sorting only when really needed. 

Ab3d.DXEngine has got some other great new features and bug fixes. And there are also two new additional samples that are designed to improve understanding of GraphicsProfiles and different options to render wireframe lines. See screenshots:

DXEngine Model Viewer

DXEngine Model Viewer

 

The Ab3d.PowerToys library also got some great new features. In my opinion the most important new feature is an updated Assimp importer. The Assimp importer is a third-party native library that can import 3D models from more than 40 file formats. The previous version 5.0.1 of Assimp was released a long time ago, in January 2020. After that release, the library got many improvements and also some breaking changes that crashed the .Net wrapper. But because there was no increase in the library's version number, it was not possible to update the wrapper to work with the newer build of the library. Finally, on 20th November (last week) a new official version 5.1.1 of Assimp library was released. This meant that it was possible to update the AssimpNet (.Net wrapper for the native library) and the Ab3d.PowerToys.Assimp library (helper library that converts the read 3D models into WPF 3D objects). The new libraries improve support for many file formats and add some new file formats to the supported list.

Those two libraries and the compiled native Assimp library are available with the new Ab3d.PowerToys sample on GitHub (https://github.com/ab4d/Ab3d.PowerToys.Wpf.Samples/tree/master/lib). Those libraries are also installed by the evaluation installer of the AB4D products (https://www.ab4d.com/Downloads.aspx) and the commercial installer for the Ab3d.PowerToys library (available from User Account web page).

The new version of Ab3d.PowerToy also comes support for calling the FitIntoView method when using FreeCamera (a highly requested feature). This provides the same functionality to FreeCamera as available by the TargetPositionCamera.

 

As always, please update to the new versions and check the new samples projects (https://github.com/ab4d/Ab3d.DXEngine.Wpf.Samples, https://github.com/ab4d/Ab3d.PowerToys.Wpf.Samples). In the new samples check the samples that are marked with NEW and UP icons. The icons mark new samples and the samples that were updated in the last version (hovering the mouse over the UP icon will show you more information about the change).

Tags: , , , ,

Ab3d.PowerToys | DXEngine

New Assimp importer for Ab3d.DXEngine published

by abenedik 30. July 2021 14:22

In this short blog post I would like to inform you that a new Ab3d.DXEngine.Assimp library has been published. It can be used to import 3D objects from many file formats into Ab3d.DXEngine objects.


The library is available with full source code on GitHub: https://github.com/ab4d/Ab3d.DXEngine.Assimp.

 

It is also available as a NuGet packge: https://www.nuget.org/packages/Ab3d.DXEngine.Assimp

 

Before this new library was published, it was also possible to import 3D objects into Ab3d.DXEngine objects, but this required using Ab3d.PowerToys.Assimp library. That library first converted native assimp objects into managed objects in Assimp.Net library, then converted those objects into WPF 3D objects and finally converted that into Ab3d.DXEngine objects. This took much longer and required more memory.

 


Now with the Ab3d.DXEngine.Assimp library it is possible to convert the native assimp objects directly into the Ab3d.DXEngine objects. The library creates the following objects:

  • MeshObjectNode for objects with meshes
  • SceneNode objects for groups of objects
  • SimpleMesh<PositionNormalTexture> for meshes
  • StandardMaterial for materials


The new library is using a Silk.NET.Assimp library as a wrapper library (instead of an old Assimp.Net library that Ab3d.PowerToys.Assimp uses).

 

Because of Silk.NET.Assimp the new library can currently work only in x64 processes (I have added an issue to the Silk.NET.Assimp GitHub repository about the problem in x86 process so hopefully, this will be solved soon).

 

Though the Ab3d.DXEngine.Assimp is much faster then Ab3d.PowerToys. Assimp, it also have the following limitations compared to Ab3d.PowerToys.Assimp:

  • cannot read animation data (Ab3d.PowerToys.Assimp can read animations and even play skinned animations by using Ab3d.PowerToys)
  • cannot read polygon data (polygon indices are read by Ab3d.PowerToys.Assimp into MeshGeometry3D).
  • cannot export 3D scene into file by using assimp as an exporter.

 

Anyway, if you only need to import 3D objects and you are using Ab3d.DXEngine that in it worth checking the new importer. Some missing features will be added in the future versions.



 

As a sidenote, I would also like to inform you that at the beginning of this week, a new hotfix version of Ab3d.DXEngine was published. It fixes a few issues mainly related to using multiple DXViewportView objects. The change log can be read here: https://www.ab4d.com/DXEngine-history.aspx


If you are using multiple DXViewportView objects, then it is highly recommended to upgrade to that version.

Tags:

DXEngine

Improved versions of Ab3d.PowerToys and Ab3d.DXEngine published

by abenedik 28. June 2021 15:48

Another new version of Ab3d.PowerToys and Ab3d.DXEngine libraries have been released.

Though this is a minor release, it still brings some amazing new improvements. For those of you that are rendering complex 3D graphics and also need to show WPF controls on top of the 3D scene, the new version of Ab3d.DXEngine brings two new great features:

1)

The performance of DirectXImage presentation type (required to show WPF controls on top of 3D scene) has been significantly improved. This was done by improving the Ab3d.DXEngine so that it can wait in a background thread until the graphics card finishes rendering the 3D scene. Then Ab3d.DXEngine invokes the code on the main thread that sends the rendered scene to the WPF composition engine. This means that the main thread does not need to wait anymore for the graphics card to complete the rendering of the 3D scene.

The most significant performance improvement of this new feature can be seen when the graphics card is rendering objects with a very big number of triangles or when using mesh instancing. In this case only a few DirectX commands issue a lot of GPU work. On the other side, when many DirectX commands are called, the performance improvement is not that big because Ab3d.DXEngine still needs to wait on the main thread until the graphics driver finishes processing the commands (DirectX Flush command needs to finish executing on the main thread). Anyway, in both cases the performance improvements (the time that you have on the main thread for your tasks) are significant. And what is best, you do not need to do anything except switching to a new version. 

 

2)

If you need even more performance and would also like that most of the drivers's work is done on the background thread, then you need to use DirectXOverlay presentation type. In this presentation type, the DirectX gets its own part of the screen (a hwnd handle) where it can present the rendered 3D scene when the graphics card finishes rendering. This presentation type is the fastest because the main thread is freed immediately after the Ab3d makes the last draw call by the Ab3d.DXEngine - both the driver's work and rendering are done in the background.

The problem with this presentation type is that it is impossible to render WPF controls on top of the 3D scene. Actually, WPF is not aware that the controls are hidden by the overlaid 3D scene so it will still render the controls, pass mouse events to the controls so they will be fully functional, but not visible.

The new version of Ab3d.DXEngine can solve the problem of hidden WPF controls in DirectXOverlay mode by using 2D sprites (also a new feature in this version) to show the static WPF controls (for example a TextBlock or a MouseCameraControllerInfo) or WPF controls that use Viewport3D (for example CameraAxisPanel or ViewCubeCameraController). The controls with Viewport3D are actually rendered by Ab3d.DXEngine. The trick is to render Viewport3D in a secondary DXViewportView control. This DXViewportView is created with the same DirectX device as the DXViewportView control that renders the main 3D scene. This way all DXViewportView controls can share the rendered results. For example, the secondary DXViewportView renders the CameraAxisPanel into a 2D texture and then this texture is shown on the main DXViewportView as a 2D sprite.

This can be done very easily with two new classes: WpfElementOverlay and Viewport3DObjectOverlay. What is more, the full source code of those two classes is available in the main Ab3d.DXEngine samples project.

 

The new version of Ab3d.DXEngine also comes with improved InstancedTextNode. This object can be used to render millions of characters. With the new version it is possible to change the individual texts and also remove some texts. For advanced users, the new version comes with a new InstancedMeshNode object that can show instanced meshes without using WPF's MeshGeometry3D (you can use any mesh derived from DXEngine's MeshBase). Also, the new version can prevent WPF's rendering thread exception (UCEERR_RENDERTHREADFAILURE) that may happen when the primary monitor has changed (for example when a laptop is connected to a docking station and uses more than one monitor; disconnecting the monitors can trigger a WPF excepton).

The Ab3d.PowerToys library also comes with a few new features and fixes. The new SphericalZoneVisual3D (and Ab3d.Meshes.SphericalZoneMesh3D) can show part of a 3Dsphere. This 3D object can be used to add a rounded end to a 3D cone or a 3D tube line. In addition, the FitIntoView method got two new overloads so you can call the method with passing a custom Rect3D (bounding box) or a custom list of 3D positions.

To see the full list of changes, check the history web pages: Ab3d.PowerToys history, Ab3d.DXEngine history.

 

I am also happy to inform you that the work on a new Vulkan based cross-platform rendering engine is also progressing very well. Here are two sample screenshots:




The first screenshot shows a test scene with the content of the memory dump command that shows advanced Vulkan memory management capabilities.

The second screenshot shows a simple 3D scene that is rendered in Linux and composed with Avalonia UI (Avalonia UI buttons are rendered on top of Vulkan 3D scene).

The current plan is to provide an alpha version in September 2021.

Tags: , ,

Ab3d.PowerToys | DXEngine

New maintenance release of 3D libraries published

by abenedik 2. April 2021 16:39

I would like to inform you that new versions of Ab3d.PowerToys and Ab3d.DXEngine have been published. The main purpose of the new versions is to solve some issues from the previous version. And as always, there are also a few interesting new features.

 

The first new feature that I would like to mention is that the new version of Ab3d.PowerToys supports creating contour lines (also known as isoline). The following image shows contour lines that were created from a height map:

Contour lines (isolone) creared by Ab3d.PowerToys library

 

The contour lines can also be added as part of a 3D plot - to demonstrate that, the existing 3D plot sample was updated to show contour lines:

Plot 3D with contour lines

 

Another bigger new feature is greatly improved support for creating 3D axes. The new axes can be used by many 3D plots and graphs. To support that 2 new classes were added to the Ab3d.PowerToys library. The first is AxisWith3DLabelsVisual3D that can show one axis and shows 3D text (axis title and value labels) by using TextBlockVisual3D objects. This shows text as real 3D objects. The other new class is the AxisWithOverlayLabelsVisual3D. As the name suggest this class is using standard 2D TextBlock elements that are added to an overlay Canvas object. The following image shows AxisWith3DLabelsVisual3D with a few different axis options:

Different axes created by AxisWith3DLabelsVisual3D

 

To simplify showing multiple axes a third class - AxesBoxVisual3D - was added. It can show up to 6 axes. It also dynamically switched the visibility of the axes and orientation so that when user rotates the camera the correct axes are visible and the text is oriented in the correct direction.

So if you want to present your 3D data in some kind of a 3D plot of a 3D graph, you just got great new tools to achieve that quickly.

 

Let me quickly mention some other new features: 

  • Improved HeightMapVisual3D with a new option to use a one-dimensional texture for colors and then adjusting the texture coordinates of the mesh. This better interpolates the colors between various height map values. See updated sample for more info.
  • Added Parent property to the BaseVisual3D object. This way you can easily traverse the hierarchy of objects that derive from BaseVisual3D object - all Visual3D objects from Ab3d.PowerToys, including ContentVisual3D.
  • Improved Boolean operation that can now change only the triangles that intersect the second object.

 

But as mentioned before, most of the work was done to solve issues based on some new testing tools. A few fixes are related to using IsVisible property. The full list of changes can be seen in the Ab3d.PowerToys versions history page.

 

The Ab3d.DXEngine library did not get any bigger new features. But there were some solved issues. See the list of changes in the Ab3d.DXEngine versons history page.

Tags: , ,

DXEngine | ReaderSvg

.Net 5.0 support with some exciting new features

by abenedik 18. December 2020 13:47

Though this year was very unusual, I am happy to conclude it by providing you additional great new features in the new version of Ab3d.PowerToys and Ab3d.DXEngine. And what is more, I am also giving you a 30% discount for any source code purchase.

In the last blog post, which was written just slightly more than one month ago, I have already mentioned that the libraries were tested with .Net 5.0 but not enough for me to release an official .Net 5.0 version. Anyway, if you checked the web page or your User Account page a few days after the release, you could see that the .Net 5.0 builds were already included in the installers. 

I also wanted to update the NuGet packages, but it is not possible to change an existing version of the NuGet packages. And I also did not want to increase the version number without any change in the code. 

Therefore I have uploaded an updated version of NuGet packages (.nupkg files) to the Downloads web page. I have also decided to provide a new version in December with some additional new features and an official .Net 5.0 support. 

So, official support for .Net 5.0 is the most significant new feature. But the new version offers much much more.

The first new feature that I would like to highlight is the new InstancedTextNode class. It can be used to render millions (!!!) of characters in any font and style. It can be also used to demonstrate the immense power of modern graphics cards. See that by yourself:

Showing 8000 texts with new InstancedTextNode object in new Ab3d.DXEngine

This screenshot is showing 8000 texts with different coordinates in the format "(xxx yyy zzz)". As seen in the screenshot, 94800 characters were used in the image. Impressive, isn't it! But what will you say if this screenshot is there only to make the texts easier to read and not to demonstrate the power of the new InstancedTextNode? To see the real power see the screenshot with 1 million texts (13.2 million characters):

Showing 1 million texts with new InstancedTextNode object in new Ab3d.DXEngine

This can easily run with 60 FPS on a modern GPU. Get the latest version and check this out by yourself. It is really amazing!

Though the previous two images used only black text, it is possible to set each text's position, orientation, size, and color. And after the text is shown, it is very easy to hide, show, move, scale and change its color. The following image shows that:

Showing different text with new InstancedTextNode object in new Ab3d.DXEngine

The InstancedTextNode achieves this level of performance by using DirectX object instancing and multiple textures - one texture for each character. When adding different texts to the InstancedTextNode, the code checks which characters are used in the text and when a character that was not used in any previous text is found, it renders the new character to a new texture. Then for each character in the text, it calculates a world transformation matrix and uses it for the InstanceData. Then it uses object instancing to render all instances (all appearances in all texts) of one character in one draw call. This is done for each character. Because some parts of the character textures are transparent, the InstancedTextNode uses alpha-clipping to discard the transparent pixels. This preserves the excellent performance because it avoids sorting the individual characters by their distance to the camera.

So the InstancedTextNode can be used when you need to render a lot of text. It can also be used to render just a few characters. But in this case I would still recommend using the TextBlockVisual3D object because it provides more options and is faster for rendering just a few characters - it requires one draw call to render the whole text while the InstancedTextNode requires individual draw calls for each character.

And the TextBlockVisual3D also got a few new improvements in this version. First, its Material and BackMaterial properties preserve the DiffuseMaterial instance (before new instances can be created when the properties were changed). Because the instance is now preserved, this means that you can easily assign special DXEngine's attributes to the Material and BackMaterial properties - for example, to use alpha-clipping. In the new version you can also assign a new UseSolidColorEffect DXAttribute. When UseSolidColorEffect is set to true, the text will be rendered without any lighting calculations. This can prevent dimming the text when the text does not face the lights. There is a new ImprovedTextBlockVisual3D sample available that demonstrates that and shows the benefits of using ImprovedTextBlockVisual3D in Ab3d.DXEngine.

This version also (finally) shows how to use object id bitmap. Object id bitmap is created by rendering the objects to a bitmap by setting each object's color to a unique color that represents object id. This way it is possible to get the object id from the color of each rendered pixel. The new version demonstrates that by showing how to make a rectangular selection of objects.

Because Ab3d.DXEngine can render millions of 3D lines with different display styles (line thickness, pattern, hidden lines), it is also used in some applications to show 2D lines and 2D shapes or to create a 2D shapes editor. To provide a demonstration on how this can be achieved, the new version comes with a new TwoDimensionalCamera class and 3 new samples. The TwoDimensionalCamera creates a camera that can show a 2D scene. The objects in that scene are still standard 3D objects - there the x and y coordinates represent the position in the 2D scene; the z value is usually set to 0 (but can be changed to render some lines or objects in front of or behind other lines or objects). The TwoDimensionalCamera supports moving and zooming the camera. A simple 2D lines editor sample shows how to create a line editor with snipping to positions.

When speaking of lines, there is another new feature that I want to talk about. It improves support for rendering 3D lines that are always rendered exactly to screen pixels. The previous version of Ab3d.DXEngine introduced super-sampling support that can produce very nice smooth lines. But because line coordinates are defined as float values, the lines on the screen can be rendered between screen pixels. For example, if a 1 screen pixel thick horizontal black line is rendered on a white background and if the line falls between two screen pixels, the line will appear as 2 pixels thick gray horizontal line - the black color will be distributed between 2 pixels. When rendering multiple thin horizontal and vertical lines (for example, in a grid) this may produce some unwanted effects. This can be seen because some lines appear black and sharp (rendered exactly to the screen pixels), some are gray and twice as thick (rendered between two screen pixels) and others are in between.

It was already possible to render lines that are rendered exactly to screen pixels. This can be done by setting UseGeometryShaderFor3DLines and RenderAntialiased3DLines properties on DXScene object to false. But this setting is applied to all lines. So also angled lines will be shown without any anti-aliasing. What is more, lines rendered without geometry shader can be only 1 pixel thick. Therefore this option was rarely used. 

So each rendering option provides its benefits and its drawbacks. In the previous version it was not possible to mix them in a single scene. Now, this is possible. You can set the new UseGeometryShaderFor3DLines and RenderAntialiased3DLines DXAttributes to the selected 3D lines and specify how you want to render them. So you can render the horizontal and vertical grid lines as sharp 1 screen pixel lines and all other lines as standard smooth lines. Unfortunately, there is still a small catch - you cannot use super-sampling when using 1 pixel thick non-anti-aliased lines. The problem is that when using super-sampling, the line thickness needs to be increased by the SuperSamplingFactor so that when the super-sampling texture is down-sampled, the final line thickness is correct. But without using a geometry shader, it is impossible to increase line thickness, so when down-sampling the 1 pixel thick lines will appear 1/2 or 1/4 thinner. Anyway, you can still use multi-sampling. In the future, I plan to solve this problem by providing options to snap 3D lines to screen pixels.

And one final new feature that you may also consider important: the new version can prevent the UCEERR_RENDERTHREADFAILURE exception in WPF's render thread that can crash the whole application. That exception can sometimes occur when the primary monitor is changed. For example, when a laptop is connected to a secondary monitor with a duplicate screen option and then the laptop is closed. In this case, the secondary monitor becomes the primary monitor. It looks like there is a bug in the WPF that may crash the application. But I was able to prevent that by detecting the primary monitor's change and then recreating some of the internal objects. This seems to prevent the crash.

 

So, plenty of reasons to be excited about the new version. As always, start the new samples project and check the NEW and UP icons to see new and updated samples. For more details read the change log - here: https://www.ab4d.com/DXEngine-history.aspx and here: https://www.ab4d.com/PowerToys-history.aspx

And if you were wondering what is going on behind the scenes and wanted to peek into the Ab3d.DXEngine and Ab3d.PowerToys source code, now is the best time to purchase the source code. Just go to the purchase web page. The 30% discount is already applied to all source code items.

 

I wish you a nice and peaceful conclusion to this year. And also a few pleasant surprises (I hope this new version is one of them). And of course, happy and successful 2021!

Tags: , ,

Ab3d.PowerToys | DXEngine

Super-smooth lines with many other features in new versions of 3D libraries

by abenedik 12. November 2020 11:12

I am happy to inform you that new versions of Ab3d.DXEngine and Ab3d.PowerToys have been released.

By the new version numbers you may think that this is just a smaller update, but I am sure that the content that follows will persuade you that this is another big and great update that can significantly improve the value of your application and provide you with some great new tools for your work with 3D graphics.

Here are the highlights of the new version:

  • Added support for super-sampling provides rendering of super-smooth 3D lines and better rendering of details.
  • Added support for creating edge lines and improved support for rendering object outlines. This can render the scene in a way that is standard for CAD programs.
  • Improved support for rendering the same 3D scene with different DXViewportView (each with different camera and render settings).
  • Significantly improved the performance of the DXEngine's update step.
  • Simplified hierarchical organization of Visual3D objects with using ContentVisual3D that defines IsVisible property and now also supports showing and hiding Visual3D objects in Children collection. This also greatly improves the performance of showing and hiding Visual3D objects.
  • Improved ViewCubeCameraController - the new version supports clicking on cube edges and corners. 
  • Added custom wpf3d file format that can store WPF 3D scene. The full source code to read and write wpf3d file is available with the samples project. This way the code can be adjusted to your needs.
  • Many other improvements and fixes.

 

The following image demonstrates the first two highlights:

Super-smooth 3D lines with using super-sampling in new Ab3d.DXEngine

The first step in creating the image above was to import an aircraft engine model from a file. Then a new EdgeLinesFactory.AddEdgeLinePositions method was called. This method analyses the 3D model and creates edge lines if the angle between two adjacent triangles is bigger than the specified angle. This way it is possible to get much more accurate edge lines than by showing the wireframe of the model. The problem with showing the wireframe is that it shows lines around all triangles even if they lay on the same plane (for example, a diagonal line on cube sides). After having the edge lines, we can show the lower part of the image.

But as the upper part of the image shows, with the new version of Ab3d.DXEngine it is possible to create a superior and much more professional looking result. 

The first thing that can be done with the Ab3d.DXEngine is to set line depth bias. This moves the 3D lines towards the camera and away from the solid model so it cannot occlude the lines when they occupy the same 3D space. In the upper image, this can be seen in the lower right part of the image where the line thickness changes because the solid model occludes the lines. The new version of Ab3d.DXEngine also improves using line depth by preventing the lines from being moved away from the 3D model (when using a perspective camera). This simplifies setting the correct line depth bias.

The second feature that improves appearance in the image above is the object's outline. This renders a thicker line around 3D models. The line is also drawn on places where there are no edge lines - for example, when a curved model ends - in the image above this is just below the "objects outlines" text.

But the most significant improvement of using the new Ab3d.DXEngine is the use of super-sampling that can produce super-smooth 3D lines. In the last few months a lot of effort was put into improving the quality of 3D lines. I first tried to create smooth lines by adjusting the alpha values on pixels near the edge of the line. This slightly improved line quality. But because of using transparency on the edges, this could create artifacts if lines were not rendered in the correct order. After some other tests, it finally became apparent that using super-sampling can provide the best results. Click here to see a screenshot from a line quality testing sample.

Super-sampling (SSAA) is an anti-aliasing technique where the 3D scene is rendered to a bigger image and then down-sampled to the final image. For example, 4x SSAA means that the rendering is performed to an image that has twice the width and twice the height of the final image (has 4 times the number of pixels). The image quality can be further improved when down-sampling uses a special filter that reads samples in a slightly rotated pattern and uses different weights on the read samples. As the image above shows, this can produce highly superior results.

The difference between super-sampling and multi-sampling is that with multi-sampling, the number of pixel shader invocations is the same as with no multi-sampling. In this case, the color that the pixel shader returns is saved to multiple pixels (samples). At the end of rendering the multi-sampled texture is resolved so that all the samples are used to produce the final pixel color. This can significantly improve edge aliasing. But because there were no more pixel shader invocations, this does not produce an image with more details. For example, 4x MSAA requires 4 times the memory because each pixel shader result is shared with 4 pixels, but the number of pixel shader invocations is the same as when no multi-sampling is used. This is the main difference compared to super-sampling. There the scene is rendered to a bigger texture. This means that 4x SSAA requires four times the memory and also four times the number of pixel shader invocations. As seen in the image above, using 4x MSAA can significantly improve line quality compared to using no multi-sampling. But using 8x MSAA does not provide any more significant quality improvement. But using super-sampling can provide much better results.

Because of much higher memory usage and the number of pixel shader invocations, using super-sampling comes with high costs. This may not provide a significant difference on a high-end graphics card, but on an integrated graphics card, the slow-down may be noticeable. Though the max supported super-sampling count is 64 (rendering to 8 times width and height), the high super-sampling count should be avoided in most cases. You should also be careful because the maximum texture width and height in DirectX 11 is 16384. For example, this limit is reached on a 4k monitor when 16x SSAA is used. The Ab3d.DXEngine knows about this limitation and can dynamically reduce the super-sampling count to stay below this limit. Also, because SSAA can be combined with multi-sampling (MSAA), the recommended setting to achieve super-smooth lines is to use 4x SSAA with 4x MSAA (this was also used to produce the image above). To see the memory requirements of the various settings, open the diagnostics window that now shows the required amount of memory. The diagnostics window can be opened in the samples project by clicking on the Diagnostics button. In your application you can show the diagnostics window by using the DXEngineSnoop tool and attaching to your application (more info on Ab3d.DXEngine diagnostics web page).

Also note, that because of super-sampling, the settings for standard GraphicProfiles have changed:

  • NormalQualityHardwareRendering is the same as before - using 4x MSAA and no super-sampling.
  • HighQualityHardwareRendering is now using 4x MSAA and 4x SSAA (before 8x MSAA was used - so now twice the memory is required and 4 times the number of pixel shaders invocations).
  • UltraQualityHardwareRendering is now using 2x MSAA and 16x SSAA (before 8x MSAA was used - so four times the memory is required and 16 times the number of pixel shaders invocations).

This is important because if you are using HighQualityHardwareRendering or UltraQualityHardwareRendering you should not be surprised if the new version will be slower than the previous version. To compare the performance, use the same settings, or keep in mind that the new super-sampling requires much more work behind the scene.

To summarize, if you show 3D lines, then the superior line quality should justify the costs of super-sampling - especially using 4x SSAA with 4x MSAA. But my recommendation is that you still use it wisely. The easiest option is that your application provides a setting that can change the graphics quality. This way users on slower computers can disable or reduce the super-sampling and still enjoy in great application performance but with reduces quality. To provide a suitable default quality setting, you may check the amount of graphics card memory, display's size and monitor DPI setting (see source code of SystemInfo class for a sample on how to get GPU memory size; you can get DPI settings by a new static GetDpiScale method on DXViewportView).

 

Ok, we have covered the first two points in the highlights list. Let's move on. The most obvious way to hide some of the 3D objects is to remove them from the 3D scene. But when this is done with Ab3d.DXEngine (and if the objects are not added back to the scene in the same frame), then the DirectX resources for the removed objects are disposed and removed from the graphics card. This also means then when those objects are added back to the scene, then the DirectX resources will need to be regenerated and sent to the graphics card.

Ab3d.DXEngine tried to solve this with improved support for IsVisible property that was available with the BaseVisual3D class from Ab3d.PowerToys library. In this case when the IsVisible property was set to false, then all the DirectX resources are preserved, but the rendering of the object is skipped in the rendering loop. This means that when the IsVisible property was set back to true, the object can be shown instantly as no resources need to be created.

Because all Visual3D objects from Ab3d.PowerToys are derived from that class, they all received that improved support. With using ContentVisual3D (also derived from BaseVisual3D) it was also possible to show and hide any GeometryModel3D or Model3DGroup objects that was set to ContentVisual3D.Content property. But if you want to show or hide a hierarchy of Visual3D objects, then you still needed to remove those objects from the scene and then add them back. This was finally solved with the new version of Ab3d.PowerToys and Ab3d.DXEngine that now also fully supports showing and hiding Visual3D objects from ContentVisual3D.Children collection.

What is more, because ContentVisual3D now defines a new ChildrenChanged event, it is much easier (and requires much less CPU time) for the Ab3d.DXEngine to check the changes in the Children collection. This makes the ContentVisual3D class a much more appropriate object to hold other 3D objects than the ModelVisual3D class. To simplify the usage of ContentVisual3D, there is also a new CreateContentVisual3D extension method that can simplify creating ContentVisual3D objects from any GeometryModel3D or Model3DGroup objects.

So using ContentVisual3D with Ab3d.DXEngine can reduce the time in the update phase (in this phase the objects are checked for changes and the RenderingQueues are updated). The new version also significantly reduces update time in some other very common cases. One such case is when an object's transformation is changed. Now, this is processed much faster and in a 3D scene with many objects can provide significantly lower update times. Also, changing individual positions or triangle indices in MeshGeometry3D now takes the faster update path.

Another great new feature is improved support for having different views of the same 3D scene. Each view can have a different camera and use different rendering settings. Before, this was possible only by creating new Viewport3D objects and duplicating the Visual3D objects in each Viewport3D (the MeshGeometry3D and Model3D objects can be shared). What is more, it was not possible to use the same SceneNode objects in multiple views. With the new version of Ab3d.DXEngine it is possible to create a DXViewportView by passing a master DXViewportView as a constructor parameter. This creates a child DXViewportView that uses the same 3D scene (DXScene object) but can provide its own camera and its own rendering settings (rendering scene as wireframe, rendering just some objects of the scene, or using some special effects on some views).

The new samples projects for Ab3d.PowerToys library also comes with a new Wpf3DFile class. This class provides the full source code to read and write wpf3d files. wpf3d is a custom binary file format that can save WPF 3D scene. It can save the hierarchy of Model3D objects with their materials. It can also save model metadata with a preview bitmap. This way you can quickly read the metadata and show that to the user. The following screenshot is showing a sample with four possible wpf3d files:

Simple dialog to import wpf3d files shows some file metadata and preview bitmap

The main use case for using this file format is to convert existing files in other file formats (for example fbx) into wpf3d files. Then you can simply use the Wpf3DFile class to read the files and do not need to distribute the native Assimp library with your application anymore. You can also change the Wpf3DFile source code and store some additional data relevant to you into the file. You may also want to encrypt the data, use any other file extension (not .wpf3d), or make any other change to the file structure.

The last feature that I would like to mention is an improvement to the ViewCubeCameraController.  Because the ViewCubeCameraController provides such an intuitive way to show the orientation of the camera, it is used by many users. Therefore, you will be happy to hear that the new version of ViewCubeCameraController supports clicking on the cube's edges or corners to rotate the camera. For users this is a very nice and useful feature. And what is the best - you just need to update to the latest version of Ab3d.PowerToys and do not need to change anything in your core to provide this new feature.

As always, there are many other new features and fixes. The best way to check them is to see them in action with new samples projects that come with both libraries - start the samples and pay attention to the NEW and UP icons in the samples list on the left (the UP icon also provides a tooltip of what is changed). You can also read the full change log on Ab3d.PowerToys history and Ab3d.DXEngine history.

You can get the new versions from new NuGet packages. If you have a valid updates subscription, you can download new installers from your User Account web page. To just test the new version you can also download the new evaluation version from the Downloads page.

 

Let me conclude with some future plans. 

The .Net 5 was just released two days ago (on 10 November). I did some testing with .Net 5 RC versions and both Ab3d.PowerToys and Ab3d.DXEngine compiled and ran without any problems there. But I run out of time to thoroughly test and update the release process to provide an official .Net 5 versions of the assemblies. But this will be done in the near future. So stay tuned for news about that.

And finally, a sneak peek of a more distanced future:

Early preview of Vulkan rendering engine for .Net running on Linux

This screenshot shows v0.2 of the new Vulkan based rendering engine. The screenshot shows it can run on Linux. There is a Rider IDE in the background. See great performance figures in the window title - note that this is running on an older system with i7 3770 @ 3.4 GHz and NVIDIA 970 GTX. The new rendering engine is being written from the ground up and will use the latest .Net features and all the know-how from Ab3d.PowerToys and Ab3d.DXEngine.

It is hard to say when the first official version of the new engine will be available. Using Vulkan API and different platforms is much more challenging than using DirectX 11 and Windows. Therefore, if you would like to speed up the development, participate in the development by providing feedback and testing on other platforms or would just like to share your wishes and ideas, you are most welcome to contact me.

As always, the goal is to provide you an awesome cross-platform rendering engine for technical, scientific and CAD-like 3D visualizations.

Tags: , , , , , ,

Ab3d.PowerToys | DXEngine