Skip to content

Commit 6f732bc

Browse files
committed
Update p5.strands hooks documentation based on reviewer feedback
1 parent ede37f1 commit 6f732bc

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

src/webgl/p5.strands.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1+
/**
2+
* @typedef {Object} Vertex
3+
* @property {{x: number, y: number, z: number}} position - The position of the vertex in world space.
4+
* @property {{x: number, y: number, z: number}} normal - The normal vector at the vertex in world space.
5+
* @property {{x: number, y: number}} texCoord - The texture coordinates (x, y) for the vertex.
6+
* @property {{r: number, g: number, b: number, a: number}} color - The color at the vertex.
7+
*/
8+
19
/**
210
* @function getWorldInputs
311
* @experimental
412
* @description
5-
* Registers a callback to modify world-space vertex inputs for each vertex.
6-
* The callback receives an object with the following properties:
7-
* - position: { x, y, z }
8-
* - normal: { x, y, z }
9-
* - texCoord: { x, y }
10-
* - color: { r, g, b, a }
11-
* and should return a modified object with the same structure.
13+
* Registers a callback to modify the world-space properties of each vertex in a shader. This hook can be used inside {@link p5.baseMaterialShader}.modify() and similar shader modify calls to customize vertex positions, normals, texture coordinates, and colors before rendering. "World space" refers to the coordinate system of the 3D scene, before any camera or projection transformations are applied.
1214
*
1315
* This hook is available in:
1416
* - {@link p5.baseMaterialShader}
1517
* - {@link p5.baseNormalShader}
1618
* - {@link p5.baseColorShader}
1719
* - {@link p5.baseStrokeShader}
1820
*
19-
* @param {function(inputs: { position: {x: number, y: number, z: number}, normal: {x: number, y: number, z: number}, texCoord: {x: number, y: number}, color: {r: number, g: number, b: number, a: number} }): object} callback
20-
* A function that receives the current inputs and returns the modified inputs.
21+
* @param {function(Vertex): Vertex} callback
22+
* A callback function which receives and returns a Vertex struct.
23+
*
24+
* @see {@link p5.baseMaterialShader}
25+
* @see {@link p5.Shader#modify}
2126
*
2227
* @example
2328
* <div modernizr='webgl'>
@@ -28,7 +33,7 @@
2833
* myShader = baseMaterialShader().modify(() => {
2934
* getWorldInputs((inputs) => {
3035
* // Move the vertex up and down in a wave
31-
* inputs.position.y += 20 * Math.sin(millis() * 0.001 + inputs.position.x * 0.05);
36+
* inputs.position.y += 20 * sin(millis() * 0.001 + inputs.position.x * 0.05);
3237
* return inputs;
3338
* });
3439
* });
@@ -49,26 +54,19 @@
4954
* @function combineColors
5055
* @experimental
5156
* @description
52-
* Registers a callback to customize how color components are combined in the fragment shader.
53-
* The callback receives an object with the following properties:
54-
* - baseColor: { r, g, b }
55-
* - opacity: number
56-
* - ambientColor: { r, g, b }
57-
* - specularColor: { r, g, b }
58-
* - diffuse: { r, g, b }
59-
* - ambient: { r, g, b }
60-
* - specular: { r, g, b }
61-
* - emissive: { r, g, b }
62-
* and should return an object with a `color` property ({ r, g, b }) and an `opacity` property (number).
57+
* Registers a callback to customize how color components are combined in the fragment shader. This hook can be used inside {@link p5.baseMaterialShader}.modify() and similar shader modify calls to control the final color output of a material. The callback receives a ColorComponents struct and should return an object with a `color` property ({ r, g, b }) and an `opacity` property (number).
6358
*
6459
* This hook is available in:
6560
* - {@link p5.baseMaterialShader}
6661
* - {@link p5.baseNormalShader}
6762
* - {@link p5.baseColorShader}
6863
* - {@link p5.baseStrokeShader}
6964
*
70-
* @param {function(components: { baseColor: {r: number, g: number, b: number}, opacity: number, ambientColor: {r: number, g: number, b: number}, specularColor: {r: number, g: number, b: number}, diffuse: {r: number, g: number, b: number}, ambient: {r: number, g: number, b: number}, specular: {r: number, g: number, b: number}, emissive: {r: number, g: number, b: number} }): { color: {r: number, g: number, b: number}, opacity: number }} callback
71-
* A function that receives the current color components and returns the final color and opacity.
65+
* @param {function(ColorComponents): { color: {r: number, g: number, b: number}, opacity: number }} callback
66+
* A callback function which receives a ColorComponents struct and returns the final color and opacity.
67+
*
68+
* @see {@link p5.baseMaterialShader}
69+
* @see {@link p5.Shader#modify}
7270
*
7371
* @example
7472
* <div modernizr='webgl'>
@@ -113,32 +111,38 @@
113111
* @function getPointSize
114112
* @experimental
115113
* @description
116-
* Registers a callback to modify the size of each point in the point shader.
117-
* The callback receives the current point size (number) and should return the new size (number).
114+
* Registers a callback to modify the size of points when rendering with a shader. This hook can be used inside {@link p5.baseMaterialShader}.modify() or similar, when drawing points (e.g., with the point() function in WEBGL mode). The callback receives the current point size (number) and should return the new size (number).
118115
*
119116
* This hook is available in:
120-
* - {@link p5.pointShader}
117+
* - {@link p5.baseMaterialShader}
118+
* - {@link p5.baseNormalShader}
119+
* - {@link p5.baseColorShader}
120+
* - {@link p5.baseStrokeShader}
121121
*
122122
* @param {function(size: number): number} callback
123-
* A function that receives the current point size and returns the modified size.
123+
* A callback function which receives and returns the point size.
124+
*
125+
* @see {@link p5.baseMaterialShader}
126+
* @see {@link p5.Shader#modify}
124127
*
125128
* @example
126129
* <div modernizr='webgl'>
127130
* <code>
128131
* let myShader;
129132
* function setup() {
130133
* createCanvas(200, 200, WEBGL);
131-
* myShader = pointShader().modify(() => {
134+
* myShader = baseMaterialShader().modify(() => {
132135
* getPointSize((size) => {
133-
* // Make points pulse
134-
* return size * (1 + 0.5 * Math.sin(millis() * 0.001));
136+
* // Make points pulse in size over time
137+
* return size * (1.0 + 0.5 * sin(millis() * 0.002));
135138
* });
136139
* });
137140
* }
138141
* function draw() {
139142
* background(255);
140143
* shader(myShader);
141-
* strokeWeight(10);
144+
* strokeWeight(20);
145+
* stroke('blue');
142146
* point(0, 0);
143147
* }
144148
* </code>

0 commit comments

Comments
 (0)