'Lightmesh's' fake light coordinates are local to the mesh.
I re-remembered this today when playing about with vertex lighting.
This is BRL's Blitz3D example for the 'LightMesh' command:
Graphics3D 640,480 ,16,2
camera=CreateCamera()
ent=CreateSphere()
EntityFX ent,2 ; enable vertex colors
LightMesh ent,-255,-255,-255 ; reset vertex colors from 255,255,255 (default) to 0,0,0
LightMesh ent,255,255,0,50,-20,20,-20 ; apply fake lighting
MoveEntity camera,0,2,-10
PointEntity camera,ent
While Not KeyDown(1)
TurnEntity ent,0,0,.5
RenderWorld
Flip
Wend
End I have added the line: TurnEntity ent,0,0,.5 to demonstrate the situation.
As you can see, the sphere is lit in the same place regardless of the rotation of the sphere. This is due to the fake light coordinates of 'LightMesh' being local to the mesh - you cannot override this with an alternative use of the 'LightMesh' command - there are no switches.
Change ent=CreateSphere() to ent=CreateSphere(32) to see a much nicer visual effect - no need to do this for the light sphere.
Many people will already be aware of fixing this and also wonder why I have posted this. However, for a noob, this info might just save a lot of frustration.
EDIT: Almost forgot - edit out the LightMesh ent,-255,-255,-255 in the main loop to see an interesting effect - this may come in handy for certain things.
New code: |
Graphics3D 640,480,16,2
camera=CreateCamera()
light=CreateSphere()
ScaleEntity light,.1,.1,.1
PositionEntity light,-4,-4,-4; I've used these coords to keep the light in view for this example
ent=CreateSphere()
EntityFX ent,2 ; enable vertex colors
LightMesh ent,-255,-255,-255 ; reset vertex colors from 255,255,255 (default) to 0,0,0
LightMesh ent,255,255,0,50,-4,-4,-4 ; apply fake lighting - I've changed the X,Y,Z to reflect the 'visual' position of the light entity
MoveEntity camera,0,2,-10
PointEntity camera,ent
While Not KeyDown(1)
TurnEntity ent,0,0,.5
LightMesh ent,-255,-255,-255 ; reset vertex colors from 255,255,255 (default) to 0,0,0
TFormPoint 0,0,0,light,ent ; bypass the limits of LightMesh's fake light coordinates
LightMesh ent,255,255,0,50,TFormedX(),TFormedY(),TFormedZ(); re-apply fake lighting
RenderWorld
Flip
Wend
End |