It is currently Sun Dec 09, 2018 10:34 pm


Advanced Lighting (its still wip)

For every thing to do with shaders.
  • Author
  • Message
User avatar

EVOLVED

Site Admin

  • Posts: 30
  • Joined: Wed Mar 05, 2014 7:52 am

Advanced Lighting (its still wip)

PostThu Mar 06, 2014 2:59 am

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/advance ... edlighting

All dbp code, so feel free to modify etc.

How it works
It works by storing most geometry data into a single A32R32G32B32f surface, this is achieved by packing diffuse + normals + specular + emissive + subsurface scattering + velocity vectors in to single channels. There is also a additional A16B16G16R16f render that stores world position and depth, this way we only have to fetch the large 128bit 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.

Function list:

Advanced Lighting.dba
AdvLighting_Setup(Width, Height, Post process Width, Post process Height, Motion Blur)
AdvLighting_Update()
AdvLighting_SetCamera(Near, Far, Fov, Aspect)
AdvLighting_Debug()

AL_Lighting.dba
AdvLighting_SetAmbient(Color Red, Color Green, Color Blue)
AdvLighting_SetAmbientTexture(Cube Texture Number)
AdvLighting_SetFog(Range, Range Power, Color Red, Color Green, Color Blue, Under light Red, Under light Green, Under light Blue)
AdvLighting_SetHeightFog(Height , Height Fade, Exponential val, Range, Range Power, Color Red, Color Green, Color Blue, Alpha)
Lens Flare=LensFlare_Create(Sub Flare Count)
LensFlare_Delete(Lens Flare)
LensFlare_SetVisible(Lens Flare, Visible)
LensFlare_SetPosition(Lens Flare, Position X, Position Y, Position Z)
LensFlare_SetColor(Lens Flare, Color Red, Color Green, Color Blue)
LensFlare_SetToDirLight(Lens Flare)
LensFlare_SetToSpotLight(Lens Flare, Spot Light)
LensFlare_SetToPointLight(Lens Flare, Point Light)
LensFlare_SetSubFlareAtlas(Lens Flare, Sub Flare, Atlas)
LensFlare_SetSubFlareScale(Lens Flare, Sub Flare, Scale X, Scale Y, View Scale)
LensFlare_SetSubFlareOffset(Lens Flare, Sub Flare, Offset, Z shift, Roll)
LensFlare_SetSubFlareColor(Lens Flare, Sub Flare, Red, Green, Blue, Alpha To Surface)
LensFlare_SetSubFlareFalloff(Lens Flare, Sub Flare, Fall off Range, Inner Fade, Edge Fade)
Fog Area=FogArea_Create(Type)
FogArea_Delete(Fog Area)
FogArea_Visible(Fog Area, Visible flag)
FogArea_SetOrientation(Fog Area, Position X, Position Y, Position Z, Angle X , Angle Y, Angle Z, Scale X, Scale Y, Scale Z)
FogArea_SetColor(Fog Area, Color Red, Color Green, Color Blue, Alpha)
FogArea_SetColor2(Fog Area, Color Red, Color Green, Color Blue)
FogArea_SetRange(Fog Area, Range, Z Range, Z Fall)
FogArea_SetCaustics(Fog Area, Texture, Dir X, Dir Y, Dir Z, Scale)

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_MotionBlur(Effect Number)
AlphaEffect_Add(Effect Number)
AlphaEffect_Remove(Effect Number)
AlphaEffect_EnableLighting(Effect Number, Enable Flag)
AlphaEffect_SetLightingPositonToCamera(Effect Number, Enable Flag)
AlphaEffect_SetLightingPositonToObject(Effect Number, Object Number)
AlphaEffect_SetLightingPositon(Effect Number, Position X, Position Y, Position Z)
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, Directional shadow flag)
Object_Mask(Object Number, Adv Lighting Mask, Shadow Mask)
Object_Update(Object Number)
Object_MotionBlur(Object Number, Limb Number, Effect Number)
Object_MotionBlurRemove(Object Number)
AlphaObject_Add(Object Number)
AlphaObject_Remove(Object Number )
AlphaObject_Mask(Object Number, Alpha flag, Refract flag, Distort/Scatter flag)
AlphaObject_AdditiveBlending(Object Number, Additive Blending flag)

