Sign in to follow this  
Waaayoff

2D lighting for a side-scroller?

Recommended Posts

Waaayoff    952
I want to add lighting to my game and there will be both static lights and moving ones. I'm using D3DXSPRITE to draw all the tiles and was wondering if it supports lighting?

If it doesn't, should i manipulate the sprite's ARGB values to add lighting effects or should i ditch it and just use textured quads with normals?

Share this post


Link to post
Share on other sites
Noggs    141
What effect are you hoping to achieve? You can have some kind of approximation of lighting if you create a normal map for your sprites and light it using a pixel shader. There's no way of doing it using fixed function. You might struggle to generate a normal map from your sprites without any 3d surface information though.

I don't know what you mean by modifying the ARGB values of your sprite, but if you are referring to doing the lighting yourself on the CPU by modifying the texture directly each frame, then that is almost certainly a bad way to do it. Normal mapped pixel shader would be the better approach.

Share this post


Link to post
Share on other sites
Waaayoff    952
I meant that when the lights move, i calculate which tiles are affected (i implemented a grid system) and then change their (I'm guessing the vertices) colour. If i want to make the tiles lighter, i just increase the RGB value, if i want it to get dimmer, i decrease it..

Anyway so i take it D3DLIGHT9 has no effect of D3DXSPRITE?

Share this post


Link to post
Share on other sites
Noggs    141
Oh ok so you just want to light the sprites as if they were flat quads. In that case you don't need to worry about normals.

If you are happy with each sprite having a uniform lighting colour then the easiest way would be to calculate the amount of light falling on a sprite and render it with that colour. If it's in full light it will be white, full darkness would be black.

If you need the sprite to be lit partially (one corner bright, the other dark) then you will need per-pixel lighting. D3DLIGHT won't be any good for this. I'm afraid you're going to have to delve into the seemingly murky world of shaders and effects (which is actually quite straightforward once you get started).

Share this post


Link to post
Share on other sites
WavyVirus    884
Another approach is to create a "light map" texture, which you can draw over the entire screen (perhaps using a multiply blend) after all of your sprites have been rendered. You can pre-create a texture with all of the static lighting in your level.

If you need moving lights then you can blit circular rings onto the lightmap each frame before drawing the whole lot over the scene - I've used a similar approach before. By projecting lines from light positions to the vertices of any objects within the light's range, you can create black 2D shadow polygons to draw to your lightmap as well.

Share this post


Link to post
Share on other sites

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

Sign in to follow this