-
-
Notifications
You must be signed in to change notification settings - Fork 36k
PassNode: Provide viewport and scissor API. #31390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
bc6d536
7805aba
e1e38a1
ef7c078
2512a47
a7ac0b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
||
|
@@ -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. | ||
* | ||
* @private | ||
* @type {number} | ||
* @default 1 | ||
*/ | ||
this._resolution = 1; | ||
|
||
/** | ||
* Custom viewport definition. | ||
* | ||
* @private | ||
* @type {?Vector4} | ||
* @default null | ||
*/ | ||
this._customViewport = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about just There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
|
||
/** | ||
* Custom scissor definition. | ||
* | ||
* @private | ||
* @type {?Vector4} | ||
* @default null | ||
*/ | ||
this._customScissor = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about just |
||
|
||
/** | ||
* This flag can be used for type testing. | ||
* | ||
|
@@ -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; | ||
|
@@ -390,6 +429,11 @@ class PassNode extends TempNode { | |
|
||
} | ||
|
||
/** | ||
* Gets the current layer configuration of the pass. | ||
* | ||
* @return {?Layers} . | ||
*/ | ||
getLayers() { | ||
|
||
return this._layers; | ||
|
@@ -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(); | ||
|
||
} | ||
|
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: taregt > target