AL_PostFilter.dba
PostProcessing_SetUp(Width, Height, D3DFormat, Refraction, Distortion, AA, Bloom, DOF)
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)

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)
Sky_SetCloudsTexture(Texture, Noise Texture)
Sky_SetCloudsDensity(Density, Alpha)
Sky_SetCloudsScale(U Sacle, V Sacle)
Sky_SetCloudsSpeed(U Speed as float, V Speed)
Sky_SetCloudsColor(Color Red, Color Green, Color Blue)
Sky_SetCloudsLightColor(Color Red, Color Green, Color Blue)
Clouds_Setup()
Clouds_Delete()
Clouds_SetTexture(Cloud Texture, Noise Texture)
Clouds_SetDensity(Density)
Clouds_SetScale(Sacle , U Sacle, V Sacle, Noise U Sacle, Noise V Sacle)
Clouds_SetHeight(Cloud Height, Cloud Height Sacle)
Clouds_SetSpeed(U Speed, V Speed, Noise U Speed, Noise V Speed)
Clouds_SetColor(Color Red, Color Green, Color Blue)
Clouds_SetLightColor(Color Red, Color Green, Color Blue)
TimeOfDay_SetUp()
TimeOfDay_SetSkyColor(Index,R , G, B, R , G, B, R , G, B)
TimeOfDay_SetFogColor(Index,R , G, B, R , G, B, R , G, B)
TimeOfDay_SetLightColor(Index,R , G, B, R , G, B, R , G, B)

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)
Materials_SaveStaticCubeMap(Position X, Position Y, Position Z, Face 1, Face 2, Face 3, Face 4, Face 5, Face 6)

Water.dba
Water_Build()
Water_SetVisible(Visible flag)
Water_SetScale(Tile Size, Height, Wave Height)
Water_SetFogColor(Range, Height,Color Red, Color Green, Color Blue, Deep Red, Deep Green, Deep Blue)

Terrain.dba
Terrain_Create(Size X, Size Z, Clamp, Height)
Terrain_Load(Height, Blendmap1, Blendmap2, Colormap, Clamp)
Terrain_Delete()
Terrain_SetVisible(Visible flag)
Terrain_SetScale(Tile Size, Height)
Terrain_SetTexture(Atlas1, Atlas2, Atlas3, Atlas4, Atlas Normal)
Terrain_SetTextureSize(Uv Tile Size, Vertical Uv Tile Size)
Terrain_AddAtlasTexture(Base file, Normal file,Stage)
Terrain_BuildAtlasTexture(Atlas1 texture, Atlas2 texture, Atlas3 texture, Atlas4 texture, Atlas Normal)
Terrain_GetHeight(Position X, Position Z)
Terrain_Ray(Position X, Position Y, Position Z, To Position X, To Position Y, To Position Z)

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_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)
Emitter_SetLighting(Emitter, Sub Emitter, Lighting)
Emitter_Mask(Emitter, Sub Emitter, Alpha, Refract, Distort)
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()

Texturing
Texturing may confuse some so here's a quick overview. some textures may need a specific texture on a certain rgba 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 (requires transparency shader to be applied).
Image

Environment map texture used on stage 1 when using environment map & environment bump map biased shader, you can also use dbp inbuilt "set cube mapping on".

Norma map texture is set to stage 1 or 2. alpha channel is used for storing height map for parallax mapping or environment bump mapping bumpiness.
ImageImage
(above: normal map + height map/bumpiness in alpha)

Specular intencity, Glossyness/Emissive, reflectivity map, fresnel term - texture is set to stage 2 or 3. Red channel is used for specular power, green channel is for Glossyness (or set the val to 255 for 1bit Emissive), blue is used for environment map reflectivity, alpha used for environment map fresnel term.
ImageImage
(above: specular intensity)

Detail normal mapping set to stage 3 or 4. This gives detail to a texture making it look high-res when up close.
ImageImage
(above: detail normal map + detail greyscale)

Approximate subsurface scattering texture set to stage 4 or 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 ).
ImageImage
(above: palm leaf sss color + palm leaf curved thickness in alpha)

Samkm

  • Posts: 5
  • Joined: Sat Mar 08, 2014 5:12 pm

Re: Advanced Lighting (its still wip)

PostSat Mar 08, 2014 5:23 pm

