Camera |
public class CameraDistanceSortedRenderingLayer : SortedRenderingLayer
The CameraDistanceSortedRenderingLayer type exposes the following members.
Name | Description | |
---|---|---|
CameraDistanceSortedRenderingLayer | Constructor |
Name | Description | |
---|---|---|
DistantObjectsFirst | Gets or sets the direction of sorting. When true the objects that are more far away from the camera are rendered first. | |
FixBackFaceMaterialOrder | 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. | |
SortingType |
Gets a RenderingLayerSortTypes that specifies when the RenderingLayer needs to be resorted.
(Overrides SortedRenderingLayerSortingType) |
Name | Description | |
---|---|---|
DisposeSortRelatedData |
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) | |
SortSortedIndexes |
Sort items in this rendering layer by setting the sortedIndexes array.
(Overrides SortedRenderingLayerSortSortedIndexes(RenderingContext, ICamera, Boolean)) |
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.