rendering meshes in c#

kopi_b

Newcomer
Joined
Mar 5, 2006
Messages
4
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
 
I don't have winRAR here, and don't have permissions ot install it; so without looking at the render I can only guess that your lighting is in such an area that it's casting shadows on your mesh.
 
@Nate Bross: this are definitely no shadows

@Voldron: i'm pretty sure that it's because of the normals
in my 3d graphic program where i've created the mesh the normals
are on the faces, in directx the normals are on the vertices.

kopi
 
Last edited:
re:

i made some progress now 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 = materials.Material3D;
meshMaterials.Ambient = meshMaterials.Diffuse;
}

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

kopi_b
 
re:

the problem was this line:
Code:
dev.Lights[0].Direction = new Vector3(2.0f, 2.0f, 2.0f);

the light came in an angle of 45°
when i change the direction to a different angle it's much better

kopi_b
 
Back
Top