|
| 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 | + |
1 | 9 | /**
|
2 | 10 | * @function getWorldInputs
|
3 | 11 | * @experimental
|
4 | 12 | * @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. |
12 | 14 | *
|
13 | 15 | * This hook is available in:
|
14 | 16 | * - {@link p5.baseMaterialShader}
|
15 | 17 | * - {@link p5.baseNormalShader}
|
16 | 18 | * - {@link p5.baseColorShader}
|
17 | 19 | * - {@link p5.baseStrokeShader}
|
18 | 20 | *
|
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} |
21 | 26 | *
|
22 | 27 | * @example
|
23 | 28 | * <div modernizr='webgl'>
|
|
28 | 33 | * myShader = baseMaterialShader().modify(() => {
|
29 | 34 | * getWorldInputs((inputs) => {
|
30 | 35 | * // 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); |
32 | 37 | * return inputs;
|
33 | 38 | * });
|
34 | 39 | * });
|
|
49 | 54 | * @function combineColors
|
50 | 55 | * @experimental
|
51 | 56 | * @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). |
63 | 58 | *
|
64 | 59 | * This hook is available in:
|
65 | 60 | * - {@link p5.baseMaterialShader}
|
66 | 61 | * - {@link p5.baseNormalShader}
|
67 | 62 | * - {@link p5.baseColorShader}
|
68 | 63 | * - {@link p5.baseStrokeShader}
|
69 | 64 | *
|
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} |
72 | 70 | *
|
73 | 71 | * @example
|
74 | 72 | * <div modernizr='webgl'>
|
|
113 | 111 | * @function getPointSize
|
114 | 112 | * @experimental
|
115 | 113 | * @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). |
118 | 115 | *
|
119 | 116 | * 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} |
121 | 121 | *
|
122 | 122 | * @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} |
124 | 127 | *
|
125 | 128 | * @example
|
126 | 129 | * <div modernizr='webgl'>
|
127 | 130 | * <code>
|
128 | 131 | * let myShader;
|
129 | 132 | * function setup() {
|
130 | 133 | * createCanvas(200, 200, WEBGL);
|
131 |
| - * myShader = pointShader().modify(() => { |
| 134 | + * myShader = baseMaterialShader().modify(() => { |
132 | 135 | * 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)); |
135 | 138 | * });
|
136 | 139 | * });
|
137 | 140 | * }
|
138 | 141 | * function draw() {
|
139 | 142 | * background(255);
|
140 | 143 | * shader(myShader);
|
141 |
| - * strokeWeight(10); |
| 144 | + * strokeWeight(20); |
| 145 | + * stroke('blue'); |
142 | 146 | * point(0, 0);
|
143 | 147 | * }
|
144 | 148 | * </code>
|
|
0 commit comments