EntityLightmap entity[,mode][,detail#][,recursive]

Parameters

entity - mesh or terrain handle

mode (optional) - how it takes part in bakes:
LIGHTMAP_AUTO (-1): decided for it (default)
LIGHTMAP_OFF (0): it moves: left out of bakes, lit by light probes
LIGHTMAP_ON (1): it is static: baked into lightmaps, casting baked shadows and bouncing light
LIGHTMAP_CONTRIBUTE (2): it is static and small: casts baked shadows and bounces light, but light probes light it

detail# (optional) - scales its lightmap's texels: 2 is twice as sharp, 0.5 half; 1 (default)

recursive (optional) - True to set its children too; False (default)

Description

Sets how an entity takes part in baked lighting.

Automatic bakes static meshes and terrains, and leaves out, for the probes to light, anything animated, with collisions or a dynamic or kinematic body, invisible, or under a parent that moves; it leaves out skies, and anything else drawn behind or over everything with EntityOrder, altogether; small objects, fullbright ones and ones with levels of detail are lit by probes while still casting baked shadows. A fullbright or emissive one also lights the bake with its glow, which EntityBakeEmission dims or keeps out. EntityLightmapMode and EntityLightmapReason$ say what it decided and why.

Automatic cannot see your game's rules, so set anything a player can pick up, push or knock over to LIGHTMAP_OFF: a baked shadow is part of the texture under it, and would stay behind when the object moved. The same goes for objects you switch between static and moving physics, and for things drawn through merged meshes.

See also: EntityLightmapMode, EntityLightmapReason, EntityLightProbes, EntityBakeEmission, BakeLighting, LightBakeView.

Example

; EntityLightmap Example
; ----------------------

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

camera=CreateCamera()
PositionEntity camera,0,2.5,-5
RotateEntity camera,20,0,0

AmbientLight 10,10,16

; The floor and a red wall are static scenery: they bake into lightmaps
ground=CreateCube()
ScaleEntity ground,3,0.1,3
wall=CreateCube()
ScaleEntity wall,0.1,1.5,3
PositionEntity wall,-2.5,1.5,0
EntityColor wall,230,40,30

; A crate the player can push must not be baked, or its shadow would stay
; behind when it moves: light probes light it instead
crate=CreateCube()
ScaleEntity crate,0.4,0.4,0.4
PositionEntity crate,0,0.5,0
EntityColor crate,200,170,120
EntityLightmap crate,LIGHTMAP_OFF

; A small bolt on the wall casts baked shadows but probes light it
bolt=CreateSphere(8)
ScaleEntity bolt,0.08,0.08,0.08
PositionEntity bolt,-2.35,1.5,-1
EntityLightmap bolt,LIGHTMAP_CONTRIBUTE

; A warm lamp, fully baked, so the crate takes its light from the probes
lamp=CreateLight(2)
PositionEntity lamp,0.5,2.5,0
LightRange lamp,3
LightColor lamp,255,220,170
LightBakeMode lamp,LIGHT_BAKED

; Probes a unit apart through the room, and closer together over the floor,
; where the crate goes
LightProbeSpacing 1
LightProbeVolume 0,0.75,0,6,1.5,6

LightBakeQuality 0
bake=BakeLighting()
While LightBakeState(bake)=LIGHT_BAKE_RUNNING
    RenderWorld
    Text 0,0,"Baking: "+(LightBakeProgress(bake)/10)+"%"
    Flip
Wend
FreeLightBake bake

probes=True

While Not KeyDown(1)

    ; The crate slides to and fro; near the red wall its probes turn it red
    PositionEntity crate,Sin(MilliSecs()/20.0)*1.8,0.5,0

    ; Space switches the crate's probe lighting off and on
    If KeyHit(57) Then
        probes=Not probes
        EntityLightProbes crate,probes
    EndIf

    ; Arrow keys move the camera
    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

    Text 0,0,"Arrow keys: move camera   Space: crate's probes on/off   Esc: exit"
    Text 0,20,"Wall: mode "+EntityLightmapMode(wall)+" because "+EntityLightmapReason(wall)
    Text 0,40,"Crate: mode "+EntityLightmapMode(crate)+" because "+EntityLightmapReason(crate)
    Text 0,60,"Bolt: mode "+EntityLightmapMode(bolt)+" because "+EntityLightmapReason(bolt)
    Text 0,80,"EntityLightProbes crate,"+probes

    Flip

Wend

End

Index