Skip to content

Commit

Permalink
Merge pull request #542 from guycalledfrank/zsort
Browse files Browse the repository at this point in the history
Zsort
  • Loading branch information
guycalledfrank committed Mar 2, 2016
2 parents 5805bc9 + 8bba7e3 commit ca82ab1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/scene/forward-renderer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pc.extend(pc, function () {

function sortDrawCalls(drawCallA, drawCallB) {
if (drawCallA.distSqr && drawCallB.distSqr) {
return drawCallB.distSqr - drawCallA.distSqr;
if (drawCallA.zdist && drawCallB.zdist) {
return drawCallB.zdist - drawCallA.zdist;
} else {
return drawCallB.key - drawCallA.key;
}
Expand Down Expand Up @@ -836,6 +836,7 @@ pc.extend(pc, function () {
// Calculate the distance of transparent meshes from the camera
// and cull too
var camPos = camera._node.getPosition();
var camFwd = camera._node.forward;
for (i = 0; i < drawCallsCount; i++) {
drawCall = drawCalls[i];
visible = true;
Expand All @@ -859,9 +860,9 @@ pc.extend(pc, function () {
var tempx = meshPos.x - camPos.x;
var tempy = meshPos.y - camPos.y;
var tempz = meshPos.z - camPos.z;
meshInstance.distSqr = tempx * tempx + tempy * tempy + tempz * tempz;
} else if (meshInstance.distSqr !== undefined) {
delete meshInstance.distSqr;
meshInstance.zdist = tempx*camFwd.x + tempy*camFwd.y + tempz*camFwd.z;
} else if (meshInstance.zdist !== undefined) {
delete meshInstance.zdist;
}
}
}
Expand Down

0 comments on commit ca82ab1

Please sign in to comment.