• Advertisement
Sign in to follow this  

D3D lighting issue

This topic is 2436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement