Light Color blowing out on meshes

BlitzMax Modules Forums/MiniB3D/Light Color blowing out on meshes

Hi there,

again sorry if this topic rather belongs into the B3D forums but since i'm new to miniB3D aswell as B3D i have a hard time sparating issues that work as intended from possible oddities in MiniB3D as it is in development.

So currently i am wondering why a mesh that is lit by a point-light with color(255,0,0) blows out to complete white on the light-facing triangles, uses the light color to fade to black on the backside.
In my opinion the lightcolor should be reflected by the mesh. This likely has to do with the material being used on the mesh, too. I disabled specular and tried lowering the color values for the light but neither worked.
As a last resort i changed the entitycolor of the mesh to the same level as the light wich works visually but in my opinion should not be nescessary.

Here an example(hope it shows):



So could somebody fill me in regarding this issue please? How do i work correctly with lights and materials in (mini)B3D?

If you can post the source code then I can try it in Blitz3D to compare.

Hi Simon,

sure thing and thanks for checking.

Strict

Import "../MiniB3D.bmx"
Type TSun
Field PIVOT:TPivot
Field MESH:TMesh
Field LIGHT:TLight

Function Create:TSun()
	Local tmp:TSun = New TSun
	tmp.PIVOT = CreatePivot()
	tmp.MESH = CreateSphere(8,tmp.PIVOT)
	tmp.LIGHT = CreateLight(2,tmp.PIVOT)
	tmp.LIGHT.LightColor(230,20,20)	
	Return tmp
End Function
End Type

Local width=640,height=480,depth=16,mode=0

Graphics3D width,height,depth,mode

HideMouse()
AmbientLight(50,50,50)

Local cam:TCamera=CreateCamera()
cam.PositionEntity(0,0,-10)
cam.CameraZoom(2)

Local tex:TTexture=LoadTexture("media/test.png",1)
Local tex2:TTexture=LoadTexture("media/sand.bmp",1)

Local Sun:TSun = TSun.Create()
sun.MESH.EntityTexture(tex)
sun.MESH.EntityFX(1)
Sun.MESH.ScaleEntity(3,3,3)
Sun.PIVOT.PositionEntity(0,0,20)

Local spherearray:TMesh[5]
For Local i% = 0 Until 5
	spherearray[i] = CreateSphere(16)
	Local vx:Float,vy:Float,vz:Float
	Local pos:Float = Rand(0.0,360.0)
	vx = 0 + 10 * Cos(pos)
	vy = 0 
	vz = 20 + 10 * Sin(pos)
	spherearray[i].PositionEntity(vx,vy,vz)
	spherearray[i].EntityTexture(tex2)
	'spherearray[i].EntityColor(230,20,20)
Next

Local spherearray2:TMesh[5]
For Local i% = 0 Until 5
	spherearray2[i] = CreateSphere()
	spherearray2[i].PositionEntity(2.5*i,0,-20)
Next
' used by camera code
Local mxs#=0
Local mys#=0
Local move#=0.5
MouseXSpeed() ' flush
MouseYSpeed() ' flush

' used by fps code
Local old_ms=MilliSecs()
Local renders
Local fps

While Not KeyDown(KEY_ESCAPE)		

	If KeyHit(KEY_ENTER) Then DebugStop

	'' control camera
	
	' mouse look
	
	mxs#=mxs#+(MouseXSpeed()/5.0)
	mys#=mys#+(MouseYSpeed()/5.0)

	RotateEntity cam,mys#,-mxs#,0

	MoveMouse width/2,height/2
	MouseXSpeed() ' flush
	MouseYSpeed() ' flush

	' move camera forwards/backwards/left/right with cursor keys
	
	If KeyDown(KEY_W)=True Then MoveEntity cam,0,0,move# ' move camera forward
	If KeyDown(KEY_S)=True Then MoveEntity cam,0,0,-move# ' move camera back

	If KeyDown(KEY_A)=True Then MoveEntity cam,-move#,0,0 ' move camera left
	If KeyDown(KEY_D)=True Then MoveEntity cam,move#,0,0 ' move camera right
	
	''
	
	'TurnEntity cube,0,1,0

	RenderWorld
	renders=renders+1

	' calculate fps
	If MilliSecs()-old_ms>=1000
		old_ms=MilliSecs()
		fps=renders
		renders=0
	EndIf
	
	Text 0,0,"FPS: "+String(fps)
	Text 0,20,"Light: " +Sun.LIGHT.EntityX(True)+", "+Sun.LIGHT.EntityY(True)+", "+Sun.LIGHT.EntityZ(True)
	Text 0,40,"Mesh : "+Sun.MESH.EntityX(True)+ ", "+Sun.MESH.EntityY(True)+ ", "+Sun.MESH.EntityZ(True)
	Text 0,60,"Pivot: "+Sun.PIVOT.EntityX(True)+", "+Sun.PIVOT.EntityY(True)+", "+Sun.PIVOT.EntityZ(True)	

	Flip

Wend
End


Yeah, it does the same in B3D. Use LightRange with a range value of 10 to get the desired effect.

Thanks Simon,

that works .. kind of.
If i wanted objects to be evenly lit whether they are 10 units away from the light source or 1000 units this would not work.
Think space simulation.. this light type might not be ideal but the only other that might be usable is the parallel light(1). which gives even illumination near and far but ... it is directional and thus not applicable for simulating a sun shining on its various sattelites.
Are there tricks to simulate such lighting conditions? The EntityColor-workaround might help but i'm not entirely happy with this solution unless a knowledgeable Blitzer can confirm this.

Thanks for your time!

Not sure if this has any relevance to the issue, but I'd suggest doing an UpdateNormals on the sphere after creating it (assuming minib3d supports that command).