SebLague / Ecosystem-2

527 stars 162 forks source link

Tile generation blue lines #4

Open Nejcc opened 5 years ago

Nejcc commented 5 years ago

alt text here is the graphic issue to fix

Hamsterman commented 5 years ago

I see the same

ladenedge commented 5 years ago

This appears to be a problem with the custom surface shader. The z-fighting seems to suggest it's coloring the triangles with both colors from the nearby biomes. (But why not the water? I dunno.)

Anyway, I solved this with the following steps:

  1. Replace the custom surface shader (in Terrain.shader) with a custom vertex shader. This one in the Unity wiki works for me.
  2. In TerrainGenerator.cs, add some color storage:
var colors = new List<Color> ();
Color[] startCols = { water.startCol, sand.startCol, grass.startCol };
Color[] endCols = { water.endCol, sand.endCol, grass.endCol };
  1. A bit below that, record the current tile color rather than UVs:
Vector2 uv = GetBiomeInfo (map[x, y], biomes);
// uvs.AddRange (new Vector2[] { uv, uv, uv, uv });  <-- not needed anymore
var color = Color.Lerp(startCols[(int)uv.x], endCols[(int)uv.x], uv.y);
colors.AddRange(new[] { color, color, color, color });
  1. Do the same in the big for loop that creates edges:
// uvs.AddRange (new Vector2[] { uv, uv, uv, uv });
colors.AddRange(new[] { color, color, color, color });
  1. In TerrainGenerator.cs, call SetColors() rather than SetUVs():
// mesh.SetUVs (0, uvs);  <-- no longer needed
mesh.SetColors(colors);

That should do it.

image

mubin986 commented 4 years ago

This appears to be a problem with the custom surface shader. The z-fighting seems to suggest it's coloring the triangles with both colors from the nearby biomes. (But why not the water? I dunno.)

Anyway, I solved this with the following steps:

  1. Replace the custom surface shader (in Terrain.shader) with a custom vertex shader. This one in the Unity wiki works for me.
  2. In TerrainGenerator.cs, add some color storage:
var colors = new List<Color> ();
Color[] startCols = { water.startCol, sand.startCol, grass.startCol };
Color[] endCols = { water.endCol, sand.endCol, grass.endCol };
  1. A bit below that, record the current tile color rather than UVs:
Vector2 uv = GetBiomeInfo (map[x, y], biomes);
// uvs.AddRange (new Vector2[] { uv, uv, uv, uv });  <-- not needed anymore
var color = Color.Lerp(startCols[(int)uv.x], endCols[(int)uv.x], uv.y);
colors.AddRange(new[] { color, color, color, color });
  1. Do the same in the big for loop that creates edges:
// uvs.AddRange (new Vector2[] { uv, uv, uv, uv });
colors.AddRange(new[] { color, color, color, color });
  1. In TerrainGenerator.cs, call SetColors() rather than SetUVs():
// mesh.SetUVs (0, uvs);  <-- no longer needed
mesh.SetColors(colors);

That should do it.

image

You're really awesome!! :D

VengantMjolnir commented 4 years ago

Lol, I solved it a different way. The tiling parameter would cause the graphical artifacts when it was set to <= 1, but if you adjust tiling X in the material to something just slight > 1 the artifacts go away. I suspect it is prevision in the shader, but didn't really dig into it a lot.

lolaswift commented 3 years ago

Lol, I solved it a different way. The tiling parameter would cause the graphical artifacts when it was set to <= 1, but if you adjust tiling X in the material to something just slight > 1 the artifacts go away. I suspect it is prevision in the shader, but didn't really dig into it a lot.

you're awesome