Jump to content
  • Advertisement
Sign in to follow this  
Tiresias

OpenGL 2d sprite ground shadow

This topic is 3262 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i would like to have some input on this topic: how to create shadows of 2d sprites ? By shadows i mean ground shadow, to give the scene some more relief. Note that for drawing the scene and sprite i am using opengl + sdl. But opengl is only used 2d style. i guess that code shall be able to: - take a image (bmp png etc), be able to determine outline of the sprite, and project it on the ground. Is there code for this ? looks complicated for me, maybe it is not feasible. I mean what is the easiest but less elegant way to do is to have a shadow.png for each sprite, and draw it on the ground, thats it, but it will multiply by 2 the number of png files ... what do u advise?

Share this post


Link to post
Share on other sites
Advertisement
What kind of 2d are we talking here? Side-on platformer view or a slanty top-down Secrets Of Mana type view? Or something else?

Often you can get away with taking the regular sprite, squashing it vertically to about a half or a third of the size, blurring it, tinting it black and drawing it with transparency. That can all be done on-the-fly while drawing or precalculated in advance (like at level load time). It's not particularly accurate but it generally looks pretty good (certainly better than just blob shadows).

Share this post


Link to post
Share on other sites
On the fly way of doing it is easy - you make a blur function for the shader which samples the sprite alpha many times and then returns the blurred sample and in the pixel shader code.. "return shadow_color * blurred_alpha_function();".. :D

Share this post


Link to post
Share on other sites
Quote:
Original post by Tiresias
Secrets Of Mana type , view is from above,
i m interested in the on the fly stuff, any code around here ?


It's basically just
glDisable(GL_TEXTURE_2D);
glColor3f(0, 0, 0);
glEnable(GL_ALPHA_TEST);
glPushMatrix();
glScale(1, -0.5, 1); // mirror vertically, make it a little smaller for fake perspective effect
// draw sprite (for shadow)
glPopMatrix();

Blurring and alpha blending can be done in addition to that. I guess you wanted to hear the most basic version.

Share this post


Link to post
Share on other sites
Thanks to all,
special thanks to escapade, this piece of code is just beautiful coz of its simplicity and works perfectly :)

here is a screen of the result :)
www.Outremondes.com/ombres.JPG,

thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!