Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 121 additions & 1 deletion src/nodes/display/PassNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { viewZToOrthographicDepth, perspectiveDepthToViewZ } from './ViewportDep

import { HalfFloatType/*, FloatType*/ } from '../../constants.js';
import { Vector2 } from '../../math/Vector2.js';
import { Vector4 } from '../../math/Vector4.js';
import { DepthTexture } from '../../textures/DepthTexture.js';
import { RenderTarget } from '../../core/RenderTarget.js';

Expand Down Expand Up @@ -323,10 +324,43 @@ class PassNode extends TempNode {
*/
this._mrt = null;

/**
* Layer object for configuring the camera that is used
* to produce the pass.
*
* @private
* @type {?Layers}
* @default null
*/
this._layers = null;

/**
* Scales the resolution of the internal render taregt.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: taregt > target

*
* @private
* @type {number}
* @default 1
*/
this._resolution = 1;

/**
* Custom viewport definition.
*
* @private
* @type {?Vector4}
* @default null
*/
this._customViewport = null;
Copy link
Owner

@mrdoob mrdoob Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just this._viewport = null;?
If it's null it just uses the renderer one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the typo and renamed the properties but the fallback to the renderer viewport and scissor needs a bit more though.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


/**
* Custom scissor definition.
*
* @private
* @type {?Vector4}
* @default null
*/
this._customScissor = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just this._scissor = null;?
If it's null it just uses the renderer one.


/**
* This flag can be used for type testing.
*
Expand Down Expand Up @@ -374,14 +408,19 @@ class PassNode extends TempNode {
* Gets the current resolution of the pass.
*
* @return {number} The current resolution. A value of `1` means full resolution.
* @default 1
*/
getResolution() {

return this._resolution;

}

/**
* Sets the layer configuration that should be used when rendering the pass.
*
* @param {Layers} layers - The layers object to set.
* @return {PassNode} A reference to this pass.
*/
setLayers( layers ) {

this._layers = layers;
Expand All @@ -390,6 +429,11 @@ class PassNode extends TempNode {

}

/**
* Gets the current layer configuration of the pass.
*
* @return {?Layers} .
*/
getLayers() {

return this._layers;
Expand Down Expand Up @@ -680,6 +724,82 @@ class PassNode extends TempNode {

this.renderTarget.setSize( effectiveWidth, effectiveHeight );

if ( this._customScissor !== null ) this.renderTarget.scissor.copy( this._customScissor );
if ( this._customViewport !== null ) this.renderTarget.viewport.copy( this._customViewport );

}

/**
* This method allows to define the pass's scissor rectangle. By default, the scissor rectangle is kept
* in sync with the pass's dimensions. To reverse the process and use auto-sizing again, call the method
* with `null` as the single argument.
*
* @param {?(number | Vector4)} x - The horizontal coordinate for the lower left corner of the box in logical pixel unit.
* Instead of passing four arguments, the method also works with a single four-dimensional vector.
* @param {number} y - The vertical coordinate for the lower left corner of the box in logical pixel unit.
* @param {number} width - The width of the scissor box in logical pixel unit.
* @param {number} height - The height of the scissor box in logical pixel unit.
*/
setScissor( x, y, width, height ) {

if ( x === null ) {

this._customScissor = null;

} else {

if ( this._customScissor === null ) this._customScissor = new Vector4();

if ( x.isVector4 ) {

this._customScissor.copy( x );

} else {

this._customScissor.set( x, y, width, height );

}

this._customScissor.multiplyScalar( this._pixelRatio * this._resolution ).floor();

}

}

/**
* This method allows to define the pass's viewport. By default, the viewport is kept in sync
* with the pass's dimensions. To reverse the process and use auto-sizing again, call the method
* with `null` as the single argument.
*
* @param {number | Vector4} x - The horizontal coordinate for the lower left corner of the viewport origin in logical pixel unit.
* @param {number} y - The vertical coordinate for the lower left corner of the viewport origin in logical pixel unit.
* @param {number} width - The width of the viewport in logical pixel unit.
* @param {number} height - The height of the viewport in logical pixel unit.
*/
setViewport( x, y, width, height ) {

if ( x === null ) {

this._customViewport = null;

} else {

if ( this._customViewport === null ) this._customViewport = new Vector4();

if ( x.isVector4 ) {

this._customViewport.copy( x );

} else {

this._customViewport.set( x, y, width, height );

}

this._customViewport.multiplyScalar( this._pixelRatio * this._resolution ).floor();

}

}

/**
Expand Down