Skip to content

Commit 8e199d8

Browse files
committed
docs: move p5.strands JSDoc to end of shaderGenerator.js and remove separate file
1 parent a3aeaa2 commit 8e199d8

File tree

2 files changed

+156
-152
lines changed

2 files changed

+156
-152
lines changed

src/webgl/ShaderGenerator.js

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,3 +1638,159 @@ export default shadergenerator;
16381638
if (typeof p5 !== 'undefined') {
16391639
p5.registerAddon(shadergenerator)
16401640
}
1641+
1642+
1643+
1644+
/* ------------------------------------------------------------- */
1645+
/**
1646+
* @typedef {Object} Vertex
1647+
* @property {{x: number, y: number, z: number}} position - The position of the vertex in world space.
1648+
* @property {{x: number, y: number, z: number}} normal - The normal vector at the vertex in world space.
1649+
* @property {{x: number, y: number}} texCoord - The texture coordinates (x, y) for the vertex.
1650+
* @property {{r: number, g: number, b: number, a: number}} color - The color at the vertex.
1651+
*/
1652+
1653+
/**
1654+
* @function getWorldInputs
1655+
* @experimental
1656+
* @description
1657+
* 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.
1658+
*
1659+
* This hook is available in:
1660+
* - {@link p5.baseMaterialShader}
1661+
* - {@link p5.baseNormalShader}
1662+
* - {@link p5.baseColorShader}
1663+
* - {@link p5.baseStrokeShader}
1664+
*
1665+
* @param {function(Vertex): Vertex} callback
1666+
* A callback function which receives and returns a Vertex struct.
1667+
*
1668+
* @see {@link p5.baseMaterialShader}
1669+
* @see {@link p5.Shader#modify}
1670+
*
1671+
* @example
1672+
* <div modernizr='webgl'>
1673+
* <code>
1674+
* let myShader;
1675+
* function setup() {
1676+
* createCanvas(200, 200, WEBGL);
1677+
* myShader = baseMaterialShader().modify(() => {
1678+
* getWorldInputs(inputs => {
1679+
* // Move the vertex up and down in a wave
1680+
* inputs.position.y += 20 * sin(
1681+
* millis() * 0.001 + inputs.position.x * 0.05
1682+
* );
1683+
* return inputs;
1684+
* });
1685+
* });
1686+
* }
1687+
* function draw() {
1688+
* background(255);
1689+
* shader(myShader);
1690+
* lights();
1691+
* noStroke();
1692+
* fill('red');
1693+
* sphere(50);
1694+
* }
1695+
* </code>
1696+
* </div>
1697+
*/
1698+
1699+
/**
1700+
* @function combineColors
1701+
* @experimental
1702+
* @description
1703+
* 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).
1704+
*
1705+
* This hook is available in:
1706+
* - {@link p5.baseMaterialShader}
1707+
* - {@link p5.baseNormalShader}
1708+
* - {@link p5.baseColorShader}
1709+
* - {@link p5.baseStrokeShader}
1710+
*
1711+
* @param {function(ColorComponents): { color: {r: number, g: number, b: number}, opacity: number }} callback
1712+
* A callback function which receives a ColorComponents struct and returns the final color and opacity.
1713+
*
1714+
* @see {@link p5.baseMaterialShader}
1715+
* @see {@link p5.Shader#modify}
1716+
*
1717+
* @example
1718+
* <div modernizr='webgl'>
1719+
* <code>
1720+
* let myShader;
1721+
* function setup() {
1722+
* createCanvas(200, 200, WEBGL);
1723+
* myShader = baseMaterialShader().modify(() => {
1724+
* combineColors(components => {
1725+
* // Custom color combination: add a red tint
1726+
* let color = {
1727+
* r: components.baseColor.r * components.diffuse.r +
1728+
* components.ambientColor.r * components.ambient.r +
1729+
* components.specularColor.r * components.specular.r +
1730+
* components.emissive.r + 0.2,
1731+
* g: components.baseColor.g * components.diffuse.g +
1732+
* components.ambientColor.g * components.ambient.g +
1733+
* components.specularColor.g * components.specular.g +
1734+
* components.emissive.g,
1735+
* b: components.baseColor.b * components.diffuse.b +
1736+
* components.ambientColor.b * components.ambient.b +
1737+
* components.specularColor.b * components.specular.b +
1738+
* components.emissive.b
1739+
* };
1740+
* return { color, opacity: components.opacity };
1741+
* });
1742+
* });
1743+
* }
1744+
* function draw() {
1745+
* background(255);
1746+
* shader(myShader);
1747+
* lights();
1748+
* noStroke();
1749+
* fill('red');
1750+
* sphere(50);
1751+
* }
1752+
* </code>
1753+
* </div>
1754+
*/
1755+
1756+
/**
1757+
* @function getPointSize
1758+
* @experimental
1759+
* @description
1760+
* 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).
1761+
*
1762+
* This hook is available in:
1763+
* - {@link p5.baseMaterialShader}
1764+
* - {@link p5.baseNormalShader}
1765+
* - {@link p5.baseColorShader}
1766+
* - {@link p5.baseStrokeShader}
1767+
*
1768+
* @param {function(size: number): number} callback
1769+
* A callback function which receives and returns the point size.
1770+
*
1771+
* @see {@link p5.baseMaterialShader}
1772+
* @see {@link p5.Shader#modify}
1773+
*
1774+
* @example
1775+
* <div modernizr='webgl'>
1776+
* <code>
1777+
* let myShader;
1778+
* function setup() {
1779+
* createCanvas(200, 200, WEBGL);
1780+
* myShader = baseMaterialShader().modify(() => {
1781+
* getPointSize(size => {
1782+
* // Make points pulse in size over time
1783+
* return size * (1.0 + 0.5 * sin(millis() * 0.002));
1784+
* });
1785+
* });
1786+
* }
1787+
* function draw() {
1788+
* background(255);
1789+
* shader(myShader);
1790+
* strokeWeight(20);
1791+
* stroke('blue');
1792+
* point(0, 0);
1793+
* }
1794+
* </code>
1795+
* </div>
1796+
*/

src/webgl/p5.strands.js

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)