Просмотр исходного кода

Documentation: `NodeMaterial.setupOutput` and TSL `positionLocal` (#33791)

Co-authored-by: chelgeson1click <chelgeson@1clicklogistics.com>
Christian Helgeson 3 дней назад
Родитель
Сommit
51c961b9f3
2 измененных файлов с 25 добавлено и 1 удалено
  1. 20 0
      src/materials/nodes/NodeMaterial.js
  2. 5 1
      src/nodes/accessors/Position.js

+ 20 - 0
src/materials/nodes/NodeMaterial.js

@@ -1157,6 +1157,26 @@ class NodeMaterial extends Material {
 	/**
 	 * Setups the output node.
 	 *
+	 * This method can be implemented by derived materials to extend the functionality
+	 * of the material's output or replace it altogether.
+	 *
+	 * ```js
+	 * class ColoredShadowMaterial extends MeshPhongNodeMaterial {
+	 *   constructor( parameters ) {
+	 *     super( parameters );
+	 *     this._shadeColor = uniform( new Color( parameters.shadeColor ?? 0xff0000 ) );
+	 *   }
+	 *
+	 *   setupOutput( builder, outputNode ) {
+	 *	   // Modify the native output of the MeshPhongNodeMaterial fragment shader
+	 *     const brightness = min( outputNode.r, 1.0 );
+	 *     const mixedColor = mix( this._shadeColor, diffuseColor.rgb, brightness );
+	 *	   // Return new output back into NodeMaterial flow
+	 *     return super.setupOutput( builder, vec4( mixedColor, outputNode.a ) );
+	 *   }
+	 * }
+	 * ```
+	 *
 	 * @param {NodeBuilder} builder - The current node builder.
 	 * @param {Node<vec4>} outputNode - The existing output node.
 	 * @return {Node<vec4>} The output node.

+ 5 - 1
src/nodes/accessors/Position.js

@@ -33,7 +33,11 @@ export const clipSpace = /*@__PURE__*/ ( Fn( ( builder ) => {
 export const positionGeometry = /*@__PURE__*/ attribute( 'position', 'vec3' );
 
 /**
- * TSL object that represents the vertex position in local space of the current rendered object.
+ * TSL object that represents the transformed vertex position in local space of the current rendered object.
+ *
+ * The term "transformed" indicates that an object or material's properties, such as skinning, batch,
+ * instancing, or displacement mapping, will change the vertex position of the node when present.
+ * To use the pre-transformed local space position of the object, use {@link positionGeometry}.
  *
  * @tsl
  * @type {AttributeNode<vec3>}

粤ICP备19079148号