fake lights

Blitz3D Forums/Blitz3D Beginners Area/fake lights

Aussie(Posted 2008) [#1]
Gday everyone

I found a pice of code a while ago somewhere in this forum about fake lighting & i can't remember who posted it. I have been playing around with it & am trying to write a fake lighting include file.

so far i have managed to write a function that sets a fake ambient lighting effect to a mesh.

copy this & save as fakelight_include1
Type fklitentity
	Field entity
	Field fx
	Field ambientr
	Field ambientg
	Field ambientb
End Type

Type fklight
	Field entity
	Field light
	Field red
	Field green
	Field blue
	Field range
	Field x
	Field y
	Field z
End Type
	
	

Function fklitentity(entity,ambientr,ambientg,ambientb)
	p.fklitentity=New fklitentity
	p\entity=entity
	LightMesh p\entity,-255,-255,-255
	p\ambientr=ambientr
	p\ambientg=ambientg
	p\ambientb=ambientb
	LightMesh p\entity,p\ambientr,p\ambientg,p\ambientb
End Function


Graphics3D 640,480,16,2
 
Include "fakelight_include1.bb"

light=CreateSphere()
	ScaleEntity light,.1,.1,.1
	PositionEntity light,-4,-4,-4
	EntityColor light,0,255,0

light1=CreateSphere()
	ScaleEntity light1,.1,.1,.1
	PositionEntity light1,4,-4,-4
	EntityColor light1,255,0,0
	
cube=CreateCube()
	PositionEntity cube,0,0,0
	EntityFX cube,3

cone=CreateCone(20)
	PositionEntity cone,-5,0,0
	EntityFX cone,3
	
cyl=CreateCylinder(20)
	PositionEntity cyl,5,0,0
	EntityFX cyl,3

piv=CreatePivot()
	PositionEntity piv,EntityX(cube),EntityY(cube),EntityZ(cube)
	
light2=CreateSphere(10,piv)
	ScaleEntity light2,.1,.1,.1
	PositionEntity light2,0,7,0
	EntityColor light2,0,0,255

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


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

While Not KeyDown(1)

PointEntity camera,cube


	 
TurnEntity piv,1,0,0

TurnEntity cube,0,.5,.5

TurnEntity cone,-.5,.5,0

TurnEntity cyl,-.5,-.5,0


;;;;;;;;;;;;;;;;;Sets the ambient light level of objects;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

fklitentity(cube,10,10,10)

fklitentity(cone,10,10,10)

fklitentity(cyl,10,10,10)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


 
TFormPoint 0,0,0,light,cube
LightMesh cube,0,255,0,10,TFormedX(),TFormedY(),TFormedZ()
TFormPoint 0,0,0,light,cone
LightMesh cone,0,255,0,10,TFormedX(),TFormedY(),TFormedZ()
TFormPoint 0,0,0,light1,cube
LightMesh cube,255,0,0,10,TFormedX(),TFormedY(),TFormedZ()
TFormPoint 0,0,0,light2,cube
LightMesh cube,0,0,255,10,TFormedX(),TFormedY(),TFormedZ()
TFormPoint 0,0,0,light2,cone
LightMesh cone,0,0,255,10,TFormedX(),TFormedY(),TFormedZ()
TFormPoint 0,0,0,light1,cyl
LightMesh cyl,255,0,0,10,TFormedX(),TFormedY(),TFormedZ()
TFormPoint 0,0,0,light2,cyl
LightMesh cyl,0,0,255,10,TFormedX(),TFormedY(),TFormedZ()






UpdateWorld

RenderWorld
 
Flip 
Wend 
End



What i would like to know is. Is there a way i could write a function so if i had 100 diferent objects in a scene i wouldn't have to code the ( TFormPoint & LightMesh ) a billion times?
I have had a try & havn't had much luck. Any help would be much appreciated.


Stevie G(Posted 2008) [#2]
You could parent the entities which recieve light from light1 to a pivot called LIGHTpivot1 and then iterated through the children of the lightpivot to get the entities associated. e.g.

[CODE]
for c = 1 to countchildren( LIGHTpivot1 )
child = getchild( LIGHTpivot1, c )
tformpoint 0,0,0,light1, child
lightmesh child, 0,255,0,10, tformedx(), tformedy(), tformedz()
next

for c = 1 to countchildren( LIGHTpivot2 )
child = getchild( LIGHTpivot2, c )
tformpoint 0,0,0,light2, child
lightmesh child, 0,0,255,10,tformedx(), tformedy(), tformedz()
next
[/CODE]


Aussie(Posted 2008) [#3]
thanks. I have just tryed it but when i want multiple lights on an entity i start having problems. I dont think it likes having multiple parents.


Matty(Posted 2008) [#4]
An entity cannot have more than one parent, although it can have many children.


Aussie(Posted 2008) [#5]
yeah i thought as much. Thanks matty


Aussie(Posted 2008) [#6]
Ok i have come up with this function but need some help


Function fklight(entity,x,y,z,red,green,blue,range)
	fklight=CreateSphere()
	ScaleEntity fklight,.5,.5,.5
	HideEntity fklight
	e.fklight=New fklight
	e\light=CopyEntity (fklight)
	e\x=x
	e\y=y
	e\z=z
	PositionEntity e\light,e\x,e\y,e\z
	e\red=red
	e\green=green
	e\blue=blue
	e\range=range
	e\entity=fklitentity
	For p.fklitentity= Each fklitentity
	TFormPoint 0,0,0,e\light,fklitentity
	LightMesh e\entity,e\red,e\green,e\blue,e\range,TFormedX(),TFormedY(),TFormedZ()
	Next
End Function



I have got this code to position a sphere where i want the light source to be as long as i have the function called before i use my (fklitentity) function. But the problem is that as soon as the scene is loaded is says. "entity dose not exist" & highlights this line

LightMesh e\entity,e\red,e\green,e\blue,e\range,TFormedX(),TFormedY(),TFormedZ()


Any sugestions?


GIB3D(Posted 2008) [#7]
For p.fklitentity= Each fklitentity


shouldn't that be

For p.fklit = Each fklit

?


Aussie(Posted 2008) [#8]
I am trying to call on the entities that have a fake ambient applied to it from the first function.
Type fklitentity
	Field entity
	Field fx
	Field ambientr
	Field ambientg
	Field ambientb
End Type

Type fklight
	Field entity
	Field light
	Field red
	Field green
	Field blue
	Field range
	Field x
	Field y
	Field z
End Type
	
	

Function fklitentity(entity,ambientr,ambientg,ambientb)
	p.fklitentity=New fklitentity
	p\entity=entity
	LightMesh p\entity,-255,-255,-255
	p\ambientr=ambientr
	p\ambientg=ambientg
	p\ambientb=ambientb
	LightMesh p\entity,p\ambientr,p\ambientg,p\ambientb
End Function


i dont know if this is the right way to go about it.