Sign in to follow this  

Normal Woes

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

I've written a function that randomly generates a terrain map and calculates all the vertex normals so it can be rendered wiht Gouraud shading. However, when I pass the vertices to DirectX it doesn't seem to be able to calculate the lighting in any sensible way. All normals are in three-space and normalized to (0,1), relative to thier vertices. I suspect my problem comes from the fact that this is not the way DirectX wants its normals. I have also attempted setting the normals relative to world space, but that didn't help either (although it gave me some seriously interesting lighting ~_^). How exactly is a normal defined in DirectX? Coordinates? Angles? A quick explanation of what it's looking for would be great! Also, do I have to have a material to use the D3D lighting routines? I set the color of each of my vertices manually, so I'm not sure if I need to set a material as well. *edit* I'm building against DX8.1, btw */edit*

Share this post


Link to post
Share on other sites
It should simply be a normalised vector for D3D. To calc a normal for a triangle take the cross product of the two sides and normalise. For Gouraud you then combine all the face normals connecting to a vertex (e.g. average).

Share this post


Link to post
Share on other sites
Normals are defined in model space. If your World matrix is identity ( as is usual for terrain ), then they are in world space. You said your normals are normalized to [0..1]. They should be in the range [-1,1].

Try forcing all vertex normals to be < 0, 1, 0 > ( straight up ) and see how that looks.

Share this post


Link to post
Share on other sites
Heh, sorry about that SimmerD ^_^. By "normalized to (0,1)", I meant that the lenght of the vertices was normalized to (0,1). Actualy values did go from (-1,1).

Anyway, I discovered the problem last night. I had made a typo when I wrote the code to calulate the cross-product for the facet normals, and so all of the z components were just plain wrong. I works great now, I had a cute little demo of it running where you could watch the sun rise and set over the terrain. Thanks guys.

Share this post


Link to post
Share on other sites

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