diff --git a/docs/api/en/renderers/WebGLRenderer.html b/docs/api/en/renderers/WebGLRenderer.html index fa6d70613dab36..f9927c33389660 100644 --- a/docs/api/en/renderers/WebGLRenderer.html +++ b/docs/api/en/renderers/WebGLRenderer.html @@ -471,6 +471,16 @@

[method:null setScissorTest]( [param:Boolean boolean] )

scissor area will be affected by further renderer actions.

+

[method:null setOpaqueSort]( [param:Function method] )

+

+ Sets the custom opaque sort function for the WebGLRenderLists. Pass null to use the default painterSortStable function. +

+ +

[method:null setTransparentSort]( [param:Function method] )

+

+ Sets the custom transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function. +

+

[method:null setSize]( [param:Integer width], [param:Integer height], [param:Boolean updateStyle] )

Resizes the output canvas to (width, height) with device pixel ratio taken into account, diff --git a/src/renderers/WebGLRenderer.d.ts b/src/renderers/WebGLRenderer.d.ts index 1a032a2edcee3e..807c1b4cecb9ae 100644 --- a/src/renderers/WebGLRenderer.d.ts +++ b/src/renderers/WebGLRenderer.d.ts @@ -258,6 +258,16 @@ export class WebGLRenderer implements Renderer { */ setScissorTest( enable: boolean ): void; + /** + * Sets the custom opaque sort function for the WebGLRenderLists. Pass null to use the default painterSortStable function. + */ + setOpaqueSort( method: Function ): void; + + /** + * Sets the custom transparent sort function for the WebGLRenderLists. Pass null to use the default reversePainterSortStable function. + */ + setTransparentSort( method: Function ): void; + /** * Returns a THREE.Color instance with the current clear color. */ diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 3b1db85a076be4..8fdc4e7223f854 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -162,6 +162,8 @@ function WebGLRenderer( parameters ) { _height = _canvas.height, _pixelRatio = 1, + _opaqueSort = null, + _transparentSort = null, _viewport = new Vector4( 0, 0, _width, _height ), _scissor = new Vector4( 0, 0, _width, _height ), @@ -505,6 +507,18 @@ function WebGLRenderer( parameters ) { }; + this.setOpaqueSort = function ( method ) { + + _opaqueSort = method; + + }; + + this.setTransparentSort = function ( method ) { + + _transparentSort = method; + + }; + // Clearing this.getClearColor = function () { @@ -1154,7 +1168,7 @@ function WebGLRenderer( parameters ) { if ( _this.sortObjects === true ) { - currentRenderList.sort(); + currentRenderList.sort( _opaqueSort, _transparentSort ); } diff --git a/src/renderers/webgl/WebGLRenderLists.js b/src/renderers/webgl/WebGLRenderLists.js index d48262cd838bae..f12376f3c2f0e5 100644 --- a/src/renderers/webgl/WebGLRenderLists.js +++ b/src/renderers/webgl/WebGLRenderLists.js @@ -130,10 +130,10 @@ function WebGLRenderList() { } - function sort() { + function sort( customOpaqueSort, customTransparentSort ) { - if ( opaque.length > 1 ) opaque.sort( painterSortStable ); - if ( transparent.length > 1 ) transparent.sort( reversePainterSortStable ); + if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable ); + if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable ); }