D3D lighting issue

Started by
3 comments, last by Endurion 12 years, 11 months ago
The way I get it - if I have set an ambient light, any material that reflects ambient should be visible. Specifically the code looks like this:


D3DMATERIAL9 material;
material.Ambient.a = material.Ambient.b = material.Ambient.g = 255;
gpu->SetMaterial(&material);
gpu->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_ARGB(255,255,255,255) );

But the object is still dark.
I suppose that most of the lighting setup is in order since adding

material.Emissive = material.Ambient

makes the object visible.

What could I possibly be missing?

P.S. I'm using Visual C++ 2008 Express
P.P.S. Here's the full code http://snipt.org/xKT its a bit messy, the setup starts at line 212
Advertisement
I finally figured this out. The problem was that I declared the [color=#1C2837][size=2]D3DMATERIAL9 structure within a method. And later it was out of scope or something. Once I made it a global variable, ambient lighting started working.
[color=#1C2837][size=2]

[color=#1C2837][size=2]Why did the emissive light work with the previous construction, I still have no idea.
I rather think it might be because you didn't set the R component. In debug local variables are initialised to different values than globals.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

There is no possible value of the R component that would make the material completely dark.

That said, I had tried it with all components set and in tens of different variations until after a long and painful process of taking a working example and transforming it step by step to what I had wrote, I noticed that where the material is declared makes the difference.
Well, 0xcdcdcdcd might end up negative, depending on the type. Or DX might fail to set up the light with an invalid color value completely (did you check the return type?)

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement