У меня проблема с сглаживанием в unity3d.
Когда я включаю его, устанавливая качество в настройках проекта или во время выполнения, используя QualitySettings.antiAliasing = 8;
, это ничего не делает.Линии / границы все еще неровные.Почему?
Кроме того, мне пришлось изменить патч рендеринга на «Deferred», потому что с помощью «Forward» сглаживание создавало белые линии.
Вот как это выглядит в моем редакторе (посмотрите на ребра, ониочень неровный):
Вот мои настройки качества:
Мои настройки графики:
А воткак это выглядит при пути рендеринга, установленном на «forward» (края не очень зазубренные, но сильно прослушиваются):
Вот как я строю четырехугольники, используя c #
private Vector3 p0 = new Vector3( -0.5f, -0.5f, 0.5f );
private Vector3 p1 = new Vector3( 0.5f, -0.5f, 0.5f );
private Vector3 p2 = new Vector3( 0.5f, -0.5f, -0.5f );
private Vector3 p3 = new Vector3( -0.5f, -0.5f, -0.5f );
private Vector3 p4 = new Vector3( -0.5f, 0.5f, 0.5f );
private Vector3 p5 = new Vector3( 0.5f, 0.5f, 0.5f );
private Vector3 p6 = new Vector3( 0.5f, 0.5f, -0.5f );
private Vector3 p7 = new Vector3( -0.5f, 0.5f, -0.5f );
public void BuildQuad(BlockFace blockFace) {
Mesh mesh = new Mesh();
mesh.name = "QuadMesh";
Vector3[] vertices = new Vector3[4];
Vector3[] normals = new Vector3[4];
Vector2[] uvs = new Vector2[4];
int[] triangles = new int[6];
if (blockFace == BlockFace.FRONT) {
vertices = new Vector3[] {p4, p5, p1, p0};
normals = new Vector3[] {
Vector3.forward,
Vector3.forward,
Vector3.forward,
Vector3.forward
};
} else if (blockFace == BlockFace.BACK) {
vertices = new Vector3[] {p6, p7, p3, p2};
normals = new Vector3[] {
Vector3.back,
Vector3.back,
Vector3.back,
Vector3.back
};
} else if (blockFace == BlockFace.LEFT) {
vertices = new Vector3[] {p7, p4, p0, p3};
normals = new Vector3[] {
Vector3.left,
Vector3.left,
Vector3.left,
Vector3.left
};
} else if (blockFace == BlockFace.RIGHT) {
vertices = new Vector3[] {p5, p6, p2, p1};
normals = new Vector3[] {
Vector3.right,
Vector3.right,
Vector3.right,
Vector3.right
};
} else if (blockFace == BlockFace.BOTTOM) {
vertices = new Vector3[] {p0, p1, p2, p3};
normals = new Vector3[] {
Vector3.down,
Vector3.down,
Vector3.down,
Vector3.down
};
} else if (blockFace == BlockFace.TOP) {
vertices = new Vector3[] {p7, p6, p5, p4};
normals = new Vector3[] {
Vector3.up,
Vector3.up,
Vector3.up,
Vector3.up
};
}
triangles = new int[] {3, 1, 0, 3, 2, 1};
uvs = BlockData.GetBlockData(blockType).GetUvs(blockFace);
mesh.vertices = vertices;
mesh.normals = normals;
mesh.uv = uvs;
mesh.triangles = triangles;
mesh.RecalculateBounds();
GameObject quad = new GameObject("quad");
quad.transform.position = location.position;
quad.transform.parent = parent.transform;
MeshFilter meshFilter = (MeshFilter) quad.AddComponent(typeof(MeshFilter));
meshFilter.mesh = mesh;
}
И рендеринг их:
World.cs:
public class World : MonoBehaviour {
public static int columnHeight = 8;
public static int chunkSize = 8;
public static int worldSize = 1;
public static Dictionary<string, Chunk> chunks = new Dictionary<string, Chunk>();
private float inc = 0.01f;
private float t = 0;
public Block GetBlock(Location location) {
Chunk chunk = GetChunk(location);
if (chunk == null) {
return null;
}
int localX = location.x() - chunk.chunkLocation.x();
int localY = location.y() - chunk.chunkLocation.y();
int localZ = location.z() - chunk.chunkLocation.z();
//Debug.Log("LOCALS: "+localX+", "+localY+", "+localZ);
try {
return chunk.chunkBlocks[localX, localY, localZ];
} catch (IndexOutOfRangeException e) {
return null;
}
}
public Chunk GetChunk(Location location) {
ChunkLocation chunkLocation = new ChunkLocation(location);
if (chunks.ContainsKey(chunkLocation.ToString())) {
return chunks[chunkLocation.ToString()];
}
return null;
}
public void BuildChunks() {
for (int x = 0; x < worldSize; x++) {
for (int y = 0; y < columnHeight; y++) {
for (int z = 0; z < worldSize; z++) {
ChunkLocation chunkLocation = new ChunkLocation(x*chunkSize, y*chunkSize, z*chunkSize);
Chunk chunk = new Chunk(chunkLocation, this);
chunk.chunkGameObject.transform.parent = this.transform;
chunks.Add(chunkLocation.ToString(), chunk);
}
}
}
foreach (KeyValuePair<string, Chunk> chunk in chunks) {
chunk.Value.drawChunkBlocks();
}
}
void Start(){
this.transform.position = Vector3.zero;
this.transform.rotation = Quaternion.identity;
QualitySettings.antiAliasing = 8;
QualitySettings.SetQualityLevel(5);
BlockData.LoadAll();
BuildChunks();
}
}
Chunk.cs:
public class Chunk {
public Block[,,] chunkBlocks;
public GameObject chunkGameObject;
public ChunkLocation chunkLocation;
public World world;
public void prepareChunkBlocks() {
chunkBlocks = new Block[World.chunkSize,World.chunkSize,World.chunkSize];
for (int x = 0; x < World.chunkSize; x++) {
for (int y = 0; y < World.chunkSize; y++) {
for (int z = 0; z < World.chunkSize; z++) {
var position = chunkGameObject.transform.position;
int worldX = (int)position.x + x;
int worldY = (int)position.y + y;
int worldZ = (int)position.z + z;
int randomY = Utils.GenerateHeight(worldX, worldZ);
if (worldY > randomY) {
chunkBlocks[x,y,z] = new Block(BlockType.AIR, new Location(x, y, z), chunkGameObject, this);
} else {
if (worldY > randomY-1) {
chunkBlocks[x,y,z] = new Block(BlockType.GRASS, new Location(x, y, z), chunkGameObject, this);
} else if (worldY > randomY-4){
chunkBlocks[x,y,z] = new Block(BlockType.DIRT, new Location(x, y, z), chunkGameObject, this);
} else {
chunkBlocks[x,y,z] = new Block(BlockType.STONE, new Location(x, y, z), chunkGameObject, this);
}
}
}
}
}
}
public void drawChunkBlocks() {
for (int x = 0; x < World.chunkSize; x++) {
for (int y = 0; y < World.chunkSize; y++) {
for (int z = 0; z < World.chunkSize; z++) {
chunkBlocks[x,y,z].Draw();
}
}
}
CombineQuads();
}
public Chunk(ChunkLocation chunkLocation, World world) {
this.chunkGameObject = new GameObject(chunkLocation.ToString());
this.chunkLocation = chunkLocation;
this.world = world;
chunkGameObject.transform.position = chunkLocation.position;
prepareChunkBlocks();
//drawChunkBlocks();
}
void CombineQuads() {
//1. Combine all children meshes
MeshFilter[] meshFilters = chunkGameObject.GetComponentsInChildren<MeshFilter>();
CombineInstance[] combine = new CombineInstance[meshFilters.Length];
int i = 0;
while (i < meshFilters.Length) {
combine[i].mesh = meshFilters[i].sharedMesh;
combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
i++;
}
//2. Create a new mesh on the parent object
MeshFilter meshFilter = (MeshFilter) chunkGameObject.AddComponent(typeof(MeshFilter));
meshFilter.mesh = new Mesh();
//3. Add combined meshes on children as the parent's mesh
meshFilter.mesh.CombineMeshes(combine);
//4. Create a renderer for the parent
MeshRenderer renderer = chunkGameObject.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
//renderer.material = BlockData.GetBlockData(BlockType.DIRT).material;
renderer.materials = new Material[] {BlockData.blockMaterial};
//5. Delete all uncombined children
foreach (Transform quad in chunkGameObject.transform) {
GameObject.Destroy(quad.gameObject);
}
}
}
Пожалуйста, кто-нибудь может мне помочь с этим?Я пытаюсь выяснить, почему он не работает с часами.