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.
basic "blended" shadows on multiple layers
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
basic "blended" shadows on multiple layers
- Attachments
-
- blended_shadows.love
- blended shadows, with stencil
- (27.32 KiB) Downloaded 111 times
Re: basic "blended" shadows on multiple layers
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.
Re: basic "blended" shadows on multiple layers
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.)
Re: basic "blended" shadows on multiple layers
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
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
Re: basic "blended" shadows on multiple layers
From the second of the two:darkfrei wrote: ↑Thu Jul 20, 2023 6:57 am Looks like
https://www.factorio.com/blog/post/fff-42
https://www.factorio.com/blog/post/fff-56
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.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.
Re: basic "blended" shadows on multiple layers
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 104 times
Re: basic "blended" shadows on multiple layers
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 118 times
Re: basic "blended" shadows on multiple layers
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.
Re: basic "blended" shadows on multiple layers
Cool. I'm glad it was helpful. Good luck!
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests