Lit spheres in 2D

Published June 11, 2009
Advertisement


Just finished implementing a very efficient and I think pretty effective way of fake-shading 2D spheres so they look good when they rotate. You can see the problem with traditional graphics in my last post where the highlights and shadows rotate with the spheres, looking terrible.

The above image does not do this new method justice - you need to see it in motion so have a look at
">this quick YouTube video to see what I mean. Notice how the spheres rotate but the shading remains constant.

It's a pretty simple technique. I just render a special effect quad over the actual sphere.

(NB: I make alpha-containing images using two bitmaps - the colour channel then a red-black image representing the alpha. I have a utility that combines these into my own image format.)

The sphere itself is flat shaded. For example, the earth has the following colour and alpha maps (the alpha map was drawn at a larger size then smart-sized down to smooth out the edges of the circle shape):



Stored somewhere else on the texture atlas is the special sphere light texture, which is composed of the following colour and alpha maps:



The alpha map was just made with a fairly simple Paint Shop Pro gradient fill.



By rendering the flat sphere at the appropriate rotation, then rendering the above effect texture over the top at a fixed rotation, the above effect comes to life.

Obviously the same light map can be applied to any circular shape to get the same effect - in the image above, the oranges and the globes are both using the same light map.

Now, encoded into each quad in an actor's quad list is a DWORD of flags, the only one at the moment being the "sphere highlight" flag. If this flag is set when a quad is rendered, the system automatically alphablends the above texture over the top of it.

So with basically four textured triangles, two for the quad and two for the light map, I get a really nice, solid-feeling but freely rotating sphere.
Previous Entry Multi-quad shapes
Next Entry Buzzsaws
0 likes 5 comments

Comments

rip-off
Looks really good.
June 11, 2009 02:32 PM
Aardvajk
Quote:Original post by rip-off
Looks really good.


Thanks. The idea occurred to me at about 3am last night and I've been itching all day at work to try it [smile]. Turned out better than I thought.
June 11, 2009 02:56 PM
HopeDagger
I'm hugely impressed with your progress on Squishy. It's been a month since I last laid eyes on Journal Land, so you can imagine my delight when I got to check out all of the new goodies you've since added. The degree of polish in particular really speaks volumes to the amount of work that you've put into this project. For god sakes, man, keep up the good work! [grin]
June 11, 2009 09:04 PM
Aardvajk
Quote:Original post by HopeDagger
I'm hugely impressed with your progress on Squishy. It's been a month since I last laid eyes on Journal Land, so you can imagine my delight when I got to check out all of the new goodies you've since added. The degree of polish in particular really speaks volumes to the amount of work that you've put into this project. For god sakes, man, keep up the good work! [grin]


Thanks and hopefully will do [smile].
June 12, 2009 02:08 AM
MrCpaw
Nice method on faking the shading. If it works, then that's all that matters in the end.
June 12, 2009 08:04 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement