# view meshes as in the dxviewer

## Recommended Posts

kopi_b    122
hi! i've a problem with my meshes. 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 on other sites
Illco    928
It can be many things; the one thing that caught my attention is the following line:
meshMaterials[i].Ambient = meshMaterials[i].Diffuse;

Why are you setting the material's ambient property to the value of the diffuse color property? Usually you want the diffuse component to be the strongest and cut down on ambient; otherwise the lighting details as seen in the DXViewer's screenshot will disappear, because each face is lit equally by ambient lighting.

If you have no other source for the material's ambient color, set it to a fifth of the diffuse color for example.

Good luck. Greetz,

Illco

##### Share on other sites
kopi_b    122
i've this line from the mesh tutorials that come with the sdk
so i think it's correct

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