[Tutorial] A real dynamic light system

Discussion and feedback on Construct 2

Post » Thu Mar 03, 2016 4:09 pm

Ashley wrote: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 ^^''
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
76
S
20
G
19
Posts: 1,931
Reputation: 17,159

Post » Thu Mar 03, 2016 4:12 pm

@megatronx

Links are working fine - already downloaded and tested.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
126
S
29
G
73
Posts: 5,089
Reputation: 51,998

Post » Thu Mar 03, 2016 4:24 pm

@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!
composer - multimedia artist
www.eli0s.com/en/
B
63
S
26
G
4
Posts: 1,145
Reputation: 9,517

Post » Thu Mar 03, 2016 4:51 pm

It's a good effect but it's significantly limited by the requirement to use one layer for each light.
B
68
S
17
G
65
Posts: 2,184
Reputation: 41,308

Post » Thu Mar 03, 2016 4:54 pm

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.
Scirra Founder
B
378
S
220
G
84
Posts: 23,868
Reputation: 188,111

Post » Thu Mar 03, 2016 4:58 pm

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 )?
Last edited by megatronx on Thu Mar 03, 2016 5:02 pm, edited 1 time in total.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
76
S
20
G
19
Posts: 1,931
Reputation: 17,159

Post » Thu Mar 03, 2016 5:00 pm

Excellent tutorial, @Ashley - thank you.

Time to experiment with how many layers I can get away with...
B
68
S
17
G
65
Posts: 2,184
Reputation: 41,308

Post » Thu Mar 03, 2016 5:40 pm

@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.
B
18
S
3
G
1
Posts: 248
Reputation: 2,348

Post » Thu Mar 03, 2016 8:10 pm

Thank you for the useful tutorial @Ashley .
B
122
S
31
G
17
Posts: 1,468
Reputation: 19,955

Post » Thu Mar 03, 2016 8:53 pm

Lol I'd settle for shadow casters that weren't additive like in Thomas was alone.
http://store.steampowered.com/app/220780/
Image ImageImage
B
164
S
49
G
138
Posts: 7,960
Reputation: 91,886

PreviousNext

Return to Construct 2 General

Who is online

Users browsing this forum: X3M and 7 guests