|
|
@@ -12,6 +12,12 @@ import { RenderTarget } from '../../core/RenderTarget.js';
|
|
|
|
|
|
const _size = /*@__PURE__*/ new Vector2();
|
|
|
|
|
|
+/**
|
|
|
+ * Represents the texture of a pass node.
|
|
|
+ *
|
|
|
+ * @augments TextureNode
|
|
|
+ * @private
|
|
|
+ */
|
|
|
class PassTextureNode extends TextureNode {
|
|
|
|
|
|
static get type() {
|
|
|
@@ -20,10 +26,21 @@ class PassTextureNode extends TextureNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new pass texture node.
|
|
|
+ *
|
|
|
+ * @param {PassNode} passNode - The pass node.
|
|
|
+ * @param {Texture} texture - The output texture.
|
|
|
+ */
|
|
|
constructor( passNode, texture ) {
|
|
|
|
|
|
super( texture );
|
|
|
|
|
|
+ /**
|
|
|
+ * A reference to the pass node.
|
|
|
+ *
|
|
|
+ * @type {PassNode}
|
|
|
+ */
|
|
|
this.passNode = passNode;
|
|
|
|
|
|
this.setUpdateMatrix( false );
|
|
|
@@ -46,6 +63,13 @@ class PassTextureNode extends TextureNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * An extension of `PassTextureNode` which allows to manage more than one
|
|
|
+ * internal texture. Relevant for the `getPreviousTexture()` related API.
|
|
|
+ *
|
|
|
+ * @augments PassTextureNode
|
|
|
+ * @private
|
|
|
+ */
|
|
|
class PassMultipleTextureNode extends PassTextureNode {
|
|
|
|
|
|
static get type() {
|
|
|
@@ -54,15 +78,40 @@ class PassMultipleTextureNode extends PassTextureNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new pass texture node.
|
|
|
+ *
|
|
|
+ * @param {PassNode} passNode - The pass node.
|
|
|
+ * @param {String} textureName - The output texture name.
|
|
|
+ * @param {Boolean} [previousTexture=false] - Whether previous frame data should be used or not.
|
|
|
+ */
|
|
|
constructor( passNode, textureName, previousTexture = false ) {
|
|
|
|
|
|
+ // null is passed to the super call since this class does not
|
|
|
+ // use an external texture for rendering pass data into. Instead
|
|
|
+ // the texture is managed by the pass node itself
|
|
|
+
|
|
|
super( passNode, null );
|
|
|
|
|
|
+ /**
|
|
|
+ * The output texture name.
|
|
|
+ *
|
|
|
+ * @type {String}
|
|
|
+ */
|
|
|
this.textureName = textureName;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Whether previous frame data should be used or not.
|
|
|
+ *
|
|
|
+ * @type {Boolean}
|
|
|
+ */
|
|
|
this.previousTexture = previousTexture;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Updates the texture reference of this node.
|
|
|
+ */
|
|
|
updateTexture() {
|
|
|
|
|
|
this.value = this.previousTexture ? this.passNode.getPreviousTexture( this.textureName ) : this.passNode.getTexture( this.textureName );
|
|
|
@@ -85,6 +134,21 @@ class PassMultipleTextureNode extends PassTextureNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * Represents a render pass (sometimes called beauty pass) in context of post processing.
|
|
|
+ * This pass produces a render for the given scene and camera and can provide multiple outputs
|
|
|
+ * via MRT for further processing.
|
|
|
+ *
|
|
|
+ * ```js
|
|
|
+ * const postProcessing = new PostProcessing( renderer );
|
|
|
+ *
|
|
|
+ * const scenePass = pass( scene, camera );
|
|
|
+ *
|
|
|
+ * postProcessing.outputNode = scenePass;
|
|
|
+ * ```
|
|
|
+ *
|
|
|
+ * @augments TempNode
|
|
|
+ */
|
|
|
class PassNode extends TempNode {
|
|
|
|
|
|
static get type() {
|
|
|
@@ -93,17 +157,69 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new pass node.
|
|
|
+ *
|
|
|
+ * @param {('color'|'depth')} scope - The scope of the pass. The scope determines whether the node outputs color or depth.
|
|
|
+ * @param {Scene} scene - A reference to the scene.
|
|
|
+ * @param {Camera} camera - A reference to the camera.
|
|
|
+ * @param {Object} options - Options for the internal render target.
|
|
|
+ */
|
|
|
constructor( scope, scene, camera, options = {} ) {
|
|
|
|
|
|
super( 'vec4' );
|
|
|
|
|
|
+ /**
|
|
|
+ * The scope of the pass. The scope determines whether the node outputs color or depth.
|
|
|
+ *
|
|
|
+ * @type {('color'|'depth')}
|
|
|
+ */
|
|
|
this.scope = scope;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A reference to the scene.
|
|
|
+ *
|
|
|
+ * @type {Scene}
|
|
|
+ */
|
|
|
this.scene = scene;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A reference to the camera.
|
|
|
+ *
|
|
|
+ * @type {camera}
|
|
|
+ */
|
|
|
this.camera = camera;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Options for the internal render target.
|
|
|
+ *
|
|
|
+ * @type {Object}
|
|
|
+ */
|
|
|
this.options = options;
|
|
|
|
|
|
+ /**
|
|
|
+ * The pass's pixel ratio. Will be kept automatically kept in sync with the renderer's pixel ratio.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {Number}
|
|
|
+ * @default 1
|
|
|
+ */
|
|
|
this._pixelRatio = 1;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The pass's pixel width. Will be kept automatically kept in sync with the renderer's width.
|
|
|
+ * @private
|
|
|
+ * @type {Number}
|
|
|
+ * @default 1
|
|
|
+ */
|
|
|
this._width = 1;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The pass's pixel height. Will be kept automatically kept in sync with the renderer's height.
|
|
|
+ * @private
|
|
|
+ * @type {Number}
|
|
|
+ * @default 1
|
|
|
+ */
|
|
|
this._height = 1;
|
|
|
|
|
|
const depthTexture = new DepthTexture();
|
|
|
@@ -115,31 +231,117 @@ class PassNode extends TempNode {
|
|
|
renderTarget.texture.name = 'output';
|
|
|
renderTarget.depthTexture = depthTexture;
|
|
|
|
|
|
+ /**
|
|
|
+ * The pass's render target.
|
|
|
+ *
|
|
|
+ * @type {RenderTarget}
|
|
|
+ */
|
|
|
this.renderTarget = renderTarget;
|
|
|
|
|
|
- this.updateBeforeType = NodeUpdateType.FRAME;
|
|
|
-
|
|
|
+ /**
|
|
|
+ * A dictionary holding the internal result textures.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {Object}
|
|
|
+ */
|
|
|
this._textures = {
|
|
|
output: renderTarget.texture,
|
|
|
depth: depthTexture
|
|
|
};
|
|
|
|
|
|
+ /**
|
|
|
+ * A dictionary holding the internal texture nodes.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {Object}
|
|
|
+ */
|
|
|
this._textureNodes = {};
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A dictionary holding the internal depth nodes.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {Object}
|
|
|
+ */
|
|
|
this._linearDepthNodes = {};
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A dictionary holding the internal viewZ nodes.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {Object}
|
|
|
+ */
|
|
|
this._viewZNodes = {};
|
|
|
|
|
|
+ /**
|
|
|
+ * A dictionary holding the texture data of the previous frame.
|
|
|
+ * Used for computing velocity/motion vectors.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {Object}
|
|
|
+ */
|
|
|
this._previousTextures = {};
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A dictionary holding the texture nodes of the previous frame.
|
|
|
+ * Used for computing velocity/motion vectors.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {Object}
|
|
|
+ */
|
|
|
this._previousTextureNodes = {};
|
|
|
|
|
|
+ /**
|
|
|
+ * The `near` property of the camera as a uniform.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {UniformNode}
|
|
|
+ */
|
|
|
this._cameraNear = uniform( 0 );
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The `far` property of the camera as a uniform.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {UniformNode}
|
|
|
+ */
|
|
|
this._cameraFar = uniform( 0 );
|
|
|
|
|
|
+ /**
|
|
|
+ * A MRT node configuring the MRT settings.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {MRTNode?}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this._mrt = null;
|
|
|
|
|
|
+ /**
|
|
|
+ * This flag can be used for type testing.
|
|
|
+ *
|
|
|
+ * @type {Boolean}
|
|
|
+ * @readonly
|
|
|
+ * @default true
|
|
|
+ */
|
|
|
this.isPassNode = true;
|
|
|
|
|
|
+ /**
|
|
|
+ * The `updateBeforeType` is set to `FRAME` since the pass render the
|
|
|
+ * scene once per frame in its {@link PassNode#updateBefore} method.
|
|
|
+ *
|
|
|
+ * @type {String}
|
|
|
+ * @default 'frame'
|
|
|
+ */
|
|
|
+ this.updateBeforeType = NodeUpdateType.FRAME;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the given MRT node to setup MRT for this pass.
|
|
|
+ *
|
|
|
+ * @param {MRTNode} mrt - The MRT object.
|
|
|
+ * @return {PassNode} A reference to this pass.
|
|
|
+ */
|
|
|
setMRT( mrt ) {
|
|
|
|
|
|
this._mrt = mrt;
|
|
|
@@ -148,18 +350,34 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the current MRT node.
|
|
|
+ *
|
|
|
+ * @return {MRTNode} The current MRT node.
|
|
|
+ */
|
|
|
getMRT() {
|
|
|
|
|
|
return this._mrt;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * The method is overwritten so it always returns `true`.
|
|
|
+ *
|
|
|
+ * @return {Boolean} Whether this node is global or not.
|
|
|
+ */
|
|
|
isGlobal() {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the texture for the given output name.
|
|
|
+ *
|
|
|
+ * @param {String} name - The output name to get the texture for.
|
|
|
+ * @return {Texture} The texture.
|
|
|
+ */
|
|
|
getTexture( name ) {
|
|
|
|
|
|
let texture = this._textures[ name ];
|
|
|
@@ -181,6 +399,12 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the texture holding the data of the previous frame for the given output name.
|
|
|
+ *
|
|
|
+ * @param {String} name - The output name to get the texture for.
|
|
|
+ * @return {Texture} The texture holding the data of the previous frame.
|
|
|
+ */
|
|
|
getPreviousTexture( name ) {
|
|
|
|
|
|
let texture = this._previousTextures[ name ];
|
|
|
@@ -197,6 +421,11 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Switches current and previous textures for the given output name.
|
|
|
+ *
|
|
|
+ * @param {String} name - The output name.
|
|
|
+ */
|
|
|
toggleTexture( name ) {
|
|
|
|
|
|
const prevTexture = this._previousTextures[ name ];
|
|
|
@@ -218,6 +447,12 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the texture node for the given output name.
|
|
|
+ *
|
|
|
+ * @param {String} [name='output'] - The output name to get the texture node for.
|
|
|
+ * @return {TextureNode} The texture node.
|
|
|
+ */
|
|
|
getTextureNode( name = 'output' ) {
|
|
|
|
|
|
let textureNode = this._textureNodes[ name ];
|
|
|
@@ -234,6 +469,12 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns the previous texture node for the given output name.
|
|
|
+ *
|
|
|
+ * @param {String} [name='output'] - The output name to get the previous texture node for.
|
|
|
+ * @return {TextureNode} The previous texture node.
|
|
|
+ */
|
|
|
getPreviousTextureNode( name = 'output' ) {
|
|
|
|
|
|
let textureNode = this._previousTextureNodes[ name ];
|
|
|
@@ -252,6 +493,12 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a viewZ node of this pass.
|
|
|
+ *
|
|
|
+ * @param {String} [name='depth'] - The output name to get the viewZ node for. In most cases the default `'depth'` can be used however the parameter exists for custom depth outputs.
|
|
|
+ * @return {Node} The viewZ node.
|
|
|
+ */
|
|
|
getViewZNode( name = 'depth' ) {
|
|
|
|
|
|
let viewZNode = this._viewZNodes[ name ];
|
|
|
@@ -269,6 +516,12 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns a linear depth node of this pass.
|
|
|
+ *
|
|
|
+ * @param {String} [name='depth'] - The output name to get the linear depth node for. In most cases the default `'depth'` can be used however the parameter exists for custom depth outputs.
|
|
|
+ * @return {Node} The lienar depth node.
|
|
|
+ */
|
|
|
getLinearDepthNode( name = 'depth' ) {
|
|
|
|
|
|
let linearDepthNode = this._linearDepthNodes[ name ];
|
|
|
@@ -337,6 +590,12 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the size of the pass's render target. Honors the pixel ratio.
|
|
|
+ *
|
|
|
+ * @param {Number} width - The width to set.
|
|
|
+ * @param {Number} height - The height to set.
|
|
|
+ */
|
|
|
setSize( width, height ) {
|
|
|
|
|
|
this._width = width;
|
|
|
@@ -349,6 +608,11 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the pixel ratio the pass's render target and updates the size.
|
|
|
+ *
|
|
|
+ * @param {Number} pixelRatio - The pixel ratio to set.
|
|
|
+ */
|
|
|
setPixelRatio( pixelRatio ) {
|
|
|
|
|
|
this._pixelRatio = pixelRatio;
|
|
|
@@ -357,6 +621,9 @@ class PassNode extends TempNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Frees internal resources. Should be called when the node is no longer in use.
|
|
|
+ */
|
|
|
dispose() {
|
|
|
|
|
|
this.renderTarget.dispose();
|