Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Dynamic Lighting [UnNamed]  (Read 6533 times)

0 Members and 1 Guest are viewing this topic.

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Dynamic Lighting [UnNamed]
« on: January 06, 2017, 07:59:01 am »
I've written a small dynamic lighting system for use in our engine.  It only casts hard shadows ( :( ) but I can have as many light as we need and as many shadow casting polygons as needed.

The algorithm doesn't sort any edges, so the geometry can be dynamic. It just needs to know the starting and ending point for each edge.

The algorithm is additive, so it does a sort of ray casting (can increase/decrease the number of rays cast) and traces out its path, keeping track of the edge closest to it. Whenever it falls off an edge and reaches another one, it uses that info to construct the area to draw the illuminated texture onto.  It uses a fragment shader to build its own texture depending on the kind of light, so you could make the light look however.

It's still very much a work in progress, but I thought I'd see what you guys think.  Still need to work on the shadow blending, since a shadow will still partially show if another light is over it.


https://www.youtube.com/watch?v=o2lpwo10Bf8&feature=youtu.be

It's certainly nothing compared to LTBL/LTBL2, but given that this is also part of a college project, I want to try to write as much of it from scratch as I can. 
If for some reason you want to see the code, it's here: https://github.com/JayhawkZombie/RayCasting

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Dynamic Lighting [UnNamed]
« Reply #1 on: January 06, 2017, 11:25:37 am »
Pretty neat! :)

Also I quite like the explanations you added, especially that one GIF on GitHub. Makes it so much easier to kind of understand what is going on.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Dynamic Lighting [UnNamed]
« Reply #2 on: January 07, 2017, 11:53:14 am »
Shameless self-bump!

I updated the lighting system.  It looks (in my opinion) much more realistic now.

It renders the illumination areas to a render texture separately, and blurs it slightly.
It renders the geometry to a different render texture, and then uses one last fragment shader with both render textures as inputs.  It uses the illumination texture as a sort of light map and alters the intensities of the pixels based on the intensity of the fragment in the light map.  The brighter the area, the higher the intensity increase; the darker the area in the lightmap, the darker the area will appear in the scene.

There are a couple videos of it in play: 




Here's one example


Here's another example with the weight on the light's color turned up, the max intensity turned down a bit, and the minimum intensity turned down.





The shadows seem to blend pretty nicely together now.  There are a few artifacts and occasional flicker I need to fix, but I want to get it looking as nicely as possible first.

I now have 3 fragment shaders I'm using:
Lighting_Frag.fsh, which just creates the radial gradient (stolen from your Wiki).
BlurShader.fsh (pretty self-explanatory)
MaskShader.fsh, which takes parameters as inputs and adjusts the geometry texture using the light map texture.

uniform sampler2D MaskTexture - The lightmap
uniform sampler2D SceneTexture - The pre-rendered geometry

uniform float MinimumIntensity - The darkest you want a pixel (so it isn't completely black, not bad for keeping a dark ambient light)

uniform vec4 LightHue - The color of light being emitted by the source
uniform float HueIntensity - How heavily you want the hue to influence the hue of the final fragment
uniform float MaximumIntensity - The maximum intensity to apply. Useful to avoid getting totally washed out.

In the second picture, the values are:
MinimumIntensity = 1.0f
HueIntensity = 0.9f
MaximumIntensity = 5.0f

I still need to work on some of the shadows flickering, but it's acceptable right now.  I'll also probably update the raycasting to more efficiently query the geometry, probably using a QuadTree or something.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Dynamic Lighting [UnNamed]
« Reply #3 on: January 07, 2017, 04:35:21 pm »

Excelent work, hope i could contribute to this project in the near future and integate it on my enigne too.
I would like a spanish/latin community...
Problems building for Android? Look here

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Dynamic Lighting [UnNamed]
« Reply #4 on: January 07, 2017, 10:34:12 pm »
Haven't had a look so far. Does it support colored lights as well?

JayhawkZombie

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Dynamic Lighting [UnNamed]
« Reply #5 on: January 08, 2017, 12:52:57 am »

Excelent work, hope i could contribute to this project in the near future and integate it on my enigne too.
Thanks! By all means! I welcome any advice/contributions!

Haven't had a look so far. Does it support colored lights as well?
Sure, but the colors are a little less subtle in the newest version.  In the first picture, the light have a blue-ish tint. In the second, they have a magenta tint.

This is what the logo in the background (darkened) looks like without the light's colors affecting it:


Now I'm playing with some godrays

(I went a little overboard with the sample rate, texture fetches are killing the fps)

 

anything