Blitz3D+ Command Reference

LightMesh mesh,red#,green#,blue#[,range#][,x#][,y#][,z#]

Parameters

mesh - mesh handle

red# - red value of light
green# - green value of light
blue# - blue value of light

range# (optional) - light range; 0 (default) applies the colour to every vertex equally

x# (optional) - light x position; 0 (default)
y# (optional) - light y position; 0 (default)
z# (optional) - light z position; 0 (default)

Description

Performs a 'fake' lighting operation on a mesh by adding to its vertex colours.

Instead of a live light that costs rendering time every frame, LightMesh bakes light into the mesh's vertex colours once. With a range and position given, vertices near x,y,z (in the mesh's local space) are brightened most, falling off with distance - a cheap way to pre-light a static scene, well suited to mood lighting that never moves. Without a range, the colour is added to every vertex equally.

You need to enable vertex colours on the mesh with EntityFX mesh,2 before the results are visible (see EntityFX).

Calls are cumulative - each LightMesh adds to the vertex colours already there. Negative colour values subtract. Note that primitives are created with vertex colours of 255,255,255 (full white), so to build lighting up from darkness first reset them to black with LightMesh mesh,-255,-255,-255.

See also: EntityFX, VertexColor, CreateLight, EntityColor.

Example

; LightMesh Example
; -----------------

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

camera=CreateCamera()
PositionEntity camera,0,2,-8

; LightMesh paints light directly into vertex colours - no real light needed
statue=CreateSphere(24)
PositionEntity statue,0,1,0

; Vertex colours must be enabled for LightMesh results to be visible
EntityFX statue,2

angle#=0

While Not KeyDown(1)

    angle=angle+1

    ; Reset the vertex colours to black, then bake fake lighting from a
    ; position that circles the statue
    LightMesh statue,-255,-255,-255
    LightMesh statue,255,200,50,8,Cos(angle)*4,3,Sin(angle)*4

    ; 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   Esc: exit"
    Text 0,20,"LightMesh statue,255,200,50,8,x,y,z  (fake light baked each frame)"

    Flip

Wend

End

Index