basic "blended" shadows on multiple layers

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
zingo
Citizen
Posts: 50
Joined: Mon Jan 16, 2023 7:34 am

basic "blended" shadows on multiple layers

Post by zingo »

I've not had much luck with "special fx" or "post-processing" stuff, and shaders are still mostly a complete mystery to me. That said, after perusing the stencil, canvas, and blendmode entries in the wiki, I did manage to cobble together something for simple sprite based "blended shadows" that looks nice enough.

What I could really use some help with, however, is adapting it to work with several "layers". That is, shadows drawn both above, and beneath other sprites, which are still properly blended with each other as they are in the attached example.

If there are already other threads in the forum for this, I apologize, but so far what I've found when searching for similar topics are several (somewhat dated), full-fledged light/shadow systems that are much more complex than I intend to use at this juncture.

Thank you in advance for taking the time to read this. I hope you are all having a great day, and that I'm not too much of a bother.
Attachments
blended_shadows.love
blended shadows, with stencil
(27.32 KiB) Downloaded 76 times
User avatar
marclurr
Party member
Posts: 111
Joined: Fri Apr 22, 2022 9:25 am

Re: basic "blended" shadows on multiple layers

Post by marclurr »

I had a look at your .love and through the code and to be honest I'm finding it hard to visualise what it is you're looking for. If you could put together a mock-up showing how you imagine the effect would work it might help show what you mean. :)
zingo
Citizen
Posts: 50
Joined: Mon Jan 16, 2023 7:34 am

Re: basic "blended" shadows on multiple layers

Post by zingo »

marclurr wrote: Wed Jul 19, 2023 7:24 am I had a look at your .love and through the code and to be honest I'm finding it hard to visualise what it is you're looking for. If you could put together a mock-up showing how you imagine the effect would work it might help show what you mean. :)
No problem, when I have a bit more time I'll make a little image showing what I'm going for (or, try to at least, I'm not the most artistic person in the world.) :)
zingo
Citizen
Posts: 50
Joined: Mon Jan 16, 2023 7:34 am

Re: basic "blended" shadows on multiple layers

Post by zingo »

Alright, so I hope this little image illustrates things a bit. The "cloud" shadow is drawn above both the sphere and the sphere's shadow.

What I'd like, is to have the "shadow" sprites -regardless of which order they are drawn- to be blended "equally"...which is to say, shadows drawn over the top of others should have matching alpha values, as shown, rather than darken each other by adding both alpha values together. In the .love example, this works well enough if all the shadows are drawn first, with nothing drawn between them...however, things get a bit tricky since I want to have shadows both above, and beneath, other objects that need to be drawn normally.

Maybe my ramblings (and horrible attempt at sprite art...something else I've been meaning to learn) makes some more sense now :?
Attachments
shadows_blended.png
shadows_blended.png (76.32 KiB) Viewed 6044 times
User avatar
marclurr
Party member
Posts: 111
Joined: Fri Apr 22, 2022 9:25 am

Re: basic "blended" shadows on multiple layers

Post by marclurr »

From the second of the two:
So I had to make a method, where the shadows of some objects can be drawn separately into one picture as 100% black shapes. Once the shadows are merged in the picture, they are drawn on the screen with 50% transparency and tadaaaa ... all the overlaps are gone.
This is literally what I was going to suggest. Keep a canvas just for shadows. Clear it to (0,0,0,0) and draw everything that casts shadows to it but in black (you might be able to just use the built in colour modulation, otherwise a really simple fragment shader can do it). Then render your ground, your shadows on top of it with alpha less than 1 and offset by whatever x and y values you decide on, then the rest of your sprites on top of that.
zingo
Citizen
Posts: 50
Joined: Mon Jan 16, 2023 7:34 am

Re: basic "blended" shadows on multiple layers

Post by zingo »

Thank you, everyone :) With your suggestions I (more or less) achieved the effect I was going for. However, I ended up having to use a second canvas and a sprite mask in order to properly draw shadows that appear directly on top of the sphere. Attached is the updated version. Any ideas for a better way to achieve the same result would be greatly appreciated, as this method may be somewhat convoluted for animated sprites.
Attachments
blended_shadows_v2.love
(6.16 KiB) Downloaded 76 times
Ross
Citizen
Posts: 99
Joined: Tue Mar 13, 2018 12:12 pm
Contact:

Re: basic "blended" shadows on multiple layers

Post by Ross »

An alternate method would be to "erase" the bottom layer of shadows from the canvas with your object layer before drawing the top shadows to it, and then draw the shadow canvas on top of everything. You can do it in one pass using a multi-canvas shader. Scroll down to where it describes the "void effect" function on the love.graphics.newShader page.
Attachments
r_blended_shadows_v3.love
(6.42 KiB) Downloaded 76 times
zingo
Citizen
Posts: 50
Joined: Mon Jan 16, 2023 7:34 am

Re: basic "blended" shadows on multiple layers

Post by zingo »

Thank you very much Ross, that is precisely the effect I was going for, lovely. I'll probably make a function for setting/updated the canvases and such, just to keep things more tidy. Again, many thanks to everyone.
Ross
Citizen
Posts: 99
Joined: Tue Mar 13, 2018 12:12 pm
Contact:

Re: basic "blended" shadows on multiple layers

Post by Ross »

Cool. I'm glad it was helpful. Good luck!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests