|
|
@@ -11,6 +11,14 @@ import { HalfFloatType } from '../../constants.js';
|
|
|
|
|
|
const _size = /*@__PURE__*/ new Vector2();
|
|
|
|
|
|
+/**
|
|
|
+ * `RTTNode` takes another node and uses it with a `QuadMesh` to render into a texture (RTT).
|
|
|
+ * This module is especially relevant in context of post processing where certain nodes require
|
|
|
+ * texture input for their effects. With the helper function `convertToTexture()` which is based
|
|
|
+ * on this module, the node system can automatically ensure texture input if required.
|
|
|
+ *
|
|
|
+ * @augments Node
|
|
|
+ */
|
|
|
class RTTNode extends TextureNode {
|
|
|
|
|
|
static get type() {
|
|
|
@@ -19,30 +27,110 @@ class RTTNode extends TextureNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Constructs a new RTT node.
|
|
|
+ *
|
|
|
+ * @param {Node} node - The node to render a texture with.
|
|
|
+ * @param {Number?} [width=null] - The width of the internal render target. If not width is applied, the render target is automatically resized.
|
|
|
+ * @param {Number?} [height=null] - The height of the internal render target.
|
|
|
+ * @param {Object} [options={type:HalfFloatType}] - The options for the internal render target.
|
|
|
+ */
|
|
|
constructor( node, width = null, height = null, options = { type: HalfFloatType } ) {
|
|
|
|
|
|
const renderTarget = new RenderTarget( width, height, options );
|
|
|
|
|
|
super( renderTarget.texture, uv() );
|
|
|
|
|
|
+ /**
|
|
|
+ * The node to render a texture with.
|
|
|
+ *
|
|
|
+ * @type {Node}
|
|
|
+ */
|
|
|
this.node = node;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The width of the internal render target.
|
|
|
+ * If not width is applied, the render target is automatically resized.
|
|
|
+ *
|
|
|
+ * @type {Number?}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this.width = width;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The height of the internal render target.
|
|
|
+ *
|
|
|
+ * @type {Number?}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this.height = height;
|
|
|
|
|
|
+ /**
|
|
|
+ * The pixel ratio
|
|
|
+ *
|
|
|
+ * @type {Number}
|
|
|
+ * @default 1
|
|
|
+ */
|
|
|
+ this.pixelRatio = 1;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The render target
|
|
|
+ *
|
|
|
+ * @type {RenderTarget}
|
|
|
+ */
|
|
|
this.renderTarget = renderTarget;
|
|
|
|
|
|
+ /**
|
|
|
+ * Whether the texture requires an update or not.
|
|
|
+ *
|
|
|
+ * @type {Boolean}
|
|
|
+ * @default true
|
|
|
+ */
|
|
|
this.textureNeedsUpdate = true;
|
|
|
- this.autoUpdate = true;
|
|
|
|
|
|
- this.updateMap = new WeakMap();
|
|
|
+ /**
|
|
|
+ * Whether the texture should automatically be updated or not.
|
|
|
+ *
|
|
|
+ * @type {Boolean}
|
|
|
+ * @default true
|
|
|
+ */
|
|
|
+ this.autoUpdate = true;
|
|
|
|
|
|
+ /**
|
|
|
+ * The node which is used with the quad mesh for RTT.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {Node}
|
|
|
+ * @default null
|
|
|
+ */
|
|
|
this._rttNode = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The internal quad mesh for RTT.
|
|
|
+ *
|
|
|
+ * @private
|
|
|
+ * @type {QuadMesh}
|
|
|
+ */
|
|
|
this._quadMesh = new QuadMesh( new NodeMaterial() );
|
|
|
|
|
|
+ /**
|
|
|
+ * The `updateBeforeType` is set to `NodeUpdateType.RENDER` since the node updates
|
|
|
+ * the texture once per render in its {@link RTTNode#updateBefore} method.
|
|
|
+ *
|
|
|
+ * @type {String}
|
|
|
+ * @default 'render'
|
|
|
+ */
|
|
|
this.updateBeforeType = NodeUpdateType.RENDER;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Whether the internal render target should automatically be resized or not.
|
|
|
+ *
|
|
|
+ * @type {Boolean}
|
|
|
+ * @readonly
|
|
|
+ * @default true
|
|
|
+ */
|
|
|
get autoSize() {
|
|
|
|
|
|
return this.width === null;
|
|
|
@@ -59,6 +147,12 @@ class RTTNode extends TextureNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the size of the internal render target
|
|
|
+ *
|
|
|
+ * @param {Number} width - The width to set.
|
|
|
+ * @param {Number} height - The width to set.
|
|
|
+ */
|
|
|
setSize( width, height ) {
|
|
|
|
|
|
this.width = width;
|
|
|
@@ -73,6 +167,11 @@ class RTTNode extends TextureNode {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the pixel ratio. This will also resize the render target.
|
|
|
+ *
|
|
|
+ * @param {Number} pixelRatio - The pixel ratio to set.
|
|
|
+ */
|
|
|
setPixelRatio( pixelRatio ) {
|
|
|
|
|
|
this.pixelRatio = pixelRatio;
|