RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
Directional lighting and 2D sprites: Normal maps are awesome
 
Post new topic Reply to topic Goto page 1, 2  Next 
View previous topic - View next topic  
Author Message
janus
Mage


Joined: 29 Jun 2002
Posts: 464
Location: Issaquah, WA

PostPosted: Sun Oct 30, 2005 2:11 pm    Post subject: Directional lighting and 2D sprites: Normal maps are awesome [quote]


(Click for video; DivX 6.0, ~4MB)
Anybody interested in seeing an article that explains the techniques used in this video? I've been thinking about writing a nice detailed article on doing 2D lighting, but now that I've implemented this normal mapping technique (that as far as I can tell, has only been used in 2D by one other person), I think it's definitely worth documenting it so other people can use it. :)

A short laundry list of the techniques and primitives used in this video:
Normal mapping
Convolution filtering (gaussian blur, specifically)
Alpha masking
Gradient polygon rendering
Radial gradients
Offscreen surface rendering/render-to-texture (this particular video was recorded running in OpenGL, though the algorithms also work fine in software, albeit slower)
Lightmap rendering
Raycasting

And of course, if you have questions (or suggestions!) you can just post them here too. :)
Back to top  
Ninkazu
Demon Hunter


Joined: 08 Aug 2002
Posts: 945
Location: Location:

PostPosted: Sun Oct 30, 2005 2:34 pm    Post subject: [quote]

Hell ya that'd be great.
Back to top  
Gooseman
Wandering Minstrel


Joined: 25 Jul 2005
Posts: 92
Location: England

PostPosted: Sun Oct 30, 2005 6:48 pm    Post subject: [quote]

Woah that video is cool! I'd love to know how it was done, even if it doesn't help me replicate it in any way, shape or form.
Back to top  
bay
Wandering Minstrel


Joined: 17 Mar 2004
Posts: 138
Location: new jersey, usa

PostPosted: Wed Nov 02, 2005 3:52 pm    Post subject: [quote]

perhaps the beginning to a game/graphix programming book career?

.02$
Back to top  
Adam
Mage


Joined: 30 Dec 2002
Posts: 416
Location: Australia

PostPosted: Wed Nov 02, 2005 4:35 pm    Post subject: [quote]

Mucho grande swank. I coudn't even clone your old lightining engine well enough so how am i meant to do this? :P
_________________
https://numbatlogic.com
Back to top  
Verious
Mage


Joined: 06 Jan 2004
Posts: 409
Location: Online

PostPosted: Wed Nov 02, 2005 6:07 pm    Post subject: [quote]

Whoa! That video was well worth the DivX codec install. I'de love to know how you achieved those lighting and physics effects. I really like how the objects cast shadows and how objects react to the explosions.

I'm definately interested in the article.
Back to top  
RuneLancer
Mage


Joined: 17 Jun 2005
Posts: 441

PostPosted: Wed Nov 02, 2005 10:35 pm    Post subject: [quote]

That looks incredible! Although, hate to burst your bubble, it's not 2D. It's rendered using a 2D projection with a 3D API (OpenGL.) A lil' less impressive, because true 2D would require (most likely; unless someone came up with a really stunning algorithm) per-pixel calculations to acheive an effect like this. Heavy, especially without the use of a pixel shader to speed up the operations.

Unless everything's rendered to a texture and OpenGL's just used to get things onscreen. ;) Then, well, forget what I said: that's definately impressive.

Nevertheless, it's a very impressive application of normal mapping and calculated shadows. Objects cast very realistic shadows and, quite frankly, it's a lot more than I could come up with. I'd love to know how to pulled it off (and what specs the demo ran on.) Great work!
_________________
Endless Saga
An OpenGL RPG in the making. Now with new hosting!

Back to top  
janus
Mage


Joined: 29 Jun 2002
Posts: 464
Location: Issaquah, WA

PostPosted: Thu Nov 03, 2005 6:11 am    Post subject: [quote]

RuneLancer wrote:
That looks incredible! Although, hate to burst your bubble, it's not 2D. It's rendered using a 2D projection with a 3D API (OpenGL.) A lil' less impressive, because true 2D would require (most likely; unless someone came up with a really stunning algorithm) per-pixel calculations to acheive an effect like this. Heavy, especially without the use of a pixel shader to speed up the operations.

Unless everything's rendered to a texture and OpenGL's just used to get things onscreen. ;) Then, well, forget what I said: that's definitely impressive.

Nevertheless, it's a very impressive application of normal mapping and calculated shadows. Objects cast very realistic shadows and, quite frankly, it's a lot more than I could come up with. I'd love to know how to pulled it off (and what specs the demo ran on.) Great work!
It actually can run in full software mode using GDI to draw the result framebuffer. That's one of the reasons it's been in development for nearly two years ;)

Most of the work was coming up with hacks and abstractions that would let me pull things off relatively quickly in software, because the high-quality simulations ran far too slow (for example, I have to do some raycasting for certain parts of the scene, but doing raycasting for every pixel would be FAR too slow, so I use some approximations to render whole groups of pixels in one pass.)

