views:

154

answers:

1

I'm making a game where the game's size varies, so I want to make my own shadows. The api i'm using can fill rectangles, make ellipses, horizontal lines etc. And supports rgba. Given this, how could I make a drop shadow? I tried making a black to white gradient and setting the alpha to 20%, but it didnt look very good... I'm not sure how they are done. Thanks

+2  A: 

I would suggest:

  1. copy the object,
  2. move it in the opposite direction of the light source and use its distance as a weight,
  3. turn it totally black,
  4. blur it using the light source's distance as a weight, too,
  5. put it behind the object,
  6. lower the alpha if you want.
  7. ?????
  8. profit.
Camilo Martin
And use a multiplying blend mode, if you have the choice.
Mark Ransom
multiplying is a photoshop thing that is not easy to implement, in fact it can be very expensive CPU-wise if badly implemented since you have to deal with pixel calculation.
Camilo Martin
@Camilo: A lot of APIs that do multiply blending (such as Cairo and OpenGL) push it to the graphics card whenever possible, and implementations tend to be quite fast.
greyfade
Oh, I was thinking it the brain-dead way :) But those APIs also must have some useful shadow effect or at least make it trivial to implement, right?
Camilo Martin