Skip to content

Commit

Permalink
Renderer: Document more modules. (#30221)
Browse files Browse the repository at this point in the history
* Renderer: Document more modules.

* Fix typo.

* Fix typo.
  • Loading branch information
Mugen87 authored Dec 27, 2024
1 parent 6462c8a commit b35ad2a
Show file tree
Hide file tree
Showing 15 changed files with 634 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/nodes/accessors/BufferAttributeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { StaticDrawUsage, DynamicDrawUsage } from '../../constants.js';
* material.colorNode = bufferAttribute( new THREE.Float32BufferAttribute( colors, 3 ) );
* ```
* This new approach is especially interesting when geometry data are generated via
* compute shaders. The below line converts a storage buffer into an attribute.
* compute shaders. The below line converts a storage buffer into an attribute node.
* ```js
* material.positionNode = positionBuffer.toAttribute();
* ```
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/accessors/StorageBufferNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getTypeFromLength } from '../core/NodeUtils.js';
* storage buffer for data. A typical workflow is to create instances of
* this node with the convenience functions `attributeArray()` or `instancedArray()`,
* setup up a compute shader that writes into the buffers and then convert
* the storage buffers to attributes for rendering.
* the storage buffers to attribute nodes for rendering.
*
* ```js
* const positionBuffer = instancedArray( particleCount, 'vec3' ); // the storage buffer node
Expand Down Expand Up @@ -49,7 +49,7 @@ class StorageBufferNode extends BufferNode {
/**
* Constructs a new storage buffer node.
*
* @param {StorageBufferAttribute|StorageInstancedBufferAttribute} value - The buffer data.
* @param {StorageBufferAttribute|StorageInstancedBufferAttribute|BufferAttribute} value - The buffer data.
* @param {String?} [bufferType=null] - The buffer type (e.g. `'vec3'`).
* @param {Number} [bufferCount=0] - The buffer count.
*/
Expand Down Expand Up @@ -337,7 +337,7 @@ export default StorageBufferNode;
* TSL function for creating a storage buffer node.
*
* @function
* @param {StorageBufferAttribute|StorageInstancedBufferAttribute} value - The buffer data.
* @param {StorageBufferAttribute|StorageInstancedBufferAttribute|BufferAttribute} value - The buffer data.
* @param {String?} [type=null] - The buffer type (e.g. `'vec3'`).
* @param {Number} [count=0] - The buffer count.
* @returns {StorageBufferNode}
Expand Down
49 changes: 49 additions & 0 deletions src/objects/ClippingGroup.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,64 @@
import { Group } from './Group.js';

/**
* In earlier three.js versions, clipping was defined globally
* on the renderer or on material level. This special version of
* `THREE.Group` allows to encode the clipping state into the scene
* graph. Meaning if you create an instance of this group, all
* descendant 3D objects will be affected by the respective clipping
* planes.
*
* Note: `ClippingGroup` can only be used with `WebGPURenderer`.
*
* @augments Group
*/
class ClippingGroup extends Group {

/**
* Constructs a new clipping group.
*/
constructor() {

super();

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

/**
* An array with clipping planes.
*
* @type {Array<Plane>}
*/
this.clippingPlanes = [];

/**
* Whether clipping should be enabled or not.
*
* @type {Boolean}
* @default true
*/
this.enabled = true;

/**
* Whether the intersection of the clipping planes is used to clip objects, rather than their union.
*
* @type {Boolean}
* @default false
*/
this.clipIntersection = false;

/**
* Whether shadows should be clipped or not.
*
* @type {Boolean}
* @default false
*/
this.clipShadows = false;

}
Expand Down
35 changes: 35 additions & 0 deletions src/renderers/common/Binding.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
/**
* A binding represents the connection between a resource (like a texture, sampler
* or uniform buffer) and the resource definition in a shader stage.
*
* This module is an abstract base class for all concrete bindings types.
*
* @abstract
* @private
*/
class Binding {

/**
* Constructs a new binding.
*
* @param {String} [name=''] - The binding's name.
*/
constructor( name = '' ) {

/**
* The binding's name.
*
* @type {String}
*/
this.name = name;

/**
* A bitmask that defines in what shader stages the
* binding's resource is accessible.
*
* @type {String}
*/
this.visibility = 0;

}

/**
* Makes sure binding's resource is visible for the given shader stage.
*
* @param {Number} visibility - The shader stage.
*/
setVisibility( visibility ) {

this.visibility |= visibility;

}

/**
* Clones the binding.
*
* @return {Binding} The cloned binding.
*/
clone() {

return Object.assign( new this.constructor(), this );
Expand Down
49 changes: 49 additions & 0 deletions src/renderers/common/Buffer.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,81 @@
import Binding from './Binding.js';
import { getFloatLength } from './BufferUtils.js';

/**
* Represents a buffer binding type.
*
* @private
* @abstract
* @augments Binding
*/
class Buffer extends Binding {

/**
* Constructs a new buffer.
*
* @param {String} name - The buffer's name.
* @param {TypedArray} [buffer=null] - The buffer.
*/
constructor( name, buffer = null ) {

super( name );

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

/**
* The bytes per element.
*
* @type {Number}
*/
this.bytesPerElement = Float32Array.BYTES_PER_ELEMENT;

/**
* A reference to the internal buffer.
*
* @private
* @type {TypedArray}
*/
this._buffer = buffer;

}

/**
* The buffer's byte length.
*
* @type {Number}
* @readonly
*/
get byteLength() {

return getFloatLength( this._buffer.byteLength );

}

/**
* A reference to the internal buffer.
*
* @type {Number}
* @readonly
*/
get buffer() {

return this._buffer;

}

/**
* Updates the binding.
*
* @return {Boolean} Whether the buffer has been updated and must be
* uploaded to the GPU.
*/
update() {

return true;
Expand Down
Loading

0 comments on commit b35ad2a

Please sign in to comment.