• entries
    743
  • comments
    1924
  • views
    580395

Lit spheres in 2D

Sign in to follow this  

117 views



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.
Sign in to follow this  


5 Comments


Recommended Comments

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.

Share this comment


Link to comment
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]

Share this comment


Link to comment
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].

Share this comment


Link to comment
Nice method on faking the shading. If it works, then that's all that matters in the end.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now