Skip to content

Commit

Permalink
Node: Document more modules. (mrdoob#30100)
Browse files Browse the repository at this point in the history
* Node: Document more modules.

* Fix typo.
  • Loading branch information
Mugen87 authored Dec 11, 2024
1 parent de85929 commit 6a4309b
Show file tree
Hide file tree
Showing 39 changed files with 1,033 additions and 18 deletions.
49 changes: 49 additions & 0 deletions src/nodes/accessors/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,60 @@ import { uniform } from '../core/UniformNode.js';
import { renderGroup } from '../core/UniformGroupNode.js';
import { Vector3 } from '../../math/Vector3.js';

/** @module Camera **/

/**
* TSL object that represents the `near` value of the camera used for the current render.
*
* @type {UniformNode<float>}
*/
export const cameraNear = /*@__PURE__*/ uniform( 'float' ).label( 'cameraNear' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.near );

/**
* TSL object that represents the `far` value of the camera used for the current render.
*
* @type {UniformNode<float>}
*/
export const cameraFar = /*@__PURE__*/ uniform( 'float' ).label( 'cameraFar' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.far );

/**
* TSL object that represents the projection matrix of the camera used for the current render.
*
* @type {UniformNode<mat4>}
*/
export const cameraProjectionMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraProjectionMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.projectionMatrix );

/**
* TSL object that represents the inverse projection matrix of the camera used for the current render.
*
* @type {UniformNode<mat4>}
*/
export const cameraProjectionMatrixInverse = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraProjectionMatrixInverse' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.projectionMatrixInverse );

/**
* TSL object that represents the view matrix of the camera used for the current render.
*
* @type {UniformNode<mat4>}
*/
export const cameraViewMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraViewMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.matrixWorldInverse );

/**
* TSL object that represents the world matrix of the camera used for the current render.
*
* @type {UniformNode<mat4>}
*/
export const cameraWorldMatrix = /*@__PURE__*/ uniform( 'mat4' ).label( 'cameraWorldMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.matrixWorld );

/**
* TSL object that represents the normal matrix of the camera used for the current render.
*
* @type {UniformNode<mat3>}
*/
export const cameraNormalMatrix = /*@__PURE__*/ uniform( 'mat3' ).label( 'cameraNormalMatrix' ).setGroup( renderGroup ).onRenderUpdate( ( { camera } ) => camera.normalMatrix );

/**
* TSL object that represents the positon in world space of the camera used for the current render.
*
* @type {UniformNode<vec3>}
*/
export const cameraPosition = /*@__PURE__*/ uniform( new Vector3() ).label( 'cameraPosition' ).setGroup( renderGroup ).onRenderUpdate( ( { camera }, self ) => self.value.setFromMatrixPosition( camera.matrixWorld ) );
26 changes: 26 additions & 0 deletions src/nodes/accessors/PointUVNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import Node from '../core/Node.js';
import { nodeImmutable } from '../tsl/TSLBase.js';

/** @module PointUVNode **/

/**
* A node for representing the uv coordinates of points.
*
* Can only be used with a WebGL backend. In WebGPU, point
* primitives always have the size of one pixel and can thus
* can't be used as sprite-like objects that display textures.
*
* @augments Node
*/
class PointUVNode extends Node {

static get type() {
Expand All @@ -9,10 +20,20 @@ class PointUVNode extends Node {

}

/**
* Constructs a new point uv node.
*/
constructor() {

super( 'vec2' );

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

}
Expand All @@ -27,4 +48,9 @@ class PointUVNode extends Node {

export default PointUVNode;

/**
* TSL object that represents the uv coordinates of points.
*
* @type {PointUVNode}
*/
export const pointUV = /*@__PURE__*/ nodeImmutable( PointUVNode );
44 changes: 44 additions & 0 deletions src/nodes/accessors/Position.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
import { attribute } from '../core/AttributeNode.js';
import { modelWorldMatrix, modelViewMatrix } from './ModelNode.js';

/** @module Position **/

/**
* TSL object that represents the position attribute of the current rendered object.
*
* @type {AttributeNode<vec3>}
*/
export const positionGeometry = /*@__PURE__*/ attribute( 'position', 'vec3' );

/**
* TSL object that represents the vertex position in local space of the current rendered object.
*
* @type {AttributeNode<vec3>}
*/
export const positionLocal = /*@__PURE__*/ positionGeometry.varying( 'positionLocal' );

/**
* TSL object that represents the previous vertex position in local space of the current rendered object.
* Used in context of {@link VelocityNode} for rendering motion vectors.
*
* @type {AttributeNode<vec3>}
*/
export const positionPrevious = /*@__PURE__*/ positionGeometry.varying( 'positionPrevious' );

/**
* TSL object that represents the vertex position in world space of the current rendered object.
*
* @type {VaryingNode<vec3>}
*/
export const positionWorld = /*@__PURE__*/ modelWorldMatrix.mul( positionLocal ).xyz.varying( 'v_positionWorld' );

/**
* TSL object that represents the position world direction of the current rendered object.
*
* @type {Node<vec3>}
*/
export const positionWorldDirection = /*@__PURE__*/ positionLocal.transformDirection( modelWorldMatrix ).varying( 'v_positionWorldDirection' ).normalize().toVar( 'positionWorldDirection' );

/**
* TSL object that represents the vertex position in view space of the current rendered object.
*
* @type {VaryingNode<vec3>}
*/
export const positionView = /*@__PURE__*/ modelViewMatrix.mul( positionLocal ).xyz.varying( 'v_positionView' );

/**
* TSL object that represents the position view direction of the current rendered object.
*
* @type {VaryingNode<vec3>}
*/
export const positionViewDirection = /*@__PURE__*/ positionView.negate().varying( 'v_positionViewDirection' ).normalize().toVar( 'positionViewDirection' );
Loading

0 comments on commit 6a4309b

Please sign in to comment.