Blitz3D+ Command Reference

AmbientLight red#,green#,blue#

Parameters

red# - red ambient light value, in the range 0-255
green# - green ambient light value, in the range 0-255
blue# - blue ambient light value, in the range 0-255

The default ambient light colour is 127,127,127.

Description

Sets the ambient lighting colour.

Ambient light is a light source that affects all points on a 3D object equally. With ambient light alone, all 3D objects appear flat, with no shading - so ambient light is used to set a base light level, and lights created with CreateLight are added on top to give shape and shading.

Think of it as the mood control: a dark dungeon might use 40,40,40, a bright cartoon world 200,200,200, and a moonlit scene a bluish 60,60,90. An ambient level of 0,0,0 gives no ambient light at all, so anything a light doesn't reach renders black - dramatic, but easy to lose the player in.

The setting applies to the whole world, not per light or per entity. Entities with the fullbright EntityFX flag ignore lighting, ambient included.

See also: CreateLight, LightColor, EntityFX.

Example

; AmbientLight Example
; --------------------

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

camera=CreateCamera()
PositionEntity camera,0,1,-6

; A directional light from the upper left - ambient light fills in its shadows
light=CreateLight()
RotateEntity light,45,45,0

; A sphere and a spinning cube: their unlit sides show the ambient level
sphere=CreateSphere(32)
PositionEntity sphere,-1.5,1,0

cube=CreateCube()
PositionEntity cube,1.5,1,0

level=127

While Not KeyDown(1)

    ; [ / ] lower or raise the ambient light level
    If KeyDown(26) And level>0 Then level=level-1
    If KeyDown(27) And level<255 Then level=level+1

    ; The same value for red, green and blue gives a grey ambient light
    AmbientLight level,level,level

    TurnEntity cube,0,1,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,"[ / ] : ambient level   Arrow keys: move camera   Esc: exit"
    Text 0,20,"AmbientLight "+level+","+level+","+level+" - watch the shaded sides"

    Flip

Wend

End

Index