EntityLODTransition entity[,width#]

Parameters

entity - entity with mesh levels registered by AddEntityLOD

width# (optional) - full transition band in world units, centred on each threshold; must be non-negative; 0 restores hard switching (default)

Description

Crossfades between a mesh's levels of detail instead of switching hard.

The non-negative width is the full transition band in world units, centred on each existing threshold. Width 0 restores hard switching with the existing 10% hysteresis. Levels added with AddEntityLOD need static, unmorphed meshes; versions made by AutoEntityLODs fade on skinned and morphed meshes too.

Versions made by AutoEntityLODs fade by default, over a band from 10% before each switch to 10% after it, because their switch distances change with the camera. Calling EntityLODTransition after AutoEntityLODs replaces that with your width, and 0 switches straight from one version to the next. Calling AutoEntityLODs again brings the default fade back.

For a threshold of 20 and width of 4, both meshes are submitted between distances 18 and 22. Their dither patterns divide the covered pixels between them. This keeps matching projected geometry fully covered; different silhouettes can still expose the mesh change. Author lower-detail meshes with similar outlines and matching materials. Both meshes cost rendering work while the transition is active.

The effective width is clamped so neighbouring transition bands never overlap and the first starts at a non-negative distance. Hysteresis remains outside each band, limited by its edges. Each LOD retains its registered brush and geometry; EntityShader and other entity material settings still apply normally. CopyEntity copies the width and LOD table; ClearEntityLODs removes the paired geometry.

Coverage is shared with supported shadows and EntityHighlight. Manual dither and distance fading multiply the pair's coverage without changing its blend mode. RenderSubmittedDraws and RenderTriangles include both submitted representations; RenderLODSelections counts the entity once. Collision and picking continue to use the base mesh. See EntityDitherFade for supported materials and the visible grain when temporal antialiasing is off.


See also: AddEntityLOD, AutoEntityLODs, ClearEntityLODs, EntityDitherFade, EntityDitherRange, RenderLODSelections.

Example

; EntityLODTransition Example
; ---------------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,1,-5
CameraRange camera,0.1,40

light=CreateLight()
RotateEntity light,35,-25,0

; A detailed prop with a low-detail replacement past 10 units
prop=CreateCylinder(32)
ScaleEntity prop,1,1.5,1
PositionEntity prop,0,1,6
EntityColor prop,60,160,190
low=CreateCylinder(8)
AddEntityLOD prop,low,10
FreeEntity low

; A 4-unit dithered crossfade band centred on the threshold
enabled=True
EntityLODTransition prop,4

While Not KeyDown(1)

    ; Space switches between crossfading and hard switching
    If KeyHit(57)
        enabled=Not enabled
        If enabled Then EntityLODTransition prop,4 Else EntityLODTransition prop,0
    EndIf

    ; Arrow keys move the camera - drive through the 8..12 unit band
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Color 255,255,255
    Text 0,0,"Arrow keys: move camera   Space: toggle transitions   Esc: exit"
    Text 0,20,"EntityLODTransition prop,4 enabled: "+enabled
    Text 0,40,"Submitted triangles: "+RenderTriangles()+"   (both meshes render inside the band)"

    Flip

Wend

End

Index