Sign in to follow this  

Mesh Normals

This topic is 3312 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[i] = 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
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

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