Arrgh! Why won't my surfaces light correctly?

Blitz3D Forums/Blitz3D Programming/Arrgh! Why won't my surfaces light correctly?

Captain Laser(Posted 2004) [#1]
I need help! Can someone please tell me where I'm going wrong here?

I'm manually creating surfaces and they seem to be fine, except that I can't get Blitz to understand that I want them to be affected by lights in the scene! I can only see them if I set the AmbientLight values quite high, or if I use EntityFX to turn full-bright on.

If I replace the MakeFace call with CreateCube(), then scale the cube to the required size and texture it, it works okay.

So what am I missing?

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

camera = CreateCamera()
PositionEntity camera, 0, 0, -10

light=CreateLight()
RotateEntity light, 75, 0, 0

Global tex = LoadTexture("texture.bmp")
b = MakeFace(4, 5)

While Not KeyHit(1)
TurnEntity b, .5, 0, 1
UpdateWorld
RenderWorld
Flip
Wend
End

Function MakeFace(h#, w#)
mesh = CreateMesh()
brush = CreateBrush()
BrushTexture brush, tex

surf = CreateSurface(mesh, brush)
v0 = AddVertex (surf, -w, h, 0, 0, 0 )
v1 = AddVertex (surf, -w, -h, 0, 0, 1 )
v2 = AddVertex (surf, w, -h, 0, 1, 1 )
v3 = AddVertex (surf, w, h, 0, 1, 0 )

tri = AddTriangle (surf, v0, v3, v2)
tri = AddTriangle (surf, v0, v2, v1)

Return mesh
End Function; MakeFace

;---------


big10p(Posted 2004) [#2]
You've forgotten to set the vertex normals when building the mesh. Use the VertexNormal() command to set them manually.

I don't think you'll be able to simply use UpdateNormals as it will probably smooth the normals at the edge of the mesh.

[edit] Actually, using UpdateNormals should be fine.


jfk EO-11110(Posted 2004) [#3]
use UpdateNOrmals(mesh) before you return


Captain Laser(Posted 2004) [#4]
Ahhh! Normals! Thank you, guys! I KNEW there was something rather simple; turned out the rather simple thing was me!

I used UpdateNormals(mesh) and it does the job perfectly; though for the future I will bear in mind big10p's note about it smoothing the normals at the edge.

When I am Emperor of All Earth (any day now), you will both be on the "Good" list!

-- Mike (AKA Captain Laser)