Of course, here you have the WHOLE light adding and light rendering code from my engine.
//LIGHT MAPPER
//ADD LIGHTS
If File Exist("addlight") = 1
Open To Read 22, "addlight"
If File Open(22) = 1
Read String 22, lightrange$
Read String 22, lightcolorr$
Read String 22, lightcolorg$
Read String 22, lightcolorb$
EndIf
Close File 22
If lightobject < 10000
INC lightobject
Make Object Sphere lightobject, 15
Position Object lightobject, Camera Position X(0), Camera Position Y(0), Camera Position Z(0) + Object Size Z(lightobject)
Point Camera 0, Object Position X(lightobject), Object Position Y(lightobject), Object Position Z(lightobject)
Color Object lightobject, RGB(VAL(lightcolorr$), VAL(lightcolorg$), VAL(lightcolorb$))
Set Object Fog lightobject, 0
Set Object Ambient lightobject, 0
//ADD DYNAMIC LIGHT
inc dynamiclight
make light dynamiclight
color light dynamiclight, rgb(val(lightcolorr$), val(lightcolorg$), val(lightcolorb$))
set light range dynamiclight, 600
position light dynamiclight, object position x(lightobject), object position y(lightobject), object position z(lightobject)
hide light dynamiclight
Open To Write 23, "Maps/" + currentmapname$ + "/" + "Lights/Static/" + STR$(lightobject)
If File Open(23) = 1
Write String 23, lightrange$
Write String 23, lightcolorr$
Write String 23, lightcolorg$
Write String 23, lightcolorb$
EndIf
Close File 23
Delete File "addlight"
//IF OBJECT IS ALREADY SELECTED APPLY PROPERTIES
If File Exist("objectselected") = 1
Hide Object Bounds objectselected
objectselected = lightobject
TG Set Active Object objectselected
Show Object Bounds objectselected, 1
//ENGINE OBJECT SELECTED DETECTION
WriteToObjectSelectedFile()
EndIf
//IF OBJECT IS NOT SELECTED ENTER OBJECT SELECTED FUNCTION
If File Exist("objectselected") = 0
objectselected = lightobject
ObjectSelect()
Exit
EndIf
EndIf
EndIf
//BUILD LIGHTS
If File Exist("buildlights") = 1
if effect exist(1) = 1
delete effect 1
endif
for nwobj = 1 to sceneobject
if object exist(nwobj) = 1
litobjposx# = object position x(nwobj)
litobjposy# = object position y(nwobj)
litobjposz# = object position z(nwobj)
litobjrotx# = object angle x(nwobj)
litobjroty# = object angle y(nwobj)
litobjrotz# = object angle z(nwobj)
litobjscx# = object scale x(nwobj)
litobjscy# = object scale y(nwobj)
litobjscz# = object scale z(nwobj)
delete object nwobj
if file exist("Maps/" + currentmapname$ + "/" + "Resources/" + str$(nwobj)) = 1
open to read 2, "Maps/" + currentmapname$ + "/" + "Resources/" + str$(nwobj)
if file open(2) = 1
read string 2, modelnw$
read string 2, texturenw$
read string 2, normalmaptexturenw$
endif
close file 2
load object modelnw$, nwobj
position object nwobj, litobjposx#, litobjposy#, litobjposz#
rotate object nwobj, litobjrotx#, litobjroty#, litobjrotz#
scale object nwobj, litobjscx#, litobjscy#, litobjscz#
endif
endif
next nwobj
LM Start
LM Clear Collision Objects
LM Clear Light Map Objects
LM Clear Lights
//SET AMBIENT LIGHT
If File Exist("Maps/" + currentmapname$ + "/" + "Lights/Settings/Ambient Light/AmbientLight") = 1
Open To Read 24, "Maps/" + currentmapname$ + "/" + "Lights/Settings/Ambient Light/AmbientLight"
If File Open(24) = 1
Read String 24, ambientlight$
EndIf
Close File 24
LM Set Ambient Light VAL(ambientlight$), VAL(ambientlight$), VAL(ambientlight$)
Else
If File Exist("Maps/" + currentmapname$ + "/" + "Lights/Settings/Ambient Light/AmbientLight") = 0
LM Set Ambient Light 0.5, 0.5, 0.5
EndIf
EndIf
//SET AMBIENT OCCLUSION
If File Exist("Maps/" + currentmapname$ + "/" + "Lights/Settings/Ambient Occlusion/AmbientOcclusion") = 1
Open To Read 25, "Maps/" + currentmapname$ + "/" + "Lights/Settings/Ambient Occlusion/AmbientOcclusion"
If File Open(25) = 1
Read String 25, ambientocclusion$
EndIf
Close File 25
If ambientocclusion$ = "enable"
LM Set Ambient Occlusion On 1, 1, 1
Else
If ambientocclusion$ = "disable"
LM Set Ambient Occlusion Off
EndIf
EndIf
Else
If File Exist("Maps/" + currentmapname$ + "/" + "Lights/Settings/Ambient Occlusion/AmbientOcclusion") = 0
LM Set Ambient Occlusion On 1, 1, 1
EndIf
EndIf
For lmaddcollobj = 1 To sceneobject
If Object Exist(lmaddcollobj) = 1
LM Add Collision Object lmaddcollobj
EndIf
Next lmaddcollobj
LM Build Collision Data
For lmaddlmobj = 1 To sceneobject
If Object Exist(lmaddlmobj) = 1
LM Add Light Map Object lmaddlmobj
EndIf
Next lmaddlmobj
For litobjs = 9004 To lightobject
If File Exist("Maps/" + currentmapname$ + "/" + "Lights/Static/" + STR$(litobjs)) = 1
Open To Read 26, "Maps/" + currentmapname$ + "/" + "Lights/Static/" + STR$(litobjs)
If File Open(26) = 1
Read String 26, lightrange$
Read String 26, lightcolorr$
Read String 26, lightcolorg$
Read String 26, lightcolorb$
EndIf
Close File 26
If Object Exist(litobjs) = 1
LM Add Point Light Object Position X(litobjs), Object Position Y(litobjs), Object Position Z(litobjs), VAL(lightrange$), VAL(lightcolorr$), VAL(lightcolorg$), VAL(lightcolorb$)
EndIf
EndIf
Next litobjs
LM Set Light Map Name currentmapname$
LM Build Light Maps 256, 1.0, 0.5, 3
LM Build Light Maps Thread 256, 1.0, 0.5, 3
Load DLL "Kernel32.dll", 1
Sync Off
While LM Get Complete() = 0
Call DLL 1, "Sleep", 100
CLS
open to write 1, "lightmapstatus"
if file open(1) = 1
write string 1, lm get status()
endif
close file 1
EndWhile
If DLL Exist(1) = 1
Delete DLL 1
EndIf
Sync On
LM Terminate Thread
LM Reset
If File Exist("Lightmap Quality Changed.txt") = 1
Delete File "Lightmap Quality Changed.txt"
EndIf
if file exist("lightmapstatus") = 1
delete file "lightmapstatus"
endif
//RELOAD EFFECT
if effect exist(1) = 0
load effect "GGbump06a.fx", 1, 0
null = make vector4(1)
set vector4 1,-0.57735,-0.57735,0.57735,0
set effect constant vector 1,"lightDirection", 1
set vector4 1,1.0,1.0,1.0,1.0
set effect constant vector 1,"lightColour", 1
set effect constant float 1, "specLevel", 5.5
set vector4 1, 0, 10, 0, 0.005
set effect constant vector 1, "lightPosition", 1
set vector4 1, 0.0, 0.0, 0.0, 1.0
set effect constant vector 1, "posLightColour", 1
set effect technique 1,"t0"
endif
//LOAD OBJECT AND APPLY TEXTURES AND SHADER
for reabobj = 1 to sceneobject
if object exist(reabobj) = 1
//READ OBJECT RESOURCES FILE
if file exist("Maps/" + currentmapname$ + "/" + "Resources/" + str$(reabobj)) = 1
open to read 1, "Maps/" + currentmapname$ + "/" + "Resources/" + str$(reabobj)
if file open(1) = 1
read string 1, model$
read string 1, texture$
read string 1, normalmaptexture$
endif
close file 1
//DELETE SHADER IMAGES
//TEXTURE
if image exist(reabobj) = 1
delete image reabobj
endif
//NORMAL TEXTURE
if image exist(reabobj + 89833) = 1
delete image reabobj + 89833
endif
//APPLY TEXTURE
if file exist(texture$) = 1
load image texture$, reabobj
texture object reabobj, 0, reabobj
endif
//APPLY NORMAL MAP TEXTURE
if file exist(normalmaptexture$) = 1
load image normalmaptexture$, reabobj + 89833
texture object reabobj, 2, reabobj + 89833
endif
set object effect reabobj, 1
endif
endif
next reabobj
Delete File "buildlights"
EndIf
Alex Matei CEO
www.alexmatei.com