Some of you may have tried/used my previous real time lighting system. Well I'm currently in the process of rewriting it and decided to make an early release as progress has pretty much ground to a halt the past couple of weeks.
http://www.evolved-software.com/advancedlighting/advancedlighting
All dbp code, so feel free to modify etc.
Function list
Advanced Lighting.dba
AdvLighting_Setup(Width, Height)
AdvLighting_Render()
AdvLighting_Debug()
AdvLighting_SetCamera(Near, Far, Fov, Aspect)
AdvLighting_SetFrameCamera(Frame Camera)
AdvLighting_EdgeDetection(Enable flag)
AdvLighting_Debug()
AL_Lighting.dba
AdvLighting_SetFog(Range, Color Red, Color Green, Color Blue, Power)
AdvLighting_SetAmbient(Color Red, Color Green, Color Blue)
AdvLighting_SetAmbientTexture(Texture Number)
AL_Directional.dba
DirLight_Create(Specular flag, SubSurface flag,Shadow quality, Shadow map Size)
DirLight_Delete()
DirLight_SetVisible(Visible Flag)
r=DirLight_GetVisible()
DirLight_SetAngle(Angle X , Angle Y, Angle Z)
r=DirLight_GetAngleX()
r=DirLight_GetAngleY()
r=DirLight_GetAngleZ()
DirLight_SetColor(Color Red, Color Green, Color Blue)
r=DirLight_GetColorRed()
r=DirLight_GetColorGreen()
r=DirLight_GetColorBlue()
DirLight_SetRange(Range)
r=DirLight_GetRange()
DirLight_SetSpecularPower(Specular pow)
DirLight_SetShadow(Shadow flag (0-5), Shadow map Size)
AL_Spot.dba
Light=SpotLight_Create(Specular flag, SubSurface flag,Shadow quality, Shadow map Size)
SpotLight_Delete(Light)
SpotLight_SetVisible(Light, Visible Flag)
r=SpotLight_GetVisible(Light)
SpotLight_SetTexture(Light, Texture)
SpotLight_SetPosition(Light, Position X, Position Y, Position Z)
r=SpotLight_GetPositionX(Light)
r=SpotLight_GetPositionY(Light)
r=SpotLight_GetPositionZ(Light)
SpotLight_SetAngle(Light, Angle X , Angle Y, Angle Z)
r=SpotLight_GetAngleX(Light)
r=SpotLight_GetAngleY(Light)
r=SpotLight_GetAngleZ(Light)
r=SpotLight_GetFOV(Light)
SpotLight_SetRoll(Light, Roll)
r=SpotLight_GetRoll(Light)
SpotLight_SetColor(Light,Color Red, Color Green, Color Blue)
r=SpotLight_GetColorRed(Light)
r=SpotLight_GetColorGreen(Light)
r=SpotLight_GetColorBlue(Light)
SpotLight_SetRange(Light, Range)
r=SpotLight_GetRange(Light)
SpotLight_SetAttenuation(Light, Attenuation)
SpotLight_SetSpecularPower(Light,Specular pow)
SpotLight_SetShadow(Light, Shadow flag (0-5), Shadow map Size, Range)
AL_Point.dba
Light=PointLight_Create(Specular flag, SubSurface flag,Shadow quality, Shadow map Size)
Light=PointLight_CreateCubeLight(Specular flag, SubSurface flag,Shadow quality, Shadow map Size)
PointLight_Delete(Light)
PointLight_SetVisible(Light, Visible Flag)
r=PointLight_GetVisible(Light)
PointLight_SetCubeTexture(Light, Texture)
PointLight_SetPosition(Light, Position X, Position Y, Position Z)
r=PointLight_GetPositionX(Light)
r=PointLight_GetPositionY(Light)
r=PointLight_GetPositionZ(Light)
PointLight_SetAngle(Light, Angle X , Angle Y, Angle Z)
r=PointLight_GetAngleX(Light)
r=PointLight_GetAngleY(Light)
r=PointLight_GetAngleZ(Light)
PointLight_SetColor(Light,Color Red, Color Green, Color Blue)
r=PointLight_GetColorRed(Light)
r=PointLight_GetColorGreen(Light)
r=PointLight_GetColorBlue(Light)
PointLight_SetRange(Light, Range)
r=PointLight_GetRange(Light)
PointLight_SetAttenuation(Light, Attenuation)
PointLight_SetSpecularPower(Light,Specular pow)
PointLight_SetShadow(Light, Shadow flag (0-5), Shadow map Size, Range)
AL_Effect.dba
Effect_Add(Effect Number)
Effect_Remove(Effect Number)
Effect_SetDetailMapping(Effect Number, Detailmapping Flag)
Effect_AttachedObject(Effect Number, Object Number)
Effect_LockIdentifier(Effect file)
Effect_SetIdentifier(Compiler Identifier, Value)
Effect_UnLockIdentifier()
AL_Object.dba
Object_Add(Object Number)
Object_Remove(Object Number)
Object_SetAutoUpdate(Object Number, Auto Update flag)
Object_SetShadow(Object Number, Shadow flag (0-2))
Object_Mask(Object Number, Adv Lighting Mask, Shadow Mask)
Object_UpdateShadow(Object Number)
AL_PostFilter.dba
PostFilter_SetUp(Width, Height, D3DFormat)
PostFilter_Delete()
Target=PostFilter_AddFrameTarget(Effect File)
PostFilter_SetFrameTargetImage(Target, Stage, Image Number)
r=PostFilter_GetFrameTargetEffect(Target)
Target=PostFilter_AddRenderTarget(Effect File, Width, Height, D3DFormat)
PostFilter_SetRenderTargetEnabled(Target, Enable flag)
PostFilter_SetRenderTargetImage(Target, Stage, Image Number)
r=PostFilter_GetRenderTargetImage(Target)
r=PostFilter_GetRenderTargetEffect(Target)
LightScattering_SetUp(Width, Height)
LightScattering_SetLightScatteringEnabled(Enable flag)
AL_Sky.dba
Sky_Create()
Sky_Delete()
Sky_SetVisible(Visible Flag)
Sky_SetDynamic(Dynamic Flag)
Sky_SetTexture(Texture Number)
Sky_SetAngle(Angle X , Angle Y, Angle Z)
Sky_SetColor1(Color Red, Color Green, Color Blue)
Sky_SetColor2(Color Red, Color Green, Color Blue)
Sky_SetSunTexture(Texture Number)
Sky_SetSunColor(Color Red, Color Green, Color Blue)
Sky_SetSunAngle(Angle X , Angle Y, Angle Z)
Sky_SetPlanetTexture(Texture Number)
Sky_SetPlanetColor(Color Red, Color Green, Color Blue)
Sky_SetPlanetAngle(Angle X , Angle Y, Angle Z)
Clouds_Create()
Clouds_Delete()
Clouds_SetVisible(Visible Flag)
Clouds_SetScale(Scale, Density)
Clouds_SetNoise(Scale, Amount)
Clouds_SetSpeed(Speed x, Speed z)
Clouds_SetColor(Color Red, Color Green, Color Blue)
Clouds_SetAlpha(Alpha)
TimeOfDay_Load(File)
TimeOfDay_SetHour(Hour)
AL_Materials.dba
Materials_Load(File, Detailmapping Flag, SubSurface Flag)
Materials_Delete()
Materials_Apply(Object Number)
Materials_ApplyToLimb(Object Number, Limb Number)
Materials_SetDetailMapping(Detailmapping Flag)
Particles.dba
Emitter_SetUp()
Emitter=Emitter_Load(Emitter file, Emitter size)
Emitter=Emitter_Clone(Emitter)
Emitter_Update(Timer)
Emitter_Delete(Emitter)
Particle=Emitter_EmitParticle(Emitter, Sub Emitter)
Emitter_Play(Emitter, Sub Emitter)
Emitter_Stop(Emitter, Sub Emitter)
Emitter_SetFog(Fog range, Fog power)
Emitter_SetVisible(Emitter, Visible Flag)
Emitter_SetAutoDelete(Emitter, Delete Flag)
Emitter_SetUpdateTimer(Emitter, Sub Emitter, Timer)
Emitter_SetUpdateDistanceStep(Emitter, Sub Emitter, Update dist)
Emitter_SetPosition(Emitter, Position X, Position Y, Position Z, Mode)
Emitter_SetAngle(Emitter, Angle X, Angle Y, Angle Z)
Emitter_SetEmissionID(Emitter, Sub Emitter, ID)
Emitter_SetCollisionID(Emitter, Sub Emitter, ID)
Emitter_SetCollisionHeight(iEmitter as integer, Sub Emitter, Enable, Height)
Emitter_SetCollisionPlane(iEmitter as integer, Sub Emitter, Enable, Position X, Position Y, Position Z, Normal X, Normal Y, Normal Z)
Emitter_SetCollisionStep(iEmitter as integer, Sub Emitter, Step)
Emitter_SetOrientationStep(iEmitter as integer, Sub Emitter, Step)
Emitter_SetEdgeSoftness(Emitter, Sub Emitter, Edge softness)
r=Emitter_GetVisible(iEmitter as integer)
r=Emitter_GetPositionX(Emitter, Sub Emitter)
r=Emitter_GetPositionX(Emitter, Sub Emitter)
r=Emitter_GetPositionX(Emitter, Sub Emitter)
r=Emitter_GetAngleX(Emitter)
r=Emitter_GetAngleY(Emitter)
r=Emitter_GetAngleZ(Emitter)
r=Emitter_GetEmissionEvent()
Event=Emitter_GetEmissionEmitter()
r=Emitter_GetEmissionParticle()
r=Emitter_GetEmissionID()
r=Emitter_GetEmissionPositionX()
r=Emitter_GetEmissionPositionY()
r=Emitter_GetEmissionPositionZ()
r=Emitter_GetEmissionDirectionX()
r=Emitter_GetEmissionDirectionY()
r=Emitter_GetEmissionDirectionZ()
Event=Emitter_GetCollisionEvent()
r=Emitter_GetCollisionEmitter()
r=Emitter_GetCollisionParticle()
r=Emitter_GetCollisionID()
r=Emitter_GetCollisionPositionX()
r=Emitter_GetCollisionPositionY()
r=Emitter_GetCollisionPositionZ()
r=Emitter_GetCollisionNormalX()
r=Emitter_GetCollisionNormalY()
r=Emitter_GetCollisionNormalZ()
How it works (14/5/2013)
It works by storing all geometry data into a a 128f (A32R32G32B32f) surface format, this is achieved by packing diffuse / normals / specular / emissive / subsurface scattering & velocity vectors in to single channels. There is also a additional 32f render that store perspective depth to which is used for pixel rejection (for alpha surfaces) and world position reconstruction, this way we only have to fetch the large 128 bit surface and unpack geometry data on lit pixels.
Shadow mapping
Im using a technique called exponential variance shadow mapping (EVSM), this unfortunately is one of them good news, bad news situations. The shadow maps require a 64 bit surface format! which can end up eating a lot of Vram. There are still some minor light bleeding (evsm fixes the major light bleeds that occur with standard vsm) where shadows hit close casters. However we do end up with some nice looking linear filter shadow maps that are extremely fast compared to the alternative PCFSS. I also have a system in place where a light is non moving only dynamic objects are rendered and not the non moving scene geometry around it, this is to improve performance when shadow maps are update. There is now shadow map LOD implemented which reduces the shadow map size / quality and format over distance.
Point lights with shadows are the easy way out when it comes to lighting a scene. However they are very costly, they equate to 6 spotlights in rendering cost. Its best to strategically place shadowed spotlights with non-shadowed point lights to get the best performance results.
Texturing
Texturing may confuse some so here's a quick overview. some textures may need a specific texture on a certain channel, I have a texture tool for this if needed ->
http://www.evolved-software.com/texturetool/texturetool
Base/diffuse texture is the default texture set to stage 0, alpha of this texture can be used for 1 bit transparency.
Norma map texture is set to stage 1. alpha channel is used for storing height map for parallax/relief mapping or environment bump mapping bumpiness.


(above: normal map + height map in alpha)
Specular+Emissive+reflectivity map texture is set to stage 2. Red channel is used for specular power, green channel is for emissive gray scale emissive map), blue is used for environment map reflectivity.


(above: specular intensity)
Environment map texture used on stage 3 when using environment map & environment bump map shader.
Detail normal mapping set to stage 3/4. This gives detail to a texture making it look high-res when up close.


(above: detail normal map + detail greyscale)
Approximate subsurface scattering texture set to stage 4/5. This texture is used to approximate how light passes through the surface, Alpha is used for the curved thickness of the surface (note: 8bit texture due to packing ).


(above: palm leaf sss color + palm leaf curved thickness in alpha)