- Home /
Lighting Issues with custom generated mesh
Hey there,
So i've followed this tutorial by Sebastian Lague on custom generated 3d caves. Unfortunately if i insert a player with a spot light into one of those caves i run into an issue. Only half of the walls do respond correctly to the light. The seam looks something like this image?
As you can see the walls appear to be completely black, even though their material is set to be red. This does not change even if i shine the light directly onto the walls.
Comment
Have you correctly created the mesh normals? Without them lighting won't work.
I think i did, since half the wall is working as intended. I did mesh.recalculateNormals().
public void Generate$$anonymous$$esh(int [,] map, float squareSize) {
outlines.Clear();
checkedVerticies.Clear();
triangleDictionary.Clear();
vertices = new List<Vector3>();
triangles = new List<int>();
squareGrid = new SquareGrid(map, squareSize);
for (int x = 0; x < squareGrid.squares.GetLength(0); x++) {
for (int y = 0; y < squareGrid.squares.GetLength(1); y++) {
TriangualateSquare(squareGrid.squares[x, y]);
}
}
$$anonymous$$esh mesh = new $$anonymous$$esh();
cave.mesh = mesh;
mesh.vertices = vertices.ToArray();
mesh.triangles = triangles.ToArray();
int tileAmount = 10;
Vector2[] uvs = new Vector2[vertices.Count];
for(int i = 0; i<vertices.Count; i++) {
float percentX = $$anonymous$$athf.InverseLerp(-map.GetLength(0) / 2 * squareSize,map.GetLength(0)/2*squareSize , vertices[i].x) * tileAmount;
float percentY = $$anonymous$$athf.InverseLerp(-map.GetLength(0) / 2 * squareSize,map.GetLength(0)/2*squareSize , vertices[i].z) * tileAmount;
uvs[i] = new Vector2(percentX, percentY);
}
mesh.uv = uvs;
if (!is2D) {
CreateWall$$anonymous$$esh();
}
mesh.RecalculateNormals();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612230344im_/https://answers.unity.com/themes/thub/images/avi.jpg)