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 > glLight AND vertex color at once ?

#101985 - ikaris - Sat Sep 09, 2006 2:56 pm

I have a display list that I created using my Maya exporter.

When I view the model with NO glLight in the scene, and my PolyFmt like this:

Code:
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE);


I can see all of my vertex color on the model. Every vertex can be a different color if I like.

However, as soon as I add add a light:

Code:
glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE | POLY_FORMAT_LIGHT0);
glLight(0, RGB15(31,31,31) , floattov10(0.67), floattov10(-0.75), floattov10(1.0));


All I can see is my model in shades of black and white, not multiplying or adding with the vertex color !

Is there a way to choose how the vertex color will be blended with the glLight ?

Thanks !

#102004 - sajiimori - Sat Sep 09, 2006 7:30 pm

No, the DS can't do it, unless someone has a hack of some kind. Turn off all lights while rendering vertex colored models.

#102022 - Lick - Sat Sep 09, 2006 10:43 pm

You need to set up a material. I can't garantee that it will work.

For unique colors on each vertex, I have no idea.
_________________
http://licklick.wordpress.com

#102028 - sajiimori - Sat Sep 09, 2006 11:21 pm

Are you making things up, Lick?

#102030 - ikaris - Sat Sep 09, 2006 11:35 pm

I have a material, thats no problem... i can make the WHOLE object a given color with the material.

But I wanted something per vertex...

I can live without it tho, unless someone comes up with something brilliant !

#102033 - Lick - Sun Sep 10, 2006 12:37 am

sajiimori wrote:
Are you making things up, Lick?


Nope. Coming from a Direct3D background, I simply figured that OpenGL (even the DS version) probably used a similar method to display lit objects, that is, using materials that react on lights.
This tutorial explains it (D3D) http://www.two-kings.de/tutorials/dxgraphics/dxgraphics06.html (Scroll all the way down, it will have a short snippet of code that sets up the material.)

As it seems from the reply above, this is indeed how it works. But like I said, I have no idea how to do per-vertex color combined with light. Only per-object. I thought I made that clear in my previous post, though.
_________________
http://licklick.wordpress.com

#102041 - DekuTree64 - Sun Sep 10, 2006 4:18 am

You may be able to do it by changing the material diffuse color per-vertex. I've never actually tried it though.

As I understand it, the vertex normal command is what does all the lighting calculations, and comes up with a final vertex color which is then stored to an internal register.
The vertex color command is basically to set that register directly, if you want to do precalculated lighting, or custom software lighting calculations (this might actually be the best way to go, although you'd be modifying the display list, so the 'original' colors would have to be stored elsewhere. Not to mention the normals).
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#102046 - sajiimori - Sun Sep 10, 2006 5:07 am

Yeah, modifying vertex colors on the fly -- essentially doing lighting in software -- is probably the best/only way on DS.

Can material changes be embedded in a display list?

#102063 - Sausage Boy - Sun Sep 10, 2006 12:11 pm

I'd think so. GBATEK has a list of geometry commands. Libnds doesn't let you use all of them in display lists though (probably for a good reason), there's a list somewhere around the middle of videoGL.h.
_________________
"no offense, but this is the gayest game ever"

#103366 - silent_code - Thu Sep 21, 2006 10:46 am

normally in openGL, when you're doing lighting your glColor settings get overwritten, but it is possible to keep that color with another state (have to look it up) so you end up having your favorite vertex colors lit by colored lighting ;)

but on the nds it depends on if that state is available or not. if it wasn't you prbably are better off doing your own lighting or using textures.

i found it: if you have enabled GL_LIGHTING, enable GL_COLOR_MATERIAL and your glColor will be modulated by the light color and the diffuse texture.

hope that makes things clear.

#103373 - ikaris - Thu Sep 21, 2006 12:48 pm

Where do you enable it ?

When I look up GL_LIGHTING in videoGL.h, I get this:

Code:
#define GL_LIGHTING    1   // no idea what this is for / who defined it


Not the most confidence-inspiring comment :)

I also can't find GL_COLOR_LIGHTING in videoGL.h, nor can I find it in the NDSLib reference

http://www.drunkencoders.com/documents/DS/ndslib.htm

(Although there are a lot of things missing from it anyway)

Can you post some sample code as to how one would activate the feature ?

Thanks !

#103383 - PypeBros - Thu Sep 21, 2006 2:17 pm

i'd be starting from dovoto's NDS NeHe Lesson 07 (found on drunkencoders) if i had to work this out ... keeping the code, but using a glColor() instead of glTextureBind().
_________________
SEDS: Sprite Edition on DS :: modplayer

#103392 - Lick - Thu Sep 21, 2006 3:28 pm

I'm guessing that either the 3D component of libnds is lacking (a lot!) or that the DS simply doesn't have this feature. Which would be awful.
_________________
http://licklick.wordpress.com

#103398 - silent_code - Thu Sep 21, 2006 4:08 pm

note: this is *real* PC OpenGL code:

glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);

...

same goes for glDisable(...);

also note, that you should not mixup ndslib and libnds. afaik ndslib is outdated and discontinued.

i neither know if libnds supports GL_COLOR_MATERIAL (NOT GL_COLOR_->LIGHTING<- !!!) nor do i know if it has some equivalent. best thing to do would be to kindly ask dovoto or the other guys that developed and maintain libnds about such a feature.

#134806 - route66 - Tue Jul 17, 2007 1:57 am

GL_COLOR_MATERIAL is not defined. Is this supported by the NDS?

#134809 - relpats_eht - Tue Jul 17, 2007 3:58 am

Please don't revive year old topics.

Yes, using glMaterial.
_________________
- relpats_eht

#134914 - a128 - Wed Jul 18, 2007 8:25 am

silent_code wrote:


i found it: if you have enabled GL_LIGHTING, enable GL_COLOR_MATERIAL and your glColor will be modulated by the light color and the diffuse texture.

hope that makes things clear.


Yout must enable Bit15

40004C0h - Cmd 30h - DIF_AMB - MaterialColor0 - Diffuse/Ambient Reflect. (W)
....
15 Set Vertex Color (0=No, 1=Set Diffuse Reflection Color as Vertex Color)

do do that

#157755 - Synthetic - Wed May 28, 2008 11:40 pm

Does anyone have a sample of working code with bit15 & textures? I'm trying to do something similar, and I've managed to get it working with just vertex colors and lighting, but when I try to add texture coordinates the lighting becomes uniform regardless of normals.