Sign in to follow this  
Toolmaker

What's wrong with my ambient light setup?

Recommended Posts

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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
I found the problem: The model materials don't have a value for ambient light, thus show up black. During loading, I do:

materials[i] = mtrls[i].Material3D;
materials[i].Ambient = materials[i].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

Share this post


Link to post
Share on other sites

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