SetUp(numberofObjects,numberofLights) `these are max numbers
You need that first.
load effect "FX\NormalMapping.fx",1,0
set vector4 1,0.15,0.15,0.15,0
set effect constant vector 1,"Ambient",1
You should always set the ambient to some low level. (scale is 0.0-1.0)
load object "meshes\sword.dbo",SwordNum
texture object SwordNum,0,SwordTex
texture object SwordNum,1,SwordNormal
set object effect SwordNum,1
Load and texture your meshes and set the effect
LightColor(LightNum,red,green,blue,radius) `rgb is 0-255
LightPosition(LightNum,X,Y,Z)
Make all the lights.
Here's where it gets tricky:
You would (could) do this every frame. You HAVE TO do this each frame for every moving light.
LN=0
`do the character light
set vector4 1,object position x(Player1),object position y(Player1)+6.0,object position z(Player1)-2.0,0
set effect constant vector 1,"LightPosition_"+str$(LN+1),1
set vector4 1,0.125,0.12,0.115,0
set effect constant vector 1,"LightColor_"+str$(LN+1),1
set effect constant float 1,"LightRange_"+str$(LN+1),15.0
LN=LN+1
for OL=0 to NumberOfLights
if abs(LightPos#(OL,0)-camera position x())<65.0 and LN<7
set vector4 1,LightPos#(OL,0),LightPos#(OL,1),LightPos#(OL,2),0
set effect constant vector 1,"LightPosition_"+str$(LN+1),1
set vector4 1,LightCol#(OL,0),LightCol#(OL,1),LightCol#(OL,2),0
set effect constant vector 1,"LightColor_"+str$(LN+1),1
set effect constant float 1,"LightRange_"+str$(LN+1),LightCol#(OL,3)
LN=LN+1
endif
next OL
if LN>0 then set effect technique 1,"Light"+str$(LN)
if LN=0 then set effect technique 1,"Ambient"
I hope you can make sense of that code.... It's kinda straight forward, but hard to explain...(?)
If you are going to have a large level with lots of lights, you can still use this. The side scroller only needed this code because you can only see a maximum of 8 lights (including the player) at one time.... (my .fx variation uses 8).
On another project I use 9 instances of the .fx and assign objects within each of the 3x3 grid to the appropriate .fx. As the player moves around, the area he can see moves along the 3x3; each time changing which are being used.... The player can only see the 3x3 so that's not a problem. For a FPS, you would need to come up with another method, but the concept is the same-- only show the player what they need to see. Going to bed now....
The fastest code is the code never written.