[Tutorial] A real dynamic light system

1 favourites
From the Asset Store
Carousel Animation, make carousel of you image gallery or anything
  • Well, you can do quite well already with a few layer effects and techniques - here's an example with 2 moving lights casting shadows, each with fade-out: https://dl.dropboxusercontent.com/u/15217362/2waylight.capx

    It does become difficult though when the lights move further apart. Because they draw shadows instead of light, it's quite tricky if one light is casting a shadow over another. It's hard to make it brighten the shadow back to lightness.

    The best approach is to start with darkness, and then add lights on top, additively blending so they contribute light. This means later lights can light up areas that are in the shadow of other lights. It also makes colored lights easy. Then you can multiply-blend the resulting "lighting map" with the background, and it applies lighting to the game.

    I thought we'd need nested layers to do this, but no! It's also already possible: https://dl.dropboxusercontent.com/u/15217362/3waycoloredlights.capx

    The real trick is multiply is associative. It's hard to have your background and then have multiple lights on top of that, because it's difficult to render the lights together and then multiply blend the end result without nested layers. So - you can render all the lights first, and multiply the background on top of that! It works out the same because a x b is the same as b x a, so the ordering doesn't matter. So here the crux of the trick is you'll notice the background layer on top of all the lights.

    You're right, this would make a good tutorial

    Links are not working ^^''

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • megatronx

    Links are working fine - already downloaded and tested.

  • Ashley , The trick with multiplying the background on top of the lights is clever indeed. However I'm not sure how it will work with multiple layers, like when we want to achieve parallax, or other z ordering effects. To be quite frank, while a tutorial would be very muck appreciated, this looks like a hack, a workaround the issue rather than a proper lighting implementation.

    And there is still the problem with the artifacts... If we use adjacent sprites, there is a chasm between them, breaking the effect of continuous surfaces. Please see the following example.

    https://www.dropbox.com/s/pl70s7bu4wtib ... .capx?dl=0

    There is a workaround with one light by using the alpha threshold effect, but this doesn't apply with multiple lights.

    Also, all of the above doesn't cover the normal-bump map subject.

    Anyway, thank you for the examples, they are really cool!

    ps megatronx , I can confirm that the links do work!

  • It's a good effect but it's significantly limited by the requirement to use one layer for each light.

  • Here's a tutorial I wrote up: Multiple colored shadow casting lights

    Nested layers would be really helpful for this. It avoids the need for the hack, and then you can apply lighting to more than one layer as well. It's a complicated feature. Perhaps we could look in to it some time after C3's release.

    eli0s - adjacent sprites are a really difficult problem if you're enabling penumbras (soft edges). Each object is rendered individually, so the result is correct for doing that, but unrealistic if objects are exactly adjacent. I'm not sure right now how to modify the algorithm to account for that. One straightforward workaround is to use extra shadowcaster objects to plug the gaps, or use different invisible shadowcaster objects to the ones which are visible.

  • It was one of the extensions i have installed. Thanks folks!

    Ashley Thanks for the tutorial. A question: do you think you could include shadow map generation in c3 for static shadows ( and we could use blending modes on them for example )?

  • Excellent tutorial, Ashley - thank you.

    Time to experiment with how many layers I can get away with...

  • Ashley is it possible to add normal maps to sprites and have the desired effects when in a scene are more than one lights?great tutorial thanks a lot.

  • Thank you for the useful tutorial Ashley .

  • Lol I'd settle for shadow casters that weren't additive like in Thomas was alone.

    http://store.steampowered.com/app/220780/

  • Lol I'd settle for shadow casters that weren't additive like in Thomas was alone.

    http://store.steampowered.com/app/220780/

    I agree.

  • Edit. Thinking about this - what would be great is having an ability to create (during runtime) a combined shadow + colour sprite, that behaves as one object and fades over a defined distance as per Ashley's demo.

  • Ashley , The trick with multiplying the background on top of the lights is clever indeed. However I'm not sure how it will work with multiple layers, like when we want to achieve parallax, or other z ordering effects.

    It is impossible to use this technique and parallax layers - or am I missing something?

  • Colludium i got a problem too with parallax i make some changes but still when in parallax shadows are in different places so an idea will be helpfull.

  • spy84 - it appears to be impossible because of the way the layers are rendered, but I await advice from anyone with more experience of doing this than I have. I suspect that we will need to be able to render a group of layers together before then rendering that on top of layers we want to appear behind.... I might try some experimenting with the Canvas plugin to see if I can get that to work.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)