Skip to main content
gamedev.net
🔒 Locked

2d Shadows

Started by catch 6 replies 1.1k views
Original Post
catch
catch
Howdy. I'm curious if anyone has an article on 2d shadows. I mean convincing 2d shadows, not just blobs at sprite's feet. I can do direct opengl calls, and most of my game is actually opengl, but I'm using 2d sprites, not 3d geometry. Any simple way of doing this? I played with yaw/pitch/rotations and alpha blending to make a black version of my sprite and position it behind my sprites with some decent effect, but some things look right, many things don't.
"Creativity requires you to murder your children." - Chris Crawford
Lord_Evil
Lord_Evil
Maybe a shadow matrix might help.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Anthony Serrano
Anthony Serrano
Quote:
Original post by catch
Any simple way of doing this? I played with yaw/pitch/rotations and alpha blending to make a black version of my sprite and position it behind my sprites with some decent effect, but some things look right, many things don't.


Such a technique is generally never going to look very convincing.

Fundamentally, a 2D sprite is just a projection of some 3D object onto a plane; so taking that image and projecting it onto any other plane that is not parallel to the sprite's plane is almost always going to look incorrect. Specifically, shadows generated this way will always look wrong unless every point of contact between the sprite image and the ground lies in the same visual z-plane. (Since the contact points are the most visually apparent indicator of proper shadowing.)

Honestly, the best options (while still staying 2D) are to use either predrawn shadow sprites or the traditional shadow "blobs".
catch
catch
Interesting. I'll have to study this in more detail (at work now).

Course if I'm using no geometry, I'm not sure how this would generate an actual shadow. Hmm, gives me something to look into, though.

Thanks!
"Creativity requires you to murder your children." - Chris Crawford
catch
catch
Quote:
Original post by Anthony Serrano
Quote:
Original post by catch
Any simple way of doing this? I played with yaw/pitch/rotations and alpha blending to make a black version of my sprite and position it behind my sprites with some decent effect, but some things look right, many things don't.


Such a technique is generally never going to look very convincing.

Fundamentally, a 2D sprite is just a projection of some 3D object onto a plane; so taking that image and projecting it onto any other plane that is not parallel to the sprite's plane is almost always going to look incorrect. Specifically, shadows generated this way will always look wrong unless every point of contact between the sprite image and the ground lies in the same visual z-plane. (Since the contact points are the most visually apparent indicator of proper shadowing.)

Honestly, the best options (while still staying 2D) are to use either predrawn shadow sprites or the traditional shadow "blobs".


Yeah I'm sort of facing that. For trees and player graphics, and relatively smaller type objects, my current rotation and pitch changes look convincing enough.

The problem is large buildings and other thicker or more square looking shapes. The projection just looks all wrong.
"Creativity requires you to murder your children." - Chris Crawford
tonyg
tonyg
Could you have 'skinny' and 'fat' attribute for your shadow objects?
Skinny ones have the skewed shadow and fat objects have a shaded polygon?
Maybe the same principle as Dynamic 2D Softw Shadows
PlayfulPuppy
PlayfulPuppy
You'd probably be better of skewing/scaling the sprites to create the shadows rather than rotating them. You can do it through either a matrix or by creating a quad manually that looks like a parallelogram.

Just out of curiosity, what style of 2D are you doing here? Side-scroller, top down, isometric?
catch
catch
Ah yes, well right now i'm scaling them by a bit height wise, rotating them by a few degrees, and pitching them by about 60 degrees.

I wish I could post a screenshot, but I'm at work!

It's a top down style game.
"Creativity requires you to murder your children." - Chris Crawford

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.