Sign in to follow this  
Brain me

Lighting Inconsistency

Recommended Posts

Okay, I've been messing around with this problem for a few hours now and I can't seem to find out what's going on. I have constructed a VERY simple room with no ceiling using 2 textures - 1 for the floor, and 1 for the wall - which I tile to create this room. Once I got the room set up and made sure that my camera was working the way I wanted too, I tried adding some light. The first thing I did was simply turn lighting on, give everything a full material, and set the ambient light:
D3DMATERIAL9 material;
material.Diffuse.r = material.Ambient.r = 1.0f;
material.Diffuse.g = material.Ambient.g = 1.0f;
material.Diffuse.b = material.Ambient.b = 1.0f;
material.Diffuse.a = material.Ambient.a = 1.0f;
d3dDevice -> SetMaterial( &material );

d3dDevice -> SetRenderState( D3DRS_LIGHTING, true );
d3dDevice -> SetRenderState( D3DRS_AMBIENT, D3DCOLOR_RGBA( 30, 30, 30, 0 ) );
d3dDevice -> SetRenderState( D3DRS_NORMALIZENORMALS, true );



After I added this bit, I added a spot light to my scene and tried getting it to work for about an hour, always with varying results. I finally commented everything out except for the above, compiled, and ran. I noticed that my results still were not consistent. If I set my ambient lighting to ( 28, 28, 28, 0 ) everything is completely lit. If I move that to ( 29, 29, 29, 0 ), I get what I would expect to get - a relatively dark room where I can barely see the wall. I change it back to ( 28, 28, 28, 0 ), and now I have an even darker room...?. Which is what I would expect. I then move it back to 29s, and its dark (I'm actually doing this right now, so bear with me - sometimes it screws up, other times it doesn't). Back to 28s, and it's still dark. And to 29s, OOPS! The whole scene is completely lit now, though it is more red than my actual images are... Does anyone have any clue why this is? I thought it might be something to do with not releasing everything correctly. I forgot to release my textures when I first put them in, so I restarted Windows, made sure that every DirectX class called Release, made sure to delete every single pointer, and then recompiled. Same results. If anyone could please help me, I would really appreciate it. Thanks in advance. EDIT: Running more tests, I have noticed that if I compile it and run it, and the whole scene is completely lit when it should not be, exit and rerun without compiling again, the scene may not be lit... I don't know if that helps. That's even scarier to me though, because that means that something is happening at runtime that I don't know... EDIT2: And yet, sometimes, I compile and it's dark, and I rerun 10 times and its always dark, and sometimes, I compile and it's light, and it stays light for 5 or 10 executions. I've never seen this kind of behaviour from Direct3D before..

Share this post


Link to post
Share on other sites
I decided to make this a reply instead of an edit so it doesn't accidentally get skipped.

I have my lighting working now. I don't know what caused the problem in the first place, but I did another restart, I double checked all of my pointers and D3D classes, and I moved my lighting code above my Vertex Buffer code, and now everything is working.

If anyone can explain this, I would really appreciate that. Surely I don't have to create every light I could possibly need before my Vertex Buffer code?!

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