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 > Getting a display list to ignore normal commands

#157412 - DiscoStew - Fri May 23, 2008 9:55 pm

Ok, so the subject sounds odd, but I'm trying to do something on the NDS that allows me to make an option to have lighting on or off on a model. With a display list, it can either have normal commands in it or not, but for my purposes, I have to have the former. My model has a preset materials, which are added to the display list. When I was looking through the NDS specs, I saw this...

Quote:
40004C0h - Cmd 30h - DIF_AMB - MaterialColor0 - Diffuse/Ambient Reflect. (W)

0-4 Diffuse Reflection Red ;\light(s) that directly hits the polygon,
5-9 Diffuse Reflection Green ; ie. max when NormalVector has opposite
10-14 Diffuse Reflection Blue ;/direction of LightVector
15 Set Vertex Color (0=No, 1=Set Diffuse Reflection Color as Vertex Color)
16-20 Ambient Reflection Red ;\light(s) that indirectly hits the polygon,
21-25 Ambient Reflection Green ; ie. assuming that light is reflected by
26-30 Ambient Reflection Blue ;/walls/floor, regardless of LightVector
31 Not used

With Bit15 set, the lower 15bits are applied as VertexColor (exactly as when when executing the Color command), the purpose is to use it as default color (eg. when outcommenting the Normal command), normally, when using lighting, the color setting gets overwritten (as soon as executing the Normal command).


When it speaks about the 15th bit, I assumed that when set would prevent the execution of normals in the display list and would "color" the model with what the Diffuse value is set to until that bit is changed. Am I right, or am I thinking this wrong? If I am wrong, what would be the best way to do what I want?

thx in advance
_________________
DS - It's all about DiscoStew

#157427 - M3d10n - Sat May 24, 2008 2:24 am

Never tested the 15th bit, but I imagine that if you set the material's diffuse to black and the ambient color to full white the lighting would be effectivelly nullfied, showing only the textures without color modulation.

But obviously turning off the lighting using the POLY_FMT flags would be preferable, no? Are POLY_FMT commands included in your display lists?

#157449 - DiscoStew - Sat May 24, 2008 6:16 pm

M3d10n wrote:
Never tested the 15th bit, but I imagine that if you set the material's diffuse to black and the ambient color to full white the lighting would be effectivelly nullfied, showing only the textures without color modulation.

But obviously turning off the lighting using the POLY_FMT flags would be preferable, no? Are POLY_FMT commands included in your display lists?


I haven't gotten to textures at the moment. Just working on the model's materials. When I go and disable the lights through the POLY_FMT command (it's separate from the display list as of now), my model shows complete black, even when I change the diffusion to black and the ambience to white.
All I'm trying to do is set up the model so that if I choose to disable lighting, the Normal commands in the display list won't change the coloring of the model, but obviously will when lighting is enabled. I'm doing this as part of a library for handling 3D models in a custom format.
_________________
DS - It's all about DiscoStew

#157466 - M3d10n - Sun May 25, 2008 3:18 am

Did you try keeping the light on, but just setting the diffuse to black?

#157469 - DekuTree64 - Sun May 25, 2008 3:49 am

I think bit15 of the material command just means to set the current vertex color at the same time as setting the material. But any normal vector commands afterward will still overwrite the current vertex color.

The technique mentioned in the command description could work, although I'm not sure what would be the best way to "comment out" the normal commands, since they also have an argument that needs to be accounted for... maybe since you won't be using lighting on the model, replace all normal commands with light vector commands. And since those usually aren't done in display lists, it should be safe to then run through and replace all light vectors with normals to switch back.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#157473 - DiscoStew - Sun May 25, 2008 4:57 am

M3d10n wrote:
Did you try keeping the light on, but just setting the diffuse to black?


I will say, that I was able to get it working in that manner (though I had to set at least one light enabled, and any lights on with a color of complete white).

DekuTree64,
You mean making a change to the command packs involving normals commands, and changing them to light vectors? Seems a little tedious, but it's worth looking into.

-------------

There is one other way that I tinkered with that could worked, but I'm not sure whether it is a good idea. Changing the emission value (along with the ambient/diffuse value). Perhaps making some cross between them? I will admit that I haven't dove into the necessity of some 3D aspects like this, and I'm learning them in this manner.
_________________
DS - It's all about DiscoStew

#157475 - DekuTree64 - Sun May 25, 2008 6:20 am

DiscoStew wrote:
There is one other way that I tinkered with that could worked, but I'm not sure whether it is a good idea. Changing the emission value (along with the ambient/diffuse value).

Good point. Just setting the emission color to white will force it to full brightness.

Modifying display lists is a bit tricky, but does have its uses. Especially when using manual vertex colors, because you can't modify the color at all otherwise.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#157515 - DiscoStew - Mon May 26, 2008 7:38 am

Ok, after a little testing, I think I got it how I want it. By doing the following code with related material values....

Code:
glMaterial(GL_DIFFUSE, RGB(0,0,0));
glMaterial(GL_EMISSION, AmbientRGB15);


....it disables the effect that the normals would have on the the model, and forces the model to have the color equal to it's ambience, whether or not lights are enabled. This is all from visual comparisons displayed in Maya using the default lighting and when all lights are disabled.
_________________
DS - It's all about DiscoStew