Hey Evolved, good to see the forum's back up and you're still improving Advanced Lighting :)
In case you haven't dropped by the DarkBASIC Pro forums for a while, I thought you might like to know there's a plugin in development which allows DBPro to use DirectX 11. Here's the thread:
http://forum.thegamecreators.com/?m=forum_view&t=210180&b=8
It's still in fairly early development, but it already has support for Pixel/Vertex shader model 5, and of course all the extra things DirectX 11 can do, like Geometry shaders. I wondered if you were interested because I know DBPro's DirectX 9 rendering system has always made speed an issue with a system like Advanced Lighting, and I imagine you could get some even more impressive shader effects from Dx11!
Anyway, good luck with the development!
User avatar

EVOLVED

Site Admin

  • Posts: 30
  • Joined: Wed Mar 05, 2014 7:52 am

Re: Advanced Lighting (its still wip)

PostSat Mar 08, 2014 8:34 pm

Interesting, I'll keep an eye on that.

Here's a image, I'm back to where the old AL was at with terrain (supports up to 8 texture layers) and water. I have no clouds though as I'm going to redo em.

http://www.evolved-software.com/mis/al001.jpg
http://www.evolved-software.com/mis/al002.jpg
http://www.evolved-software.com/mis/al003.jpg

Samkm

  • Posts: 5
  • Joined: Sat Mar 08, 2014 5:12 pm

Re: Advanced Lighting (its still wip)

PostFri Mar 14, 2014 2:45 pm

Those pictures look amazing, s'pecially the second one! :D
Any plans for when this might be released?
Also, just wondering... Compared to the last update of the old AL system, what are the main improvements between that and your new system?
Thanks, and keep up the great work!

Tyler

  • Posts: 5
  • Joined: Tue Mar 18, 2014 11:11 am

Re: Advanced Lighting (its still wip)

PostTue Mar 18, 2014 11:14 am

I am with Sam, it's looking great! I can tell from just the screenshots that the visual fidelity has definitely gone up as the terrain looks far crisper than before as the normal mapping really shows off the details. I too am interested in the performance gains compared to the old version.

Also, glad to see you're still working on this, keep it up ;)

Tyler

  • Posts: 5
  • Joined: Tue Mar 18, 2014 11:11 am

Re: Advanced Lighting (its still wip)

PostSat Mar 22, 2014 4:34 pm

Thanks for the update! Downloading it now ;) I saw some terrain in those screenshots, I truly look forward to playing with that!
User avatar

just1

  • Posts: 11
  • Joined: Tue Mar 25, 2014 2:04 pm

Re: Advanced Lighting (its still wip)

PostTue Mar 25, 2014 2:09 pm

Nice work Evolved!
You use texture atlas for your terrain system so you hve to use some code to avoid seems between tiles. Is it possible maybe to use volume texture for atlas? :idea: Have you ever have such idea?
User avatar

EVOLVED

Site Admin

  • Posts: 30
  • Joined: Wed Mar 05, 2014 7:52 am

Re: Advanced Lighting (its still wip)

PostFri Mar 28, 2014 6:09 pm

I have had a go at using 3d textures in past with in the old adv lighting sys, but mip mapping was an issue as well as performance. I also have no method of creating them through dbp.

Tyler

  • Posts: 5
  • Joined: Tue Mar 18, 2014 11:11 am

Re: Advanced Lighting (its still wip)

PostMon Apr 21, 2014 11:02 pm

Been playing with the new AdvLighting for the past week or so and I am loving it. I do however wish to submit a feature request that I think AdvLighting could greatly benefit from - flexibility with water.

Currently there can only be one piece of water that simply covers the world... We can adjust the height, sure - but what if we want multiple bodies of water, each with different params (color, wave speed/scale, etc.) in different places (a lake/pond in a mountain and an ocean below - both at different elevations - for example.)

Surely, it'd be as simple as using multiple 3d planes with the necessary shader effects applied, correct? Also, another thing that I noticed about the new water is that without an object (or terrain) below the water, the rendering acts up (I am going to assume this has something to do with the render targets.) I can provide a screenshot of this, if needed.

ilsanto74

  • Posts: 9
  • Joined: Thu Apr 24, 2014 11:22 am

Re: Advanced Lighting (its still wip)

PostThu Apr 24, 2014 11:28 am

Hi, I tried these Advanced Lighting and it is fantastic. But the new versions do not work anymore. I see everything black.
I tried to change the screen resolution, the value ID3D.
Attachments
Senza titolo-1.jpg
Senza titolo-1.jpg (42.98 KiB) Viewed 12040 times
Next

Return to Shaders