What's wrong with my ambient light setup?

Started by
8 comments, last by Toolmaker 18 years, 7 months ago
I'm having some severe with ambient lightning, and I don't know if the problem is my code or not. I'm currently loading a model from disk, but when I display it with normal lights, it looks messed up, but when I use ambient lights, the screen goes blank. I have no idea what I am doing wrong here. I'm loading a simple test model from disc, the sphere.x that comes with the DirectX SDK. I loaded it into a D3DXMesh(Or in C# it's just Mesh) and when I reset my device, I set the lightning as this:

device.RenderState.Ambient = Color.White;
When I render, the sphere, the screen is blank. When I turn lightning off, the sphere shows up, but completely white. What am I doing wrong? Lights ARE on when using ambient lights. Toolmaker

Advertisement
Have you turned D3D Lighting on?

Is this done with shaders or D3DLighting?

ace
According to the documentation, lightning is on by default in Managed DirectX, so yes, lightning is on, and this is using default lightning(so, up to 8 light sources).

Toolmaker

Has the mesh got normals?

ace
I just made sure the mesh has normals, by adding this piece of code at the end of my loading code:
			if ((mesh.VertexFormat & VertexFormats.Normal) != VertexFormats.Normal)			{				Mesh tmpMesh = mesh.Clone(mesh.Options.Value, mesh.VertexFormat | VertexFormats.Normal, engine.Device);				tmpMesh.ComputeNormals();				mesh.Dispose();				mesh = tmpMesh;			}


Still nothing on screen, unless I turn lightning off.

Toolmaker

Any ideas?

Are you clearing your background to black? If so, the sphere may be incorrectly rendered as black, and you simply can't see it on your background.

Are you setting the correct vertex format before you render the object? And are you rendering anything else at all?
Turring Machines are better than C++ any day ^_~
Quote:Original post by intrest86
Are you clearing your background to black? If so, the sphere may be incorrectly rendered as black, and you simply can't see it on your background.

Are you setting the correct vertex format before you render the object? And are you rendering anything else at all?


Yes, I'm clearing to background to black. I changed it to SteelBlue, and my mesh shows up as black. In other words, it does render, but ends up black.

Also, the D3DXMesh class is suppose to set the vertexformat itself before rendering, and no, I'm currently not rendering anything else.

Would this have to do with the material(s) of my mesh not properly set? If so, how can I fix it?

Toolmaker

Can you post just the code that renders the mesh? Since it is from the SDK it obviously is a valid mesh, so there is something code-wise going on.
Turring Machines are better than C++ any day ^_~
I found the problem: The model materials don't have a value for ambient light, thus show up black. During loading, I do:
materials = mtrls.Material3D;materials.Ambient = materials.Diffuse;


And voila the model shows up:


But yeah, the models is totally fucked up. It now works perfect with the SDK models and the converted model. Down-side is, I can't calculate the normals for this model, or it throws an exception, even after cleaning and validating the mesh.

But, at least it works now. I still wonder, the model I first had looked totally messed up with the lights. So, I want to try again with a light, just to see how it ends up.

I want my camera to be at a 45 degree angle. What is the best location to place the light? Right below the camera, or on the opposite location of the camera? I was to have some shading on the ship, so the light should be above it. My zFarPlane is 5000 units now, so how should I set the range and more important, the attenuation? How does the attenuation work? If I set it to 0.2f, does the light decrease 0.2f each unit or so?

Toolmaker

This topic is closed to new replies.

Advertisement