Sign in to follow this  

Lighting Problems - Still

This topic is 3660 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

[Edit: The problem has changed somewhat - check below] I'm using Managed DirectX, and C#. I'm also using the CustomVertex types. The object you see above is PositionNormalColored. There is no texture. My set up code looks like this:
			device.RenderState.Lighting = true;

			device.Lights[0].DiffuseColor = ColorValue.FromArgb(0xFFFFFF);
			device.Lights[0].Type = LightType.Directional;
			device.Lights[0].Direction = new Vector3(-1, -0.05f, -1);
			device.Lights[0].Update();
			device.Lights[0].Enabled = true;

			device.RenderState.AmbientColor = 0x808080;
			//Material material = new Material();
			//material.AmbientColor = ColorValue.FromArgb(0xFFFFFF);
			//device.Material = material;


The normals are correct, and the directional light is working fine. The ambient color does not show up at all. I have some PositionTextured objects in the scene that appear black with lighting enabled, which is to be expected because they have no normals. If I enable the material, the textured objects show up with the ambient color. However, the PositionNormalColored object shows up with BLUE ambient color. I can not get rid of this blue. If I switch the globe to PositionNormalTextured, I get the ambient lighting, but the directional lighting does not work. I feel like I've tried every combination of everything... Help? [Edited by - mg_mchenry on December 7, 2007 4:00:11 PM]

Share this post


Link to post
Share on other sites
The least I can do is give you the formula by which DX9 calculates the ambient lighting contribution for each vertex you feed it:
Ambient Lighting = Ca*[Ga + sum(Atti*Spoti*Lai)];
where Ca = Material ambient color and Ga = Global ambient color. From this it should be obvious that a material _has_ to be defined in order to have any ambient lighting (otherwise, the left-most product would yield 0). Also, if no ambient color is specified by the material, the device will pick the vertex color (or more specifically: either of two possible color attributes). This might explain the blueish tint.

I don't know MDX, so I'm afraid I can't help you further :/.

EDIT: reading Evil Steve's in-between post one thing does come to mind: are you by any chance setting a material somewhere and then forgetting about it?

Share this post


Link to post
Share on other sites
I should add, though it should be obvious, I'm using the fixed function pipeline.


I do not know where the blue color is coming from. There is no current material, unless I uncomment the lines you see above.

I did figure out the problem, however:

device.RenderState.AmbientMaterialSource = ColorSource.Color1;

All better!

Share this post


Link to post
Share on other sites
Quote:
Original post by mg_mchenry
I should add, though it should be obvious, I'm using the fixed function pipeline.


I do not know where the blue color is coming from. There is no current material, unless I uncomment the lines you see above.

I did figure out the problem, however:

device.RenderState.AmbientMaterialSource = ColorSource.Color1;

All better!
All that does is force the amvient colour to come from the vertex colour instead of the material (which is the default). That implies that the material has the blue colour set on currently.

I don't know how it's done in MDX, but in unmanaged you call SetMaterial() to set a material. You must be setting a material somewhere, otherwise the object will show up as black (The default material is completely black).

Share this post


Link to post
Share on other sites
I actually want the color to come from the vertex color. Why else would I have a vertex color, except for some shader effect?

Also, you can see in the commented code, I create a material, and set it's ambient color to white. Setting the ambient color to white results in blue ambient lighting.

What I did not try while using a material is setting
device.RenderState.AmbientMaterialSource = ColorSource.Material;

The problem seems specific to using PositionNormalColored vertices, which I'm guessing isn't all that often because most things are textured.

Share this post


Link to post
Share on other sites
Quote:
Original post by Todo
I don't know MDX, so I'm afraid I can't help you further :/.

EDIT: reading Evil Steve's in-between post one thing does come to mind: are you by any chance setting a material somewhere and then forgetting about it?


There isn't usually that much difference between MDX and DX when you get down to the basics.


I actually never set a material anywhere in the program and I get the blue. I should have tried clearing the material just to be sure, but I didn't think of it because even explicitly setting the material left me with blue vertices.

Share this post


Link to post
Share on other sites
Quote:
Original post by mg_mchenry
I actually want the color to come from the vertex color. Why else would I have a vertex color, except for some shader effect?
It just gives you a bit more control really. But if you don't want/need it, then sure, what you're doing there is absolutely fine.

Quote:
Original post by mg_mchenry
Also, you can see in the commented code, I create a material, and set it's ambient color to white. Setting the ambient color to white results in blue ambient lighting.
Actually, that code sets the light colour, not the material colour.
Perhaps materials are set differently for MDX? I'm really not sure.

Share this post


Link to post
Share on other sites
By setting:

device.RenderState.AmbientMaterialSource = ColorSource.Color1;

I was able to get ambient lighting to work:




Or, by setting up materials properly, I can get this to work:
device.RenderState.AmbientMaterialSource = ColorSource.Material;

which is important because the textured polygons don't seem to work without it.

But I still have this blue problem:


That box you see on top is WHITE. 0xFFFFFF. white. Really.

It is as if the light color itself was blue. But it's white. The entirety of the lighting code is here:
[source ]

device.RenderState.Lighting = true;

Light light = new Light();
light.DiffuseColor = ColorValue.FromArgb(0xFFFFFF);
light.SpecularColor = ColorValue.FromArgb(0xFFFFFF);
light.Type = LightType.Directional;
light.Direction = new Vector3(-1, -0.05f, -1);

device.Lights[0].FromLight( light );
device.Lights[0].Enabled = true;
device.Lights[0].Update();

device.RenderState.AmbientMaterialSource = ColorSource.Material;// .Color1;
device.RenderState.AmbientColor = 0x505050;

Material material = new Material();
material = device.Material;
material.DiffuseColor = ColorValue.FromArgb(0xFFFFFF);
material.AmbientColor = ColorValue.FromArgb(0xFFFFFF);
material.SpecularColor = ColorValue.FromArgb(0xFFFFFF);
material.DiffuseColor = ColorValue.FromArgb(0xFFFFFF);
device.Material = material;



I can't believe I haven't figured this out yet!

Share this post


Link to post
Share on other sites

This topic is 3660 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this