Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - Advanced Lighting

Author
Message
EVOLVED
16
Years of Service
User Offline
Joined: 9th Feb 2003
Location: unknown
Posted: 24th Oct 2012 14:30 Edited at: 26th May 2013 21:41
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)
MrValentine
AGK Backer
8
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: Playing
Posted: 24th Oct 2012 15:20
I recall mention of this, tagging in for now, hope you can pick it up soon, as I hope to use your plugins in my projects!

Stab in the Dark software
Valued Member
16
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 26th Oct 2012 03:31
Evolved why are you using "Constants" with same name as your functions?
The DBpro compiler does not like this and won't compile unless you delete the "Constants".
I did get your examples to run and they are fantastic.
You are the Shader master.

[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
Virtual Nomad
13
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Oct 2012 01:14
thanks, evolved

Virtual Nomad @ California, USA . DBPro V7.7
AMD Phenom™ X4 9750 Quad-Core @ 2.4 GHz . 8 GB PC2-6400 RAM
ATI Radeon HD 3650 @ 512 MB . Vista Home Premium 64 Bit
EVOLVED
16
Years of Service
User Offline
Joined: 9th Feb 2003
Location: unknown
Posted: 27th Oct 2012 12:52 Edited at: 27th Oct 2012 12:52
@Stab in the Dark software

Odd that it wont compile, made an update that removes the constants in case anyone else has the same issue. I was using them for testing to see if I could call functions like a plugin command (it did work btw), so I could call a function like this "SetupAdvLighting sw,sh" instead of SetupAdvLighting(sw,sh).

@Virtual Nomad

Thanks for the nomination
Chris Tate
DBPro Master
10
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 27th Oct 2012 14:47
I do that sometimes; instead of having to write Log("Report program status"), I can just write Log "Report program status".

Nice system by the way. I have learned about programming from your work in recent years; keep up the good work.

Chenak
16
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 27th Oct 2012 15:11
@Stab in the Dark software

I think you need to update your IDE, this works with codesurge and the default ide, I'm guessing you're using your own ide?

@Evolved

Brilliant as usual, very impressive stuff, looking forward to what else you come up with
Stab in the Dark software
Valued Member
16
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 27th Oct 2012 15:50 Edited at: 27th Oct 2012 16:42
The error is:

Quote: "Constant name 'AddObject' cannot share the name of a reserved word or command."


The error occurs with the default IDE "Synergy".
The error is being kicked out by the compiler not the IDE.
Our IDE only picks up the compile errors kicked out by the compiler.
The next obvious question would be are we all using the same version of DBPro.
Because I could not get it to compile I was curious how it was for others.

EDIT: The problem is using constants in DBPro. Here is two links about it.

http://forum.thegamecreators.com/?m=forum_view&t=144491&b=15
http://forum.thegamecreators.com/?m=forum_view&t=190804&b=15

[img][/img]


WindowsXP SP3,Vista,Windows 7 SP1, DBpro v7.7RC7
Stab In The Dark Editor
The coffee is lovely dark and deep,and I have code to write before I sleep.
Chenak
16
Years of Service
User Offline
Joined: 13th Sep 2002
Location: United Kingdom
Posted: 27th Oct 2012 16:53
Thats really weird, I'm not getting any errors on my end, I am using the last official update so not sure if it's specific to the beta. Works fine in the latest codesurge :/

I don't use the default synergy editor as I always had a problem with the synergy ides to the point of loosing code and random crashes, last time I used the default old ide with constants as function names it worked fine.
Brendy boy
13
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 28th Oct 2012 11:28 Edited at: 28th Oct 2012 11:32
Quote: "EDIT: The problem is using constants in DBPro. Here is two links about it."

i get the same error, i'm using U77 beta and default IDE

EDIT:
now i get this error:
Quote: "Cannot use reserved word 'RemoveObject' as declaration inside Include\AL_Object.dba."

Does anyone know where reserved word "RemoveObject" comes from

EVOLVED
16
Years of Service
User Offline
Joined: 9th Feb 2003
Location: unknown
Posted: 28th Oct 2012 23:39
Might be from a plugin, swapped RemoveObject() to ObjectRemove().
Red Eye
10
Years of Service
User Offline
Joined: 15th Oct 2008
Location:
Posted: 18th Dec 2012 17:15 Edited at: 18th Dec 2012 17:17
I have been having some issues with the deferred lighting.
Got it to work in my engine in DarkGDK, with the example of Mista Wilson. But I believe the normals are being calculated wrong, and have a vague idea that it has to do with the depth calculation. But then again I am clueless, been having this issue for weeks now.



Have you got an idea what could be causing this?

Like = Follow!
Green Gandalf
VIP Member
14
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 21st Dec 2012 12:25
@Red Eye

I can't see your image.
Juggernaut
6
Years of Service
User Offline
Joined: 12th Mar 2012
Location:
Posted: 25th Jan 2013 20:11
Hello Evolve,

Can you please write us a guide regarding what each of your function does and the purpose of each parameter within the function ?

It will help us to understand your framework properly and use it in our games.

Does your advanced lighting system work with BlitZ Terrain ?

Thanks,

Login to post a reply

Server time is: 2019-02-16 02:52:40
Your offset time is: 2019-02-16 02:52:40