Sign in to follow this  
kopi_b

rendering meshes

Recommended Posts

hi i've a problem when i render my meshes with c#. because every mesh is made of triangles, even actually flat faces with more than three vertices have to be devided into more faces. unfortunately this causes the problems when i render the meshes. at the transitions from one of these faces to the next one i've dark areas. the more faces there are the darker are the areas although the mesh is made up of just one material. here is my code and the mesh : http://www.toomaniac.com/kopi/blender/Render_Mesh.rar thx, kopi

Share this post


Link to post
Share on other sites
If you are having to split quads to make triangles for DirectX Meshes, be sure you are specifying the vertices for the index buffer in a clockwise format.

Share this post


Link to post
Share on other sites
hi!

>If you are having to split quads to make triangles for DirectX Meshes,
>be sure you are specifying the vertices for the index buffer in a clockwise
>format.

when i look into my .x file in the Mesh{} section i can find lines that start
with a 3 and lines that sart with a 4
for example:
4; 2060, 2061, 2062, 2063;
3; 2064, 2065, 2066;
i guess the first digit tells me how many vertices build the following face
and the rest are the vertices which are defined above, right?
so i also asume that if faces can be defined by four vertices i don't have to split them.
i ment faces which are more complicated
here are some screenshots of the mesh
here you can see the different triangles:
http://www.toomaniac.com/kopi/blender/edit_mode.gif
this is how it should look in the end:
http://www.toomaniac.com/kopi/blender/object_mode_solid.gif
and this is how it looks now:
http://www.toomaniac.com/kopi/blender/directx.gif
the face on the top of the mesh e.g. is actually one face but i've to devide it into a lot of triangels or squads.

kopi

Share this post


Link to post
Share on other sites
What template in the .X file are you seeing this in?:

4; 2060, 2061, 2062, 2063;
3; 2064, 2065, 2066;

Share this post


Link to post
Share on other sites
Mesh and MeshNormals, in both of them

but i made some progress and therefore the problem slightly changed (don't know if i should start a new thread)

since i recognized that the normals in directx hang on the vertices and not on the faces as in the 3d graphic program where i've made the mesh i concentrated on the nomals of the mesh.
mostly every vertex belongs to more faces and i think that's what causes the problem. when e.g. three faces share one vertex the normal for that one is calculated by the intersection of the three normals of the faces that share the vertex. then directx interpolates between two normals that make the same edge. could this be right?

now i've made a new mesh where i've as many normals per vertex as i've faces that share that vertex and it works better
in dxviewer it looks nearly how it should be:
http://www.toomaniac.com/kopi/mesh/dxviewer.gif

but in my program the shading isn't like in the dxviewer (e.g. the lots are missing):
http://www.toomaniac.com/kopi/mesh/program.gif

here are my parameters and my renderstates:
parameters.Windowed = true;
parameters.SwapEffect = SwapEffect.Discard;
parameters.EnableAutoDepthStencil = true;
parameters.AutoDepthStencilFormat = DepthFormat.D16;

dev = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, parameters);
dev.RenderState.ZBufferEnable = true;
dev.RenderState.Lighting = true;
dev.RenderState.CullMode = Cull.None;
dev.RenderState.Ambient = System.Drawing.Color.White;
dev.RenderState.SourceBlend = Blend.SourceAlpha;
dev.RenderState.DestinationBlend = Blend.InvSourceAlpha;
dev.RenderState.ZBufferWriteEnable = true;
dev.RenderState.AlphaBlendEnable = false;
dev.Lights[0].Type = LightType.Directional;
dev.Lights[0].Diffuse = System.Drawing.Color.White;
dev.Lights[0].Direction = new Vector3(-2.0f, -2.0f, -2.0f);
dev.Lights[0].Enabled = true;
dev.Lights[1].Type = LightType.Directional;
dev.Lights[1].Diffuse = System.Drawing.Color.White;
dev.Lights[1].Direction = new Vector3(2.0f, 2.0f, 2.0f);
dev.Lights[1].Enabled = true;
dev.RenderState.Ambient = System.Drawing.Color.FromArgb(0x202020);

loading of the mesh:
mesh = Mesh.FromFile(filename, MeshFlags.SystemMemory, dev, out materials);
meshMaterials = new Material[materials.Length];
for (int i = 0; i < materials.Length; i++)
{
meshMaterials[i] = materials[i].Material3D;
meshMaterials[i].Ambient = meshMaterials[i].Diffuse;
}

what do i have to do to see my mesh as in the dxviewer?

kopi_b

Share this post


Link to post
Share on other sites

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