Why would you divide by the total number of lights? All existing lights would become dimmer every time you add a new one.
The following code assumes you'll add a "source_strength" field to FDLight instead of using a global for light strength.
Implementing multi-coloured lights (r,g,b) should be trivial.
The following code assumes you'll add a "source_strength" field to FDLight instead of using a global for light strength.
Function F3D_UpdateLights() For r.fdreciever = Each fdreciever ;Calculate vertex colors s=GetSurface(r\ent,1) For i=1 To CountVertices(s)-1 TFormPoint VertexX(s,i),VertexY(s,i),VertexZ(s,i),r\ent,0 local intensity# = 0 For l.fdlight = Each fdlight xd#=TFormedX()-EntityX(l\ent) yd#=TFormedY()-EntityY(l\ent) zd#=TFormedZ()-EntityZ(l\ent) dist#=Sqr(xd*xd + yd*yd + zd*zd)*radius intensity = intensity + l\source_strength / (xd*xd + yd*yd + zd*zd) ; ()=distance^2 Next if intensity > 255 then intensity = 255 VertexColor s,i,intensity,intensity,intensity Next Next End Function
Implementing multi-coloured lights (r,g,b) should be trivial.