The new version of Ab3d.DXEngine brings three big new features:
- Added support for rendering reflections with environmental and reflection maps.
- Added support for rendering unlimited number of lights with using multi-pass rendering.
- Improved rendering instanced objects with adding support for rendering many instances of Model3DGroup objects. Simplified hit testing on instanced objects with a new GetHitInstanceIndex method.
The Ab3d.PowerToys library also got some great new features. Some of the main new features are:
- Added ModelRotatorVisual3D that allows users to rotate selected 3D model. Improved ModelMoverVisual3D so that it also works in Ab3d.DXEngine.
- Greatly reduced the initialization time when creating many instances of SphereVisual3D and BoxVisual3D objects.
- Simplified working with hierarchically organized 3D models with new model iterators.
Let’s see some more details about the new features.</p> <p>Showing reflections pushes the boundaries of what is possible to achieve with WPF 3D API even further. The above image with reflective teapot shows a fully reflective 3D model. The level of reflection can be adjusted and specified for the whole object. Or, it can be specified for each part of the model with using a reflection map. The following image shows that is action (the reflection map is shown on the right):
The handle and top of the teapot are shown with green color (specified in the teapot’s texture on the bottom image) and do not reflect the environment – those parts are almost black on the reflection map (upper image). But the rest of the teapot is fully reflective – defined by white color on the reflection map (in the bottom 1/3 of the image and on the smaller white rectangle on the right side).
To support scenarios where additional DXEngine properties need to be added to the existing WPF objects, the new version of Ab3d.DXEngine introduces a new set of extensions methods that allow adding additional attributes to WPF objects.
For example the following two lines set EnvironmantMap and ReflectionMap to an existing WPF material:
usedMaterial.SetDXAttribute(DXAttributeType.Material_EnvironmentMap, _dxCubeMap);
usedMaterial.SetDXAttribute(DXAttributeType.Material_ReflectionMap, bitmapImage);
The new version of Ab3d.DXEngine also adds support to render unlimited number of lights. Previous version supported rendering only 16 lights + ambient light. This limit is now lifted with using multi-pass rendering. This means that when there are more than 16 lights in the scene it is rendered multiple times – each time different 16 lights are used and then all the rendered scenes are combined into the final image. The following screenshot shows a sample that animates the intensity of 64 PointLights:
Multi-pass rendering is great for such scenarios. But it also has some disadvantages. If you need to use many lights, please check the additional comments in the “Many lights” sample.
I would also like to write a few words about new object instancing capabilities.
Object instancing is the ultimate performance optimization – if you show really many 3D objects and you convert your code to use object instancing than you have almost reached the peak of the performance. Some additional performance gains are still possible with tweaking the shaders, but most of the work was already done.
The trick is that when object instancing is used, the applications sends one mesh geometry to the graphics card and then tells it to render it many times – for each instance of the mesh you can specify different color and different transformation. Because the data about all the instances is send in one draw call, this can be done very quickly on the CPU. So the usual performance problem where GPU waits for the CPU to send commands is completely eliminated.
Because instancing is so great for improving performance, the new version also allows you to render many instances of Model3DGroup objects (and not only many instances of MeshGeometry3D). The following screenshot shows many instances of RobotArm model:
Another improvement with instancing is that a GetHitInstanceIndex method was added to the InstanceData class. That method can be used in hit testing to get the index of the hit instance. This way you can easily connect the hit object with the background data that are connected to the hit instance.
If you are rendering many 3D objects, I would really advice you to try to convert your code to use instancing. You will be amazed on how fast the graphics cards can become when they are not waiting for the CPU (a newer graphics card recommended).
There are still lots of other new features and fixes. Also Ab3d.PowerToys library has been greatly improved.
But I do not want to make this blog post too long.
To check new features in action, please check the new samples that come with the libraries. And for the record here are the full list of changes:
Ab3d.DXEngine v1.2:
- Added support for rendering reflections with using EnvironmentalMaps
- Added support for ReflectionMaps
- Added support for rendering more than 16 lights (+ ambient light) with using multi-pass rendering.
- Added support for Transform on InstancedMeshGeometryVisual3D
- Added InstancedModelGroupVisual3D that can render many instances of all 3D models defined in the Model3DGroup.
- Added GetHitInstanceIndex method to InstanceData to get an index of hit instance
- Fixed showing transparent objects in some cases
- Added TextureBlendState to IDiffuseTextureMaterial interface
- Fixed rendering textures from files that use different DPI settings
- Added extension methods that simplify adding additional DXEngine attributes to the existing WPF's objects (SetDXAttribute, GetDXAttributeCollection, GetDXAttribute, IsDXAttributeSet, ClearDXAttribute, GetDXAttributeOrDefault). This is currently used to specify the EnvironmentalMap and ReflectionMap.
- Prevented memory leak when 3D model that was shown inside WireframeVisual3D was changed (further performance improvements in this case will follow).
- Prevented rendering strange 3D lines that sometimes occur when the 3D lines were completely behind the camera
- Fixed rendering transparent 3D lines
- Fixed rendering transparent objects with emissive materials
- Some other smaller bug fixes and improvements
BREAKING CHANGE:
The InstancedGeometryVisual3D was renamed into InstancedMeshGeometryVisual3D – the renaming was needed because a new InstancedModelGroupVisual3D was introduced and the previous name did not describe the class well enough.
Ab3d.PowerToys v7.4:
- Added ModelRotatorVisual3D that allows user to rotate selected Model3D around any axes.
- Added SubscribeWithEventManager3D method to ModelMoverVisual3D and ModelRotatorVisual3D to allow them to use EventManager3D for processing mouse events. This allows using the ModelMoverVisual3D and ModelRotatorVisual3D in Ab3d.DXEngine.
- Greatly reduced the initialization time when creating many instances of SphereVisual3D or BoxVisual3D objects
- Added ModelIterator class and two extension methods (ForEachVisual3D and ForEachGeometryModel3D) to simplify working with hierarchacly organized 3D models.
- Added FitIntoView and GetFitIntoViewDistanceOrCameraWidth methods to TargetPositionCamera, SceneCamera, TargetRect3DCamera and ThirdPersonCamera. The method has greatly improved algorithm then it was available in the "Scene Editor" sample in the previous versions of Ab3d.PowerToys.
- Fixed showing transparent 3D lines when LineColor's alpha value is less than 255.
- Improved support for TextureCoordinates in ModelOptimizer
- Added WidthDirection and HeightDirection to WireGridVisual3D that allows to set custom direction of the WireGrid (not only horizontal or horizontal in another coordinate system)
- Added CreateWireGrid to Line3DFactory that allows creating WireGrid object with custom widthDirection and heightDirection vectors.
- Added GetTargetViewport3DSceneBounds method to all Camera classes in Ab3d.PowerToys – the method calculates the scene bounding box
- Change validation of Size property on BoxVisual3D, WireBoxVisual3D, MultiMaterialBoxVisual3D and PyramidVisual3D to allow having one component of size zero.
- Fixed calculating scene size in SceneCamera when the scene hierarchy is complex
- Added GetBounds and CombineTransform methods to Ab3d.Utilities.ModelUtils
- Added CompositionRenderingHelper to help work with CompositionTarget.Rendering (allowing subscribed objects to be recycled by Garbage Collection and therefore preventing infinite rendering subscription in case when the Rendering is not unsubscribed)
- Improved ModelMoverVisual3D so that it can also use EventManager3D for mouse event processing - this allows using ModelMoverVisual3D inside Ab3d.DXEngine.
- Prevented throwing "Object reference" exception in ModelOptimiter that could occur sometimes when ImageBrush is used.
- Added HeightDirection to TubeVisual3D and TubeMesh3D – this allows orienting the object in any direction and not only in up (0, 1, 0) direction.
- Fixed throwing exception when Is3DAxesShown is initially set to false on CameraAxisPanel
- Added "Custom Up Axis" sample that shows how to show data in another coordinate system - for example where Z is up.
- Added "Perspective Transformation" sample that shows how to convert 3D positions to the 2D positions on the screen
BREAKING CHANGE:
Moved the ModelMovedEventArgs class from Ab3d.PowerToys.Common to Ab3d.Common namespace