Where is the light gone ?

Blitz3D Forums/Blitz3D Beginners Area/Where is the light gone ?

If i use createcube(), the cube will be affected by light/lightrange.
But if i create my own cubemesh nothing happens.
I tried different flags for LoadBrush, BrushFx etc but nothing seems to work.

Here is an example.
Simply change file$ to any texturefile and change
the 'if 1=1' to 'if 1=0' to see the differences to createcube().
Use the spacebar then to change the lightrange.
Any Idea ?


Graphics3D 640,480

camera = CreateCamera()
MoveEntity camera,0,0,-5

;ChangeDir "F:\programming\Blitz3D\samples\"
Global file$="gfx/1.jpg"

;CHANGE to 1=1 to use cubebox !
If 1=1 then
ball = Create_cubebox() ;no light here !?
Else
ball = CreateCube() ;light ok
brush = LoadBrush(file$,flag)
PaintEntity ball,brush
EndIf

lite = CreateLight(3)
MoveEntity lite,5,0,-5
PointEntity lite,ball

range# = 0.5
LightRange lite,range

While Not KeyDown(1)
TurnEntity ball,0.4,0.4,0.0
RenderWorld:Flip
If KeyHit(57) Then ; hit SPACEBAR to increase light range
range = range + 0.5
LightRange lite,range
EndIf
Wend

End




Function create_cubebox()
mesh = CreateMesh()

flag = 49

;front face
brush = LoadBrush(file$,flag,1,1)
BrushFX brush,2
BrushShininess brush,0.5

surface = CreateSurface(mesh,brush)

AddVertex surface,-1,+1,-1,0,0
AddVertex surface,+1,+1,-1,1,0
AddVertex surface,+1,-1,-1,1,1
AddVertex surface,-1,-1,-1,0,1
AddTriangle surface,0,1,2
AddTriangle surface,0,2,3
FreeBrush brush

;right face
brush = LoadBrush(file$,flag)

surface = CreateSurface(mesh,brush)
AddVertex surface,+1,+1,-1,0,0
AddVertex surface,+1,+1,+1,1,0
AddVertex surface,+1,-1,+1,1,1
AddVertex surface,+1,-1,-1,0,1
AddTriangle surface,0,1,2
AddTriangle surface,0,2,3
FreeBrush brush

;back face
brush = LoadBrush(file$,flag)

surface = CreateSurface(mesh,brush)
AddVertex surface,+1,+1,+1,0,0
AddVertex surface,-1,+1,+1,1,0
AddVertex surface,-1,-1,+1,1,1
AddVertex surface,+1,-1,+1,0,1
AddTriangle surface,0,1,2
AddTriangle surface,0,2,3
FreeBrush brush

;left face
brush = LoadBrush(file$,flag)
surface = CreateSurface(mesh,brush)
AddVertex surface,-1,+1,+1,0,0
AddVertex surface,-1,+1,-1,1,0
AddVertex surface,-1,-1,-1,1,1
AddVertex surface,-1,-1,+1,0,1
AddTriangle surface,0,1,2
AddTriangle surface,0,2,3
FreeBrush brush


;top face
brush = LoadBrush(file$,flag)
surface = CreateSurface(mesh,brush)
AddVertex surface,-1,+1,+1,0,1
AddVertex surface,+1,+1,+1,0,0
AddVertex surface,+1,+1,-1,1,0
AddVertex surface,-1,+1,-1,1,1
AddTriangle surface,0,1,2
AddTriangle surface,0,2,3
FreeBrush brush

;bottom face
brush = LoadBrush(file$,flag)
surface = CreateSurface(mesh,brush)
AddVertex surface,-1,-1,-1,1,0
AddVertex surface,+1,-1,-1,1,1
AddVertex surface,+1,-1,+1,0,1
AddVertex surface,-1,-1,+1,0,0
AddTriangle surface,0,1,2
AddTriangle surface,0,2,3

FreeBrush brush

Return mesh

End Function

You haven't given your cube any normals by using the VertexNormal command. Without normals, the cube can't be lit properly.

UpdateNormals or sswift's Calculate_Normals will set all the normals to respectable defaults for you.

Don't think updatenormals will work on a cube as it'll smooth the normals.

Updatenormals did it !
Thanks a lot !!!

As I said, UpdateNormals doesn't work properly on cubes. Put a rotating Blitz cube next to yours and you'll see the difference.