Skip to content
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

Node: Document more modules. #30041

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/nodes/core/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ class Node extends EventDispatcher {
* The {@link Node#updateBeforeType} property defines how often the update is executed.
*
* @param {NodeFrame} frame - A reference to the current node frame.
* @return {Boolean?} An optional bool that indicates whether the implementation actually performed an update or not (e.g. due to caching).
*/
updateBefore( /*frame*/ ) {

Expand All @@ -534,6 +535,7 @@ class Node extends EventDispatcher {
* The {@link Node#updateAfterType} property defines how often the update is executed.
*
* @param {NodeFrame} frame - A reference to the current node frame.
* @return {Boolean?} An optional bool that indicates whether the implementation actually performed an update or not (e.g. due to caching).
*/
updateAfter( /*frame*/ ) {

Expand All @@ -546,6 +548,7 @@ class Node extends EventDispatcher {
* The {@link Node#updateType} property defines how often the update is executed.
*
* @param {NodeFrame} frame - A reference to the current node frame.
* @return {Boolean?} An optional bool that indicates whether the implementation actually performed an update or not (e.g. due to caching).
*/
update( /*frame*/ ) {

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/display/PassNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ class PassNode extends TempNode {
this.isPassNode = true;

/**
* The `updateBeforeType` is set to `FRAME` since the pass render the
* The `updateBeforeType` is set to `NodeUpdateType.FRAME` since the node renders the
* scene once per frame in its {@link PassNode#updateBefore} method.
*
* @type {String}
Expand Down
46 changes: 46 additions & 0 deletions src/nodes/display/ScreenNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { Vector4 } from '../../math/Vector4.js';

let screenSizeVec, viewportVec;

/**
* This node provides a collection of screen related metrics.
* Depending on {@link ScreenNode#scope}, the nodes can represent
* resolution or viewport data as well as fragment or uv coordinates.
*
* @augments Node
*/
class ScreenNode extends Node {

static get type() {
Expand All @@ -16,23 +23,55 @@ class ScreenNode extends Node {

}

/**
* Constructs a new screen node.
*
* @param {('coordinate'|'viewport'|'size'|'uv')} scope - The node's scope.
*/
constructor( scope ) {

super();

/**
* The node represents different metric depending on which scope is selected.
*
* - `ScreenNode.COORDINATE`: Window-relative coordinates of the current fragment according to WebGPU standards.
* - `ScreenNode.VIEWPORT`: The current viewport defined as a four-dimnesional vector.
* - `ScreenNode.SIZE`: The dimensions of the current bound framebuffer.
* - `ScreenNode.UV`: Normalized screen coordinates.
*
* @type {('coordinate'|'viewport'|'size'|'uv')}
*/
this.scope = scope;

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isViewportNode = true;

}

/**
* This method is overwritten since the node type depends on the selected scope.
*
* @return {('vec2'|'vec4')} The node type.
*/
getNodeType() {

if ( this.scope === ScreenNode.VIEWPORT ) return 'vec4';
else return 'vec2';

}

/**
* This method is overwritten since the node's update type depends on the selected scope.
*
* @return {NodeUpdateType} The update type.
*/
getUpdateType() {

let updateType = NodeUpdateType.NONE;
Expand All @@ -49,6 +88,13 @@ class ScreenNode extends Node {

}

/**
* `ScreenNode` implements {@link Node#update} to retrieve viewport and size information
* from the current renderer.
*
* @param {NodeFrame} frame - A reference to the current node frame.
* @return {Boolean?} An optional bool that indicates whether the implementation actually performed an update or not (e.g. due to caching).
*/
update( { renderer } ) {

const renderTarget = renderer.getRenderTarget();
Expand Down
38 changes: 38 additions & 0 deletions src/nodes/display/ViewportDepthNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { cameraNear, cameraFar } from '../accessors/Camera.js';
import { positionView } from '../accessors/Position.js';
import { viewportDepthTexture } from './ViewportDepthTextureNode.js';

/**
* This node offers a collection of features in context of the depth logic in the fragment shader.
* Depending on {@link ViewportDepthNode#scope}, it can be used to define a depth value for the current
* fragment or for depth evaluation purposes.
*
* @augments Node
*/
class ViewportDepthNode extends Node {

static get type() {
Expand All @@ -12,13 +19,44 @@ class ViewportDepthNode extends Node {

}

/**
* Constructs a new viewport depth node.
*
* @param {('depth'|'depthBase'|'linearDepth')} scope - The node's scope.
* @param {Node?} [valueNode=null] - The value node.
*/
constructor( scope, valueNode = null ) {

super( 'float' );

/**
* The node behaves differently depending on which scope is selected.
*
* - `ViewportDepthNode.DEPTH_BASE`: Allows to define a value for the current fragment's depth.
* - `ViewportDepthNode.DEPTH`: Represents the depth value for the current fragment (`valueNode` is ignored).
* - `ViewportDepthNode.LINEAR_DEPTH`: Represents the linear (orthographic) depth value of the current fragment.
* If a `valueNode` is set, the scope can be used to convert perspective depth data to linear data.
*
* @type {('depth'|'depthBase'|'linearDepth')}
*/
this.scope = scope;

/**
* Can be used to define a custom depth value.
* The propety is ignored in the `ViewportDepthNode.DEPTH` scope.
*
* @type {Node}
* @default null
*/
this.valueNode = valueNode;

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isViewportDepthNode = true;

}
Expand Down
13 changes: 13 additions & 0 deletions src/nodes/display/ViewportDepthTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { DepthTexture } from '../../textures/DepthTexture.js';

let sharedDepthbuffer = null;

/**
* Represents the depth of the current viewport as a texture. This module
* can be used in combination with viewport texture to achieve effects
* that require depth evaluation.
*
* @augments ViewportTextureNode
*/
class ViewportDepthTextureNode extends ViewportTextureNode {

static get type() {
Expand All @@ -14,6 +21,12 @@ class ViewportDepthTextureNode extends ViewportTextureNode {

}

/**
* Constructs a new viewport shared texture node.
*
* @param {Node} [uvNode=screenUV] - The uv node.
* @param {Node?} [levelNode=null] - The level node.
*/
constructor( uvNode = screenUV, levelNode = null ) {

if ( sharedDepthbuffer === null ) {
Expand Down
13 changes: 13 additions & 0 deletions src/nodes/display/ViewportSharedTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { FramebufferTexture } from '../../textures/FramebufferTexture.js';

let _sharedFramebuffer = null;

/**
* `ViewportTextureNode` creates an internal texture for each node instance. This module
* shares a texture across all instances of `ViewportSharedTextureNode`. It should
Mugen87 marked this conversation as resolved.
Show resolved Hide resolved
* be the first choice when using data of the default/screen framebuffer for performance reasons.
*
* @augments ViewportTextureNode
*/
class ViewportSharedTextureNode extends ViewportTextureNode {

static get type() {
Expand All @@ -14,6 +21,12 @@ class ViewportSharedTextureNode extends ViewportTextureNode {

}

/**
* Constructs a new viewport shared texture node.
*
* @param {Node} [uvNode=screenUV] - The uv node.
* @param {Node?} [levelNode=null] - The level node.
*/
constructor( uvNode = screenUV, levelNode = null ) {

if ( _sharedFramebuffer === null ) {
Expand Down
36 changes: 36 additions & 0 deletions src/nodes/display/ViewportTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import { LinearMipmapLinearFilter } from '../../constants.js';

const _size = /*@__PURE__*/ new Vector2();

/**
* A special type of texture node which represents the data of the current viewport
* as a texture. The module extracts data from the current bound framebuffer with
* a copy operation so no extra render pass is required to produce the texture data
* (which is good for performance). `ViewportTextureNode` can be used as an input for a
* variety of effects like refractive or transmissive materials.
*
* @augments TextureNode
*/
class ViewportTextureNode extends TextureNode {

static get type() {
Expand All @@ -17,6 +26,13 @@ class ViewportTextureNode extends TextureNode {

}

/**
* Constructs a new viewport texture node.
*
* @param {Node} [uvNode=screenUV] - The uv node.
* @param {Node?} [levelNode=null] - The level node.
* @param {Texture?} [framebufferTexture=null] - A framebuffer texture holding the viewport data. If not provided, a framebuffer texture is created automatically.
*/
constructor( uvNode = screenUV, levelNode = null, framebufferTexture = null ) {

if ( framebufferTexture === null ) {
Expand All @@ -28,10 +44,30 @@ class ViewportTextureNode extends TextureNode {

super( framebufferTexture, uvNode, levelNode );

/**
* Whether to generate mipmaps or not.
*
* @type {Boolean}
* @default false
*/
this.generateMipmaps = false;

/**
* This flag can be used for type testing.
*
* @type {Boolean}
* @readonly
* @default true
*/
this.isOutputTextureNode = true;

/**
* The `updateBeforeType` is set to `NodeUpdateType.FRAME` since the node renders the
* scene once per frame in its {@link ViewportTextureNode#updateBefore} method.
*
* @type {String}
* @default 'frame'
*/
this.updateBeforeType = NodeUpdateType.FRAME;

}
Expand Down
Loading
Loading