I渲染六角網格平面,得到結果:http://gyazo.com/0a008cc909138c7e3c1368e0078c7695WebGl紋理視覺失真
網格失真。請幫助 - 這可能是什麼原因以及如何解決? 我想這是因爲疊加透明膠片而發生的,但不知道如何解決它,而無需將網格更改爲六邊形。
紋理文件看起來:http://gyazo.com/0fea1cb07e52976dc9427b74ab23a252 (它有大小256x256px)
片段着色器:
vec4 textureColor0 = texture2D(uSampler0, vec2(vTextureCoord.s, vTextureCoord.t));
gl_FragColor = vec4(textureColor0.rgb, textureColor0.a);
網格位置:-10,-10,-26.99f,而相機:-5, - 2,-20和角度:-8,0,-22
網格生成代碼:
public static MeshData makePlane(int w, int h) {
float[] planeVerts = new float[12 * w * h];
float[] planeNormals = new float[planeVerts.length];
float[] planeTexCoords = new float[8 * w * h];
int[] planeTriangles = new int[6 * w * h];
{
int idx = 0;
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
planeVerts[idx] = x * 0.8f;
planeVerts[idx + 1] = y + 0.5f * x;
planeVerts[idx + 2] = 0;
planeVerts[idx + 3] = x * 0.8f;
planeVerts[idx + 4] = y + 1 + 0.5f * x;
planeVerts[idx + 5] = 0;
planeVerts[idx + 6] = x * 0.8f + 1;
planeVerts[idx + 7] = y + 1 + 0.5f * x;
planeVerts[idx + 8] = 0;
planeVerts[idx + 9] = x * 0.8f + 1;
planeVerts[idx + 10] = y + 0.5f * x;
planeVerts[idx + 11] = 0;
idx += 12;
}
}
}
for (int i = 0; i < planeVerts.length; i+=3) {
planeNormals[i] = 0;
planeNormals[i + 1] = 0;
planeNormals[i + 2] = 1;
}
for (int idx = 0; idx < planeTexCoords.length; idx += 8) {
if (idx % 32 == 0) {
planeTexCoords[idx] = 0;
planeTexCoords[idx + 1] = 0.5f;
planeTexCoords[idx + 2] = 0;
planeTexCoords[idx + 3] = 0;
planeTexCoords[idx + 4] = 0.5f;
planeTexCoords[idx + 5] = 0;
planeTexCoords[idx + 6] = 0.5f;
planeTexCoords[idx + 7] = 0.5f;
} else {
planeTexCoords[idx] = 0;
planeTexCoords[idx + 1] = 1;
planeTexCoords[idx + 2] = 0;
planeTexCoords[idx + 3] = 0.5f;
planeTexCoords[idx + 4] = 0.5f;
planeTexCoords[idx + 5] = 0.5f;
planeTexCoords[idx + 6] = 0.5f;
planeTexCoords[idx + 7] = 1;
}
}
for (int idx = 0; idx < planeTriangles.length; idx += 6) {
planeTriangles[idx] = idx * 4/6;
planeTriangles[idx + 1] = idx * 4/6 + 1;
planeTriangles[idx + 2] = idx * 4/6 + 2;
planeTriangles[idx + 3] = idx * 4/6;
planeTriangles[idx + 4] = idx * 4/6 + 2;
planeTriangles[idx + 5] = idx * 4/6 + 3;
}
return new MeshData(planeVerts, planeTriangles, planeNormals, planeTexCoords);
}
謝謝,禁用深度緩衝區解決問題! – Vecnas