Is there a way to emulate shadows of an image simply by drawing a black version of a sprite upside down (under the original), but with a slant calculated from where the "light source" is? Any ideas?
It seems like the slanting can be done wither with a shader or love.transform, the same with upside down (but maybe also using angles).
A way to do simple shadows
- Gunroar:Cannon()
- Party member
- Posts: 1142
- Joined: Thu Dec 10, 2020 1:57 am
Re: A way to do simple shadows
You can simply use the scale and shear arguments of love.graphics.draw() and some trigonometry to transform the shadow. Here's an example that handles a light source from any direction:
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
- BrotSagtMist
- Party member
- Posts: 657
- Joined: Fri Aug 06, 2021 10:30 pm
Re: A way to do simple shadows
This _example_ looks way more awesome than it should for such a little piece of code
obey
Re: A way to do simple shadows
Absolutely. Brilliant.
Re: A way to do simple shadows
I love how stuff in front of the light source gets silhouetted. Amazing!
EDIT: Just for funsies, here's a modified version where the light source follows the mouse instead.
EDIT: Just for funsies, here's a modified version where the light source follows the mouse instead.
- Attachments
-
- SimpleShadows.love
- (3.24 KiB) Downloaded 173 times
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
- Gunroar:Cannon()
- Party member
- Posts: 1142
- Joined: Thu Dec 10, 2020 1:57 am
Re: A way to do simple shadows
You are all beautiful people
Though it's looking... flat. Like it those paper -style GE's like Don't Starve and Paper Mario. I don't even know how one would go about making the shadows more 3D looking. Still looks wonderful though!
Though it's looking... flat. Like it those paper -style GE's like Don't Starve and Paper Mario. I don't even know how one would go about making the shadows more 3D looking. Still looks wonderful though!
Re: A way to do simple shadows
Well, the sprites are flat, so all you can get are flat shadows. You'd need 3D geometry to some extent for more 3D-looking shadows. Since they look the most flat when the light comes from the side it could be a good idea to design your game/levels such that that situation doesn't happen.
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
Re: A way to do simple shadows
Just awesome!
Re: A way to do simple shadows
Put simply, it's what can be done using slant and size alone, which is what the OP specified.
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've been thinking what it would take to make it look right in that sense, but I couldn't think of anything short of a shader. And even with a shader it sounds tricky.
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've been thinking what it would take to make it look right in that sense, but I couldn't think of anything short of a shader. And even with a shader it sounds tricky.
Re: A way to do simple shadows
Wow, this example is amazing. There should be a repo to collect gems like this.
Who is online
Users browsing this forum: No registered users and 3 guests