#### Archived

This topic is now archived and is closed to further replies.

# lighting problems

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

## Recommended Posts

Hey all, I was wondering if anyone else has ever had this problem and might recognize it. I wrote a model exporter for milkshape recently, and I have my model displaying on the screen and everything, but there not much light seems to be getting to it, which I wouldn''t find wierd normall, but if I have it constantly rotate, every now and then it goes to full brightness. Anyone know what to do about that?

##### Share on other sites
If you''re using shaders, you may have forgotten to transform the normals of your mesh along with its position. When you rotate a mesh, the normals of the mesh need to be tranformed as well.

However, because of the way the 3D math works, you can''t always transform the normals of a mesh with the same matrix you use to transform the vertices of the mesh. Do a search for something like "transforming normals" if you''re not sure what I mean.

If I remember correctly (brain is mush right now after having pulled an all-nighter), the matrix to transform normals is:

Mn = ( (M)^-1 )^T

This says that the Matrix to transform normals (Mn) is equal to the transpose (that''s the ^T part) of the inverse (that''s the ^-1 part) of the mesh''s original transformation matrix used to move the mesh around the scene.

neneboricua

##### Share on other sites
hmm... not using shaders. I''ve never had to worry about transforming my normals before (I''ve used the same code to render a terrain with lighting). I wonder if maybe there is an issue with the normal as they are being exported from milkshape

##### Share on other sites
If you''re using the fixed function pipeline, D3D takes care of transforming the normals for you. That''s why you''ve never run into that problem. When you use shaders, you''re responsible for all this kind of work. It''s easy to forget to transform normals when writing your shaders.

Your problem still sounds like it has something to do with the normals. If rotating your mesh causes lighting to work at some orientations and not others, it really sounds like a problem with your normals. Double check how the normals are being exported and that all your code dealing them is ok.

Perhaps other forum members will have other ideas about what could be the problem.

neneboricua

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002051
×