Browse Source

Fix renderPass depth sort not being stable.

TothBenoit 11 months ago
parent
commit
33813afa08
1 changed files with 18 additions and 2 deletions
  1. 18 2
      h3d/scene/Renderer.hx

+ 18 - 2
h3d/scene/Renderer.hx

@@ -106,9 +106,25 @@ class Renderer extends hxd.impl.AnyProps {
 			p.depth = w > 0.0 ? z / w : - z / w;
 		}
 		if( frontToBack )
-			passes.sort(function(p1, p2) return p1.pass.layer == p2.pass.layer ? (p1.depth > p2.depth ? 1 : -1) : p1.pass.layer - p2.pass.layer);
+			passes.sort(
+				function(p1, p2) {
+					if ( p1.pass.layer != p2.pass.layer )
+						return p1.pass.layer - p2.pass.layer;
+					if ( p1.depth == p2.depth )
+						return 0;
+					return p1.depth > p2.depth ? 1 : -1;
+				}
+			);
 		else
-			passes.sort(function(p1, p2) return p1.pass.layer == p2.pass.layer ? (p1.depth > p2.depth ? -1 : 1) : p1.pass.layer - p2.pass.layer);
+			passes.sort(
+				function(p1, p2) {
+					if ( p1.pass.layer != p2.pass.layer )
+						return p1.pass.layer - p2.pass.layer;
+					if ( p1.depth == p2.depth )
+						return 0;
+					return p1.depth < p2.depth ? 1 : -1;
+				}
+			);
 	}
 
 	inline function clear( ?color, ?depth, ?stencil ) {