A way to do simple shadows

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: A way to do simple shadows

Post by Gunroar:Cannon() »

milon wrote: Wed Sep 21, 2022 4:37 pm EDIT: Just for funsies, here's a modified version where the light source follows the mouse instead.
Was useful to really let the "example" shine.
pgimeno wrote: Wed Sep 21, 2022 7:40 pm Put simply, it's what can be done using slant and size alone, which is what the OP specified.
Yeah, it even exceeded expectations with the glare and everything else ReFreezed added :3
In fact, slant does not produce correct results even admitting that the object is 2D. Since the light is a point, each side of the object should have a different angle with respect to the light, resulting in a shape for the shadow with diverging sides, not parallel.
I was thinking of a way to explain it, and yeah, this is what I was imagining. The shadow should ...slant? I'll just let my pictures do the talking.

So any way to make it diverge like that?
Attachments
Straight(ish) shadow
Straight(ish) shadow
straight.png (1.43 KiB) Viewed 2866 times
more natural slant
more natural slant
slant.png (1.55 KiB) Viewed 2866 times
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
BrotSagtMist
Party member
Posts: 604
Joined: Fri Aug 06, 2021 10:30 pm

Re: A way to do simple shadows

Post by BrotSagtMist »

With a point the shadow will get wider, not narrower tho.

If the lightsource is an area it may work to fill this area with source points and create a few dozen half transparent shadows instead one based on all these points.
That should look natural.
obey
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: A way to do simple shadows

Post by Gunroar:Cannon() »

BrotSagtMist wrote: Wed Sep 21, 2022 10:24 pm With a point the shadow will get wider, not narrower tho.
Yeah, I guess. Though I think it depends sometimes (like maybe if perspective is considered or something :?)
If the lightsource is an area it may work to fill this area with source points and create a few dozen half transparent shadows instead one based on all these points.
That should look natural.
... I don't know how to do that :( :ultrahappy:
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
BrotSagtMist
Party member
Posts: 604
Joined: Fri Aug 06, 2021 10:30 pm

Re: A way to do simple shadows

Post by BrotSagtMist »

you run the code twice...

Edit: Had to try this for fun:
shm.love
(3.91 KiB) Downloaded 107 times
These are softer shadows rendered three times. Just copy the shadow part with an X offset to make the shadows as fine as you like.

This can be tweaked to look quite nice but i think we will get performance problems rather fast.
obey
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: A way to do simple shadows

Post by Gunroar:Cannon() »

Ahh, I guess it's better.
These shadows are da-best.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: A way to do simple shadows

Post by ReFreezed »

I spent some more time adding to the "example". It fixes the perspective issue pgimeno mentioned (using shaders, tears, and blood from an eldritch beast), and you can tweak the light's height and strength dynamically. I'd say the project has moved beyond simple at this point.

Code is here: https://github.com/ReFreezed/LoveFlatShadows
.love file at the bottom of the post.
Screenshot 2022-09-24.png
Screenshot 2022-09-24.png (148.1 KiB) Viewed 2720 times
FlatShadows.20220924.love
(6.01 KiB) Downloaded 91 times
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: A way to do simple shadows

Post by pgimeno »

Awesome! Very well done.

But it's still not 3D... /s

(maybe the OP should remove the word "simple" from the title)

Edit: After looking into the code a bit, this thread came to my mind: viewtopic.php?f=5&t=12483
Last edited by pgimeno on Sat Sep 24, 2022 8:04 pm, edited 1 time in total.
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: A way to do simple shadows

Post by GVovkiv »

ReFreezed wrote: Sat Sep 24, 2022 7:28 pm I spent some more time adding to the "example". It fixes the perspective issue pgimeno mentioned (using shaders, tears, and blood from an eldritch beast), and you can tweak the light's height and strength dynamically. I'd say the project has moved beyond simple at this point.

Code is here: https://github.com/ReFreezed/LoveFlatShadows
.love file at the bottom of the post.
It's amazing how people can achieve something like this easly, while i myself sometimes might struggle with something like "soemthing = something1" instead of "something = something1" and unironically waste 10 mins trying to understand where i made mistake
User avatar
ReFreezed
Party member
Posts: 612
Joined: Sun Oct 25, 2015 11:32 pm
Location: Sweden
Contact:

Re: A way to do simple shadows

Post by ReFreezed »

GVovkiv wrote: Sat Sep 24, 2022 7:58 pm It's amazing how people can achieve something like this easly, while i myself sometimes might struggle with something like "soemthing = something1" instead of "something = something1" and unironically waste 10 mins trying to understand where i made mistake
Heh, well you don't know the (many painful) hours it took me to fix the darn perspective issue. :death:
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

Re: A way to do simple shadows

Post by Gunroar:Cannon() »

(maybe the OP should remove the word "simple" from the title)
:rofl:
pgimeno wrote: Sat Sep 24, 2022 7:52 pm Awesome! Very well done.

But it's still not 3D... /s
Doesn't need to be 3D. just appear so. This version is better and still wonderful, but yes, it still gives of that paper-vibe a little...
but it gives it off wAAAY less than before. Especially since it can be tweaked. Nice job.

And...ehem...I...heheheh...Yes, this passes the scope of the topic and the thread is already solved but since we're just saying...the shadows are fine now and I think what makes it look 2D now is the... shading on the objects themselves (*runs away*)
GVovkiv wrote: Sat Sep 24, 2022 7:58 pm struggle with something like "soemthing = something1" instead of "something = something1" and unironically waste 10 mins trying to understand where i made mistake
That's the worst :crazy:

Oh, and
ReFreezed wrote: Sat Sep 24, 2022 7:28 pm (using shaders, tears, and blood from an eldritch beast
Wondering how you got the eldritch blood (asking for a friend)...
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: darkfrei and 17 guests