gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Directional Lighting

#171938 - headspin - Sun Jan 03, 2010 12:13 pm

I am trying to setup 4 different colored lights to light up a 2d level made of quads.

Here is the light code from the Display_List_2 libnds example

Code:
glLight(0, RGB15(31,31,31), 0, floattov10(-1.0), 0);
glLight(1, RGB15(31,0,0), 0, floattov10(1) - 1, 0);
glLight(2, RGB15(0,31,0), floattov10(-1.0), 0, 0);
glLight(3, RGB15(0,0,31), floattov10(1.0) - 1, 0, 0);
   
//need to set up some material properties since DS does not have them set by default
glMaterialf(GL_AMBIENT, RGB15(16, 16, 16));
glMaterialf(GL_DIFFUSE, RGB15(16, 16, 16));
glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8, 8, 8));
glMaterialf(GL_EMISSION, RGB15(16, 16, 16));


I cannot seem to get the coloured effect I'm looking for. Something like [Images not permitted - Click here to view it] but probably a bit subtler.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game

#171941 - GugloPWN - Sun Jan 03, 2010 4:20 pm

If your scene is 2D but drawn on textured quads you could use vertex colors to get that effect.

Basically when you define a vertex you can give it a color by calling glColor3b(int r, int g, int b) values between 0-255 and the texture is blended with what ever color you define.

#171942 - kusma - Sun Jan 03, 2010 5:57 pm

If I understand the picture correct, you're trying to get colored volumetric point-lights. Unfortunately, this isn't something the Nintendo DS GPU can do directly, so you'll have to fake it somehow (like GugloPWN suggests).

Not even your desktop GPU can do it "directly", you'll have to do stuff like ray-matching in shadow-maps for similar effects on PCs, and it's quite slow. That solution is simply out the window on NDS ;)

#171943 - headspin - Sun Jan 03, 2010 7:28 pm

Thanks for the feedback guys. I had a feeling the effect I was after was not possible. I guess I could have a quad that covers the screen using a 5 bit alpha and then use the glColor3b to set it different colours of light.

Anyway it's nice to know I can at least set the colour of a vertex for a similar effect.

Should be good for doing effects like sunset.
_________________
Warhawk DS | Manic Miner: The Lost Levels | The Detective Game