我在unity3d中使用抗锯齿有问题。
当我通过在项目设置中或在运行时使用tf.name_scope
设置质量来启用它时,它什么都不做。线条/边界仍然参差不齐。为什么?
另外,我不得不将渲染补丁更改为“ Deferred”,因为使用“ Forward”时,抗锯齿会产生白线。
这是我在编辑器中的外观(看一下边缘,它们非常锯齿):
以下是我的质量设置:
我的图形设置:
这是将“渲染路径”设置为“ forward”的样子(版本不是很锯齿,但是很臭):
这是我使用c#构建四边形的方法
QualitySettings.antiAliasing = 8;
并渲染它们:
World.cs:
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;
}
Chunk.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();
}
}
请,有人可以帮我吗?我试图找出为什么几个小时后仍无法正常工作。