Click or drag to resize
Ab4d.SharpEngine logo

CameraDistanceSortedRenderingLayer Class

CameraDistanceSortedRenderingLayer is a rendering layer where the objects inside the queue are sorted by their distance from the camera. This is uses for transparent object that need to be rendered so that the objects that are farther away from the camera are rendered first. See remarks for more info.
Inheritance Hierarchy
SystemObject
  Ab4d.SharpEngine.RenderingLayersRenderingLayer
    Ab4d.SharpEngine.RenderingLayersSortedRenderingLayer
      Ab4d.SharpEngine.RenderingLayersCameraDistanceSortedRenderingLayer

Namespace: Ab4d.SharpEngine.RenderingLayers
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 1.0.8740+deb2991acfe86a95cca780cd4f82bcae2805c1a5
Syntax
C#
public class CameraDistanceSortedRenderingLayer : SortedRenderingLayer

The CameraDistanceSortedRenderingLayer type exposes the following members.

Constructors
 NameDescription
Public methodCameraDistanceSortedRenderingLayer Constructor
Top
Properties
 NameDescription
Public propertyDistantObjectsFirst Gets or sets the direction of sorting. When true the objects that are more far away from the camera are rendered first.
Public propertyFixBackFaceMaterialOrder Gets or sets a Boolean that specifies if the order of objects that render back face is manually fixed so that they are always rendered before front face materials. This is only used when DistantObjectsFirst is true. Default value is true. See remarks in this class description for more info.
Public propertySortingType Gets a RenderingLayerSortTypes that specifies when the RenderingLayer needs to be resorted.
(Overrides SortedRenderingLayerSortingType)
Top
Methods
 NameDescription
Protected methodDisposeSortRelatedData DisposeSortRelatedData disposes all data that are used to store and cache sort related data. This method is called when Disposing or when IsSortingEnabled is set to false.
(Overrides SortedRenderingLayerDisposeSortRelatedData)
Protected methodSortSortedIndexes Sort items in this rendering layer by setting the sortedIndexes array.
(Overrides SortedRenderingLayerSortSortedIndexes(RenderingContext, ICamera, Boolean))
Top
Remarks

CameraDistanceSortedRenderingLayer is a rendering layer where the objects inside the queue are sorted by their distance from the camera. This is uses for transparent object that need to be rendered so that the objects that are farther away from the camera are rendered first.

The CameraDistanceSortedRenderingLayer uses a highly optimized quick sort algorithm. This algorithm is not a stable sort algorithm. This means that objects with the same sort value can change their positions (for example if A, B and C have the same value, then sort may return them in a different order as initially defined). Because of this it may happen that when a 3D objects is rendered with its back and front face materials, then sometimes the order of those two materials can change and this can lead to some flickering when camera is changed. To fix that the CameraDistanceSortedRenderingLayer by default fixes the order so that when one object renders both back and front material, then back material is always rendered before front material (this only works when no other object has the same distance to the camera - so that there are no other objects inserted into rendering layer between back and front face material). This fix can be disabled with setting FixBackFaceMaterialOrder property to false.

With DistantObjectsFirst property it is possible to change the sorting order. By default this property is set to true so that distant objects are rendered first. This is used for rendering transparent objects. But if you have a few big objects that occlude most of the scene, then you may want to set this property to false. This will render the closest objects first and therefore occlude other objects - improving performance with early rejecting of triangles because of depth testing.

To provide custom sort order, you can subscribe to SortingCompleted event and in the event handler change the order of RenderingItem objects by changing the indexes in the provided SortedIndexes array.

See Also