blog games developers documentation portfolio gallery

More in this category:

LODSwitcher

Easy to use component that will automatically switch LOD levels based on occupied screen space.

The LODSwitcher computes the size of the object and the screenspace it will occupy at startup. So when either the screen size, camera perspective angle, or the object size changes, you should call a ComputeDimensions().

Properties


Mesh[] lodMeshes
An array of meshes to switch between. The first mesh in the array will be used for LOD 0, the last mesh for LOD x.

GameObject[] lodGameObjects
Alternative for lodMeshes. An array of gameObject to enable/disable for valrious LOD levels. The first GameObject in the array is used for LOD 0, the last GameObject for LOD x.

float[] lodScreenSizes
Array of relative screen sizes that are used to switch between LOD levels. The length of this array should always be lodMeshes.Length - 1 or lodGameObject.Length - 1. The first value defines when to switch between LOD0 and LOD 1, the second between LOD 1 and LOD 2, etc.
The relative screen size is computed by dividing the max size of any of the objects bounds (can be x, y or z) by the Screen.width. A value of 0.6 means the LOD Switcher will switch when the objects height, width or depth becomes larger (or smaller) than 0.6 * Screen.width. This is regardless of the viewing angle, so when you have a horizontal pole with width 0.1 meter, height 0.1 meter and depth/length 10 meter, the LOD Switcher will act as if the long side was entirely visible.

float deactivateAtDistance
When you want to deactivate the rendering of the mesh entire beyond a certain distance to the camera, use this property to set this distance. A value of 0 will always render the mesh.


Public functions


void ComputeDimensions()
Computes the object's bounds and measures the number of pixels it takes do display an object of 1 meter at 1 meter distance from the camera. These values are used to determine the relative screen size of the object.

void SetFixedLODLevel(int aLevel)
If you want to switch to a cspecific LOD level at runtime you can call this function. When in editor mode, you can simple set the Lod level property in the inspector. The LODSwitcher will stop computing LOD levels when a fixed LOD level is set.

void ReleaseFixedLODLevel()
Clears the fixed LOD level and makes the LODSwitcher compute LOD levels automatically again

int GetLODLevel()
Returns the current LOD level

public int MaxLODLevel()
Returns the maximum LOD level available

public void SetMesh(Mesh aMesh, int aLevel)
Set the mesh for a specific LOD level at runtime

public void SetRelativeScreenSize(float aValue, int aLevel)
Set the relative screen size at which an LOD level should be activated at runtime









follow us