defold / sample-lights-and-shadows

Example of how to achieve pixel perfect shadows in a 2D view
MIT License
33 stars 5 forks source link

How to actually hide objects? #2

Closed haath closed 2 years ago

haath commented 2 years ago

Both in my project, as well as the example in this repository, shadows don't actually hide anything. All game objects just appear with full brightness on top of a black layer.

Ideally I'd like what you expect from a lighting system, that blend in with the darkness, and progressively disappear as they move further from light sources.

Is it possible to get such light/shadow effects with this library? Or more work in the render script is required?


Another issue I've been having, and maybe it's related, is that if I have a tilemap under the whole screen (topdown game) then there is no darkness, the whole map is fully lit. (with and without the light occluder material)

Apologies if I have just misunderstood what this library does! :sweat_smile:

Sayuris1 commented 2 years ago

Change the blend mode of the sprite or the tilemap to multiply.

haath commented 2 years ago

Change the blend mode of the sprite or the tilemap to multiply.

It worked, thanks!

haath commented 2 years ago

And any tips on how to make it so that the shadowed area is not fully black? For example to specify some ambient light color with some alpha. That way overshadowed objects could appear partially visible, and tinted to some color.

I imagine I'd have to somehow blend the shadows predicate with the tile predicate? But I have no idea where to start.

When it comes to rendering I'm still a complete beginner, so I could make do with any advice on how to get started. I've read the Defold render manuals, but I can't say it's gotten me very far...

Sayuris1 commented 2 years ago

Try to change the background color to something like vec4(0.1, 0.1, 0.1, 0). Maybe we should add a section about hiding objects to the manual ?

haath commented 2 years ago

Can't believe it was that simple and I missed it 😄

Thanks again!