# Mesh Lightning

This topic is 3811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey When I'm rendering multiple meshes , the lightning is rendered foreach mesh. In my case, the meshes are rendering 4 parts of a map, and thus the lightning creates colour difference between each mech, which looks odd. The way I'm drawing the meshes is using device world to the specific mesh, and drawing it as a subset C#
device.Transform.World = Matrix.Translation(-128,-128,0) * Matrix.RotationZ(zAngle);
meshA.DrawSubset(0);

device.Transform.World = Matrix.Translation(-1,-128,0) * Matrix.RotationZ(zAngle);
meshB.DrawSubset(0);

The lightning is set overall with 1 directional light on the device C#
device.RenderState.Lighting = true;

device.Lights[0].Type      = LightType.Directional;
device.Lights[0].Diffuse   = Color.White;
device.Lights[0].Direction = new Vector3(0, 0.5f, -1);
device.Lights[0].Enabled   = true;

Is this the correct way to do it in theroy, or did I miss something ? Thanks.

##### Share on other sites
Any chance of a picture showing this aftifact? Could make it a little clearer [smile]

From your description it doesn't sound like you're doing anything obviously wrong. The sort of rendering approach you're using isn't unheard of and is a valid way of rendering a tiled map.

Have you inspected the data where the artifacts occur? Sometimes it'll be a discontinuity such that the algorithm is correct but the data isn't...

hth
Jack

##### Share on other sites
hey

Yes, I've checked the data before. If I render the entire map without using meshes , but simply raw trinagles, the colour problem don't appear.
The effect problem can be seen here. When not using multiple meshes the colours match , instead of here where it appears as the lightning is draw foreach mesh.

The image shows the middle of the 4 meshes that renders my area (zoomed well in).

##### Share on other sites
That screenshot looks like it's a case of texture coordinates/sampling rather than lighting. Try setting the ambient render state (device.RenderState.Ambient maybe) to white to effectively disable lighting and check again for artifacts. I'll bet they still exist.

If I'm correct then you need to look at your geometry creation, quite specifically how it differs from the case where you say it works and the case where you say it doesn't.

How are you putting the data into a mesh? Are you running any D3DX operators on the mesh?

hth
Jack