Use the average of the three triangle vertices (rather than the first

vertex) to compute the depth used for sorting.  There are still annoying 
artifacts, but I've already spent too much time exploring all the ways 
to sort these things.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@31 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Andrzej Kapolka
2006-08-24 23:27:42 +00:00
parent 8e0bdacd05
commit 22b867bb61
2 changed files with 18 additions and 7 deletions
@@ -769,19 +769,29 @@ public class ModelMesh extends TriMesh
d = radius - a*mc.x - b*mc.y - c*mc.z,
dscale = 65535f / (radius * 2);
// premultiply the scale and averaging factor
a *= dscale / 3f;
b *= dscale / 3f;
c *= dscale / 3f;
d *= dscale;
// encode the model's triangles into integers such that the
// high 16 bits represent the original triangle index and the
// low 16 bits represent the distance to the plane. also
// increment the byte counts used for radix sorting
int tcount = getTriangleCount(), idx, idist;
int tcount = getTriangleCount(), idist;
if (_tcodes == null || _tcodes.length < tcount) {
_tcodes = new int[tcount];
}
FloatBuffer vbuf = getVertexBuffer();
for (int ii = 0; ii < tcount; ii++) {
idx = _oibuf[ii*3] * 3;
idist = (int)((a*_vbuf[idx++] + b*_vbuf[idx++] +
c*_vbuf[idx] + d) * dscale);
int i1, i2, i3;
for (int ii = 0, idx = 0; ii < tcount; ii++) {
i1 = _oibuf[idx++] * 3;
i2 = _oibuf[idx++] * 3;
i3 = _oibuf[idx++] * 3;
idist = (int)(
a * (_vbuf[i1++] + _vbuf[i2++] + _vbuf[i3++]) +
b * (_vbuf[i1++] + _vbuf[i2++] + _vbuf[i3++]) +
c * (_vbuf[i1++] + _vbuf[i2++] + _vbuf[i3++]) + d);
_tcodes[ii] = (ii << 16) | idist;
_bcounts[idist & 0xFF]++;
}
@@ -791,7 +801,7 @@ public class ModelMesh extends TriMesh
// reorder the triangles as dictated by the sorted codes, furthest
// triangles first
int icount = tcount * 3;
int icount = tcount * 3, idx;
if (_sibuf == null || _sibuf.length < icount) {
_sibuf = new int[icount];
}
@@ -366,6 +366,7 @@ public class ModelViewer extends JmeCanvasApp
{
super.initDisplay();
_ctx.getRenderer().setBackgroundColor(ColorRGBA.gray);
_ctx.getRenderer().getQueue().setTwoPassTransparency(false);
}
@Override // documentation inherited