Jump to content
  • Advertisement
Sign in to follow this  
oa1111

Mesh Normals

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

Hi I'm new to development in DirectX and am having some problems getting lighting to work on a mesh that I have generated. When I try to light my mesh the faces appear to lighten and darken together (http://img168.imageshack.us/img168/2749/meshproblemexampleshz2.th.jpg). Can anyone help me out? private void ConstructMesh() { // Create a mesh. mesh = new Mesh( 16, //faces 10, //vertices 0, // no flags VertexFormats.Position, // Position information only device); // Set up the 8 corners of the cube int circleDivisions = 8; float radius = 2; CustomVertex.PositionOnly[] vertices = new CustomVertex.PositionOnly[circleDivisions + 2]; //Create vertices around a circle on the x-z plane. for (int i = 0; i < circleDivisions; i++) { double theta = (2 * Math.PI / circleDivisions) * (double)i; float z = radius * (float)Math.Sin(theta); float x = radius * (float)Math.Cos(theta); vertices = new CustomVertex.PositionOnly(new Vector3(x, 0, z)); } //Create two additional vertexes above and below the circle. vertices[8] = new CustomVertex.PositionOnly(new Vector3(0, 2, 0)); vertices[9] = new CustomVertex.PositionOnly(new Vector3(0, -2, 0)); // Indices for all 16 faces. short[] indices = new short[] { 0, 1, 8, 1, 2, 8, 2, 3, 8, 3, 4, 8, 4, 5, 8, 5, 6, 8, 6, 7, 8, 7, 0, 8, 0, 1, 9, 1, 2, 9, 2, 3, 9, 3, 4, 9, 4, 5, 9, 5, 6, 9, 6, 7, 9, 7, 0, 9 }; mesh.SetVertexBufferData(vertices, LockFlags.None); mesh.SetIndexBufferData(indices, LockFlags.None); int[] adjacency = new int[mesh.NumberFaces * 3]; mesh.GenerateAdjacency(0.01F, adjacency); //Attempt to calculate normals for the mesh. Mesh tempMesh = mesh.Clone(mesh.Options.Value, mesh.VertexFormat | VertexFormats.Normal, device); tempMesh.ComputeNormals(); mesh.Dispose(); mesh = tempMesh; mesh.OptimizeInPlace(MeshFlags.OptimizeVertexCache, adjacency); }

Share this post


Link to post
Share on other sites
Advertisement
Is this Mesh your own data type? You could try visualizing normals (send them to the pixel shader and output them as color) to see how they look.

Share this post


Link to post
Share on other sites
n3Xus, thanks for your reply.

The mesh is not a custom type I've created, it belongs to the namespace Microsoft.DirectX.Direct3D. I should also have mentioned that I'm using DirectX 9.0.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!