For example, a recent addition:

It's simpler than it looks - only took about 30 minutes to add, mostly due to the way the engine works. :)
Back to top  
bay
Wandering Minstrel


Joined: 17 Mar 2004
Posts: 138
Location: new jersey, usa

PostPosted: Thu Nov 03, 2005 4:13 pm    Post subject: [quote]

janus wrote:
Most of the work was coming up with hacks and abstractions that would let me pull things off relatively quickly in software, because the high-quality simulations ran far too slow (for example, I have to do some raycasting for certain parts of the scene, but doing raycasting for every pixel would be FAR too slow, so I use some approximations to render whole groups of pixels in one pass.)


p i m p

i can't wait to read your documentation of such feats.

.02$
_________________
INTJ
Back to top  
Ren
Wandering Minstrel


Joined: 07 Aug 2004
Posts: 130
Location: turn around...

PostPosted: Thu Nov 03, 2005 7:53 pm    Post subject: [quote]

Very neat demo. I wouldn't read the article (i'm not a code-phile really), but I love the way it looks, great stuff.

Verious wrote:
Whoa! That video was well worth the DivX codec install.


The what now? Remember guys, VLC is your friend.
_________________
Previous nicks: MidnightDreamer, The_Anarchist, Shroomasta.

ren-tek.net : BGC games and more!
Back to top  
RuneLancer
Mage


Joined: 17 Jun 2005
Posts: 441

PostPosted: Thu Nov 03, 2005 9:11 pm    Post subject: [quote]

Nice. :)

So you basically did some interpolation and whatnot here and there to keep down the amount of pixels to calculate? That brings me back, heh... Reminds me of a raycaster I wrote for a college course (realtime! In those days, it was something rather new and PCs had a hard time keeping up with a full-screen retrace every frame.)

Little trick I had that may or may not apply to your situation was to cast a ray. When it'd hit an object, I'd do whatever (calculate the color/texture, etc..) Next ray, I'd start MUCH closer to the object (a few pixels away from where the previous one hit). This cut down tremendously on the amount of time spent casting rays in the scene. How I did this was based on a few assumptions and precalculated stuff: first of all, an object fit within a sphere of 'x' size and didn't have any awkward angles jutting out crazily (so the surface was smooth.) Second, I kept a "map" of how distant objects were from the viewpoint so I would know when a ray would intersect something and when I'd have to start calculating the ray from scratch.

Eh, I suck at explaining. Picture this: you have 5 spheres (traditional raytracer objects :P ) As you move around, you keep a list of vectors indicating the distance of the object, its size (as in, the smallest sphere that could contain the object's radius), and its relative position to the viewpoint (another vector.) When casting a ray, a very rough approximation is made to see if any of the 5 spheres are in the way. If not, the ray isn't traced (since it would be guaranteed not to hit an object.) If there's a sphere in the way, however, an approximation is made to determine how close is "close enough" without being "inside" the object (using the radius of its bounding sphere) and the tracing begins from there.

I'm guessing you raytrace to figure out if light hits an object or not. Making a rough calculation to see which range from the lightsource doesn't hit a sprite could allow you to skip a chunk of rays and go straight to the drawing phase. Or to figure out which ones DO hit an object and just skip straight to figuring out the object's outline.

Dunno if it's of any help. That was 2 years ago, and the only recent code I've written involving lighting is lazy 3D lighting done by the graphic card for me. :P
_________________
Endless Saga
An OpenGL RPG in the making. Now with new hosting!

Back to top  
tcaudilllg
Dragonmaster


Joined: 20 Jun 2002
Posts: 1731
Location: Cedar Bluff, VA

PostPosted: Fri Nov 04, 2005 12:30 am    Post subject: [quote]

Those are amazing shadows. Good work.
Back to top  
Terry
Spectral Form


Joined: 16 Jun 2002
Posts: 798
Location: Dublin, Ireland

PostPosted: Mon Nov 14, 2005 12:49 am    Post subject: [quote]

How much work is involved in doing something like this? There's a section of my game that would really benifit from a lighting effect like this. At the moment, I'm using an animated 2D lightmap with tiles blended on top of the regular one, which doesn't compare...

Well, I'm very definitly interested in a tutorial like that.
_________________
http://www.distractionware.com
Back to top  
BadMrBox
Bringer of Apocalypse


Joined: 26 Jun 2002
Posts: 1022
Location: Dark Forest's of Sweden

PostPosted: Mon Nov 14, 2005 4:57 pm    Post subject: [quote]

Can you put together a movie with the pink and yellow effects? Or rather, a exe? Would very much like run around in a room blowing things up.
I like your stuff :)
_________________
Back to top  
Verious
Mage


Joined: 06 Jan 2004
Posts: 409
Location: Online

PostPosted: Fri Nov 25, 2005 3:32 pm    Post subject: [quote]

Janus:

Have you made any progress on the creation of an article/tutorial describing the lighting techniques used in your engine/video?
Back to top  
Post new topic Reply to topic Page 1 of 2 All times are GMT
Goto page 1, 2  Next 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum