ShadowLightLimit [count]

Parameters

count (optional) - how many lights may cast shadows at once, from 1 to 8; 1 (default)

Description

Sets how many lights in the current world may cast shadows at the same time.

By default only one light casts shadows - usually the sun. Raise the limit for scenes with several: two stage lamps throwing crossed shadows, a torch beside a campfire, a car's headlights. Each light's shadow takes away only that light, so where one lamp is blocked, the other still lights the floor, as in real life.

The candidates are the first eight lights, picked by LightShadows priority, then directional lights first, then the order the lights were made. Point lights cast shadows only at ShadowQuality 2 or 3. All the shadow maps share a 512 MB budget: a light that does not fit tries smaller maps, down to 1024 pixels, and one that still does not fit lights the scene without a shadow. DrawRenderStats with flag 8 and CaptureFrame report the shadows actually drawn.

More than one shadow light needs Direct3D 12, Metal or WebGPU. The limit stays when ShadowQuality or Shadows change. To turn shadows off, use Shadows False: 0 is not a valid limit, and a count outside 1 to 8 is a runtime error that leaves the limit as it was.

Extended mode always lights the default material per pixel, so the limit does not change how the scene is lit. Custom shaders receive the first shadow; a format-3, layout-4 shader can declare multi-light-shadows 1 and use blitz3d_multi_light_shadows.hlsli to sample them all.

See it working in the Multi_Light_Shadows.bb sample.


See also: Shadows, LightShadows, ShadowQuality, EntityShadows, ShadowColor.

Example

; ShadowLightLimit Example
; ------------------------

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

camera=CreateCamera()
PositionEntity camera,0,5,-6
RotateEntity camera,35,0,0

AmbientLight 20,20,25

; A stage floor that receives shadows, and a crate standing on it
stage=CreateCube()
ScaleEntity stage,8,0.1,8
PositionEntity stage,0,-0.1,5
EntityShadows stage,False,True
crate=CreateCube()
PositionEntity crate,0,1,4

; Two coloured stage lamps aimed at the crate, the warm one first in line
focus=CreatePivot()
PositionEntity focus,0,0,4
warm_lamp=CreateLight(3)
PositionEntity warm_lamp,-4,5,-2
PointEntity warm_lamp,focus
LightColor warm_lamp,240,100,40
LightRange warm_lamp,25
LightConeAngles warm_lamp,40,100
LightShadows warm_lamp,1,10
cool_lamp=CreateLight(3)
PositionEntity cool_lamp,4,5,-2
PointEntity cool_lamp,focus
LightColor cool_lamp,40,120,240
LightRange cool_lamp,25
LightConeAngles cool_lamp,40,100
LightShadows cool_lamp,1,0

; Turn on the automatic shadow system, with solid black shadows
Shadows 1
ShadowQuality 2
ShadowColor 0,0,0,1

limit=2

While Not KeyDown(1)

    ; Press 1 or 2 to choose how many lights may cast shadows at once
    If KeyHit(2) Then limit=1
    If KeyHit(3) Then limit=2
    ShadowLightLimit limit

    TurnEntity crate,0,0.5,0

    ; 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,"1 / 2: shadow light limit   Arrow keys: move camera   Esc: exit"
    Text 0,20,"ShadowLightLimit "+limit
    If limit=1 Then
        Text 0,40,"Only the warm lamp (priority 10) casts a shadow"
    Else
        Text 0,40,"Each lamp casts its own shadow"
    EndIf

    Flip

Wend

End

Index