# Normal Woes

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

## 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 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 on other sites
Hmmm, that's exactly what I'm doing. I'll keep hashing away at it and hopefully figure it out.

##### 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 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.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633725
• Total Posts
3013567
×