@@ -7,6 +7,7 @@ import { viewZToOrthographicDepth, perspectiveDepthToViewZ } from './ViewportDep
7
7
8
8
import { HalfFloatType /*, FloatType*/ } from '../../constants.js' ;
9
9
import { Vector2 } from '../../math/Vector2.js' ;
10
+ import { Vector4 } from '../../math/Vector4.js' ;
10
11
import { DepthTexture } from '../../textures/DepthTexture.js' ;
11
12
import { RenderTarget } from '../../core/RenderTarget.js' ;
12
13
@@ -323,10 +324,43 @@ class PassNode extends TempNode {
323
324
*/
324
325
this . _mrt = null ;
325
326
327
+ /**
328
+ * Layer object for configuring the camera that is used
329
+ * to produce the pass.
330
+ *
331
+ * @private
332
+ * @type {?Layers }
333
+ * @default null
334
+ */
326
335
this . _layers = null ;
327
336
337
+ /**
338
+ * Scales the resolution of the internal render taregt.
339
+ *
340
+ * @private
341
+ * @type {number }
342
+ * @default 1
343
+ */
328
344
this . _resolution = 1 ;
329
345
346
+ /**
347
+ * Custom viewport definition.
348
+ *
349
+ * @private
350
+ * @type {?Vector4 }
351
+ * @default null
352
+ */
353
+ this . _customViewport = null ;
354
+
355
+ /**
356
+ * Custom scissor definition.
357
+ *
358
+ * @private
359
+ * @type {?Vector4 }
360
+ * @default null
361
+ */
362
+ this . _customScissor = null ;
363
+
330
364
/**
331
365
* This flag can be used for type testing.
332
366
*
@@ -374,14 +408,19 @@ class PassNode extends TempNode {
374
408
* Gets the current resolution of the pass.
375
409
*
376
410
* @return {number } The current resolution. A value of `1` means full resolution.
377
- * @default 1
378
411
*/
379
412
getResolution ( ) {
380
413
381
414
return this . _resolution ;
382
415
383
416
}
384
417
418
+ /**
419
+ * Sets the layer configuration that should be used when rendering the pass.
420
+ *
421
+ * @param {Layers } layers - The layers object to set.
422
+ * @return {PassNode } A reference to this pass.
423
+ */
385
424
setLayers ( layers ) {
386
425
387
426
this . _layers = layers ;
@@ -390,6 +429,11 @@ class PassNode extends TempNode {
390
429
391
430
}
392
431
432
+ /**
433
+ * Gets the current layer configuration of the pass.
434
+ *
435
+ * @return {?Layers } .
436
+ */
393
437
getLayers ( ) {
394
438
395
439
return this . _layers ;
@@ -680,6 +724,82 @@ class PassNode extends TempNode {
680
724
681
725
this . renderTarget . setSize ( effectiveWidth , effectiveHeight ) ;
682
726
727
+ if ( this . _customScissor !== null ) this . renderTarget . scissor . copy ( this . _customScissor ) ;
728
+ if ( this . _customViewport !== null ) this . renderTarget . viewport . copy ( this . _customViewport ) ;
729
+
730
+ }
731
+
732
+ /**
733
+ * This method allows to define the pass's scissor rectangle. By default, the scissor rectangle is kept
734
+ * in sync with the pass's dimensions. To reverse the process and use auto-sizing again, call the method
735
+ * with `null` as the single argument.
736
+ *
737
+ * @param {?(number | Vector4) } x - The horizontal coordinate for the lower left corner of the box in logical pixel unit.
738
+ * Instead of passing four arguments, the method also works with a single four-dimensional vector.
739
+ * @param {number } y - The vertical coordinate for the lower left corner of the box in logical pixel unit.
740
+ * @param {number } width - The width of the scissor box in logical pixel unit.
741
+ * @param {number } height - The height of the scissor box in logical pixel unit.
742
+ */
743
+ setScissor ( x , y , width , height ) {
744
+
745
+ if ( x === null ) {
746
+
747
+ this . _customScissor = null ;
748
+
749
+ } else {
750
+
751
+ if ( this . _customScissor === null ) this . _customScissor = new Vector4 ( ) ;
752
+
753
+ if ( x . isVector4 ) {
754
+
755
+ this . _customScissor . copy ( x ) ;
756
+
757
+ } else {
758
+
759
+ this . _customScissor . set ( x , y , width , height ) ;
760
+
761
+ }
762
+
763
+ this . _customScissor . multiplyScalar ( this . _pixelRatio * this . _resolution ) . floor ( ) ;
764
+
765
+ }
766
+
767
+ }
768
+
769
+ /**
770
+ * This method allows to define the pass's viewport. By default, the viewport is kept in sync
771
+ * with the pass's dimensions. To reverse the process and use auto-sizing again, call the method
772
+ * with `null` as the single argument.
773
+ *
774
+ * @param {number | Vector4 } x - The horizontal coordinate for the lower left corner of the viewport origin in logical pixel unit.
775
+ * @param {number } y - The vertical coordinate for the lower left corner of the viewport origin in logical pixel unit.
776
+ * @param {number } width - The width of the viewport in logical pixel unit.
777
+ * @param {number } height - The height of the viewport in logical pixel unit.
778
+ */
779
+ setViewport ( x , y , width , height ) {
780
+
781
+ if ( x === null ) {
782
+
783
+ this . _customViewport = null ;
784
+
785
+ } else {
786
+
787
+ if ( this . _customViewport === null ) this . _customViewport = new Vector4 ( ) ;
788
+
789
+ if ( x . isVector4 ) {
790
+
791
+ this . _customViewport . copy ( x ) ;
792
+
793
+ } else {
794
+
795
+ this . _customViewport . set ( x , y , width , height ) ;
796
+
797
+ }
798
+
799
+ this . _customViewport . multiplyScalar ( this . _pixelRatio * this . _resolution ) . floor ( ) ;
800
+
801
+ }
802
+
683
803
}
684
804
685
805
/**
0 commit comments