Skip to content

Commit ede37f1

Browse files
committed
Add doc comments for getWorldInputs, combineColors, getPointSize
1 parent ae09118 commit ede37f1

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

src/webgl/p5.strands.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/**
2+
* @function getWorldInputs
3+
* @experimental
4+
* @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.
12+
*
13+
* This hook is available in:
14+
* - {@link p5.baseMaterialShader}
15+
* - {@link p5.baseNormalShader}
16+
* - {@link p5.baseColorShader}
17+
* - {@link p5.baseStrokeShader}
18+
*
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+
*
22+
* @example
23+
* <div modernizr='webgl'>
24+
* <code>
25+
* let myShader;
26+
* function setup() {
27+
* createCanvas(200, 200, WEBGL);
28+
* myShader = baseMaterialShader().modify(() => {
29+
* getWorldInputs((inputs) => {
30+
* // Move the vertex up and down in a wave
31+
* inputs.position.y += 20 * Math.sin(millis() * 0.001 + inputs.position.x * 0.05);
32+
* return inputs;
33+
* });
34+
* });
35+
* }
36+
* function draw() {
37+
* background(255);
38+
* shader(myShader);
39+
* lights();
40+
* noStroke();
41+
* fill('red');
42+
* sphere(50);
43+
* }
44+
* </code>
45+
* </div>
46+
*/
47+
48+
/**
49+
* @function combineColors
50+
* @experimental
51+
* @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).
63+
*
64+
* This hook is available in:
65+
* - {@link p5.baseMaterialShader}
66+
* - {@link p5.baseNormalShader}
67+
* - {@link p5.baseColorShader}
68+
* - {@link p5.baseStrokeShader}
69+
*
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.
72+
*
73+
* @example
74+
* <div modernizr='webgl'>
75+
* <code>
76+
* let myShader;
77+
* function setup() {
78+
* createCanvas(200, 200, WEBGL);
79+
* myShader = baseMaterialShader().modify(() => {
80+
* combineColors((components) => {
81+
* // Custom color combination: add a red tint
82+
* let color = {
83+
* r: components.baseColor.r * components.diffuse.r +
84+
* components.ambientColor.r * components.ambient.r +
85+
* components.specularColor.r * components.specular.r +
86+
* components.emissive.r + 0.2,
87+
* g: components.baseColor.g * components.diffuse.g +
88+
* components.ambientColor.g * components.ambient.g +
89+
* components.specularColor.g * components.specular.g +
90+
* components.emissive.g,
91+
* b: components.baseColor.b * components.diffuse.b +
92+
* components.ambientColor.b * components.ambient.b +
93+
* components.specularColor.b * components.specular.b +
94+
* components.emissive.b
95+
* };
96+
* return { color, opacity: components.opacity };
97+
* });
98+
* });
99+
* }
100+
* function draw() {
101+
* background(255);
102+
* shader(myShader);
103+
* lights();
104+
* noStroke();
105+
* fill('red');
106+
* sphere(50);
107+
* }
108+
* </code>
109+
* </div>
110+
*/
111+
112+
/**
113+
* @function getPointSize
114+
* @experimental
115+
* @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).
118+
*
119+
* This hook is available in:
120+
* - {@link p5.pointShader}
121+
*
122+
* @param {function(size: number): number} callback
123+
* A function that receives the current point size and returns the modified size.
124+
*
125+
* @example
126+
* <div modernizr='webgl'>
127+
* <code>
128+
* let myShader;
129+
* function setup() {
130+
* createCanvas(200, 200, WEBGL);
131+
* myShader = pointShader().modify(() => {
132+
* getPointSize((size) => {
133+
* // Make points pulse
134+
* return size * (1 + 0.5 * Math.sin(millis() * 0.001));
135+
* });
136+
* });
137+
* }
138+
* function draw() {
139+
* background(255);
140+
* shader(myShader);
141+
* strokeWeight(10);
142+
* point(0, 0);
143+
* }
144+
* </code>
145+
* </div>
146+
*/

0 commit comments

Comments
 (0)