Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.7k
[WIP] Docs: Add initial draft of Strands documentation (feedback wanted)#7940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
16 commits Select commitHold shift + click to select a range
a3aeaa2 docs: Add initial draft of Strands documentation
Abhayaj2478e199d8 docs: move p5.strands JSDoc to end of shaderGenerator.js and remove s…
Abhayaj247c9d07c1 docs: fix JSDoc syntax for p5.js compatibility
Abhayaj24706cf619 docs: clarify combineColors and getPointSize documentation per mainta…
Abhayaj2471d01ca8 docs: remove getPointSize documentation as it is not present in publi…
Abhayaj247e73b524 Add documentation for remaining public shader hooks in ShaderGenerato…
Abhayaj2476b54ecd Address maintainer feedback: update shader hook docs and examples for…
Abhayaj2471146190 Update ShaderGenerator docs and examples
Abhayaj24736c4c2d Address maintainer feedback: Update ShaderGenerator docs and examples
Abhayaj2476e1311d Fix shouldDiscard example
Abhayaj24758d8e5d Fix getPixelInputs description and getFinalColor example
Abhayaj247483edcb Fix getPixelInputs description and getColor description
Abhayaj24729fbe52 Address Maintainer feedbacks: Update ShaderGenerator docs and examples
Abhayaj247be56924 Address maintainer feedback by refining references, param annotations…
Abhayaj24717992d7 updated .modify() links
Abhayaj247ff81847 Address maintainer feedback by updating fill color, adjusting sphere …
Abhayaj247File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
docs: Add initial draft of Strands documentation
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commita3aeaa29a0662f85393ce350508523e9b72acad1
There are no files selected for viewing
152 changes: 152 additions & 0 deletionssrc/webgl/p5.strands.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| /** | ||
| * @typedef {Object} Vertex | ||
| * @property {{x: number, y: number, z: number}} position - The position of the vertex in world space. | ||
| * @property {{x: number, y: number, z: number}} normal - The normal vector at the vertex in world space. | ||
| * @property {{x: number, y: number}} texCoord - The texture coordinates (x, y) for the vertex. | ||
| * @property {{r: number, g: number, b: number, a: number}} color - The color at the vertex. | ||
| */ | ||
| /** | ||
| * @function getWorldInputs | ||
| * @experimental | ||
| * @description | ||
| * 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. | ||
| * | ||
| * This hook is available in: | ||
| * - {@link p5.baseMaterialShader} | ||
| * - {@link p5.baseNormalShader} | ||
| * - {@link p5.baseColorShader} | ||
| * - {@link p5.baseStrokeShader} | ||
| * | ||
| * @param {function(Vertex): Vertex} callback | ||
| * A callback function which receives and returns a Vertex struct. | ||
| * | ||
| * @see {@link p5.baseMaterialShader} | ||
| * @see {@link p5.Shader#modify} | ||
| * | ||
| * @example | ||
| * <div modernizr='webgl'> | ||
| * <code> | ||
| * let myShader; | ||
| * function setup() { | ||
| * createCanvas(200, 200, WEBGL); | ||
| * myShader = baseMaterialShader().modify(() => { | ||
| * getWorldInputs(inputs => { | ||
| * // Move the vertex up and down in a wave | ||
| * inputs.position.y += 20 * sin( | ||
| * millis() * 0.001 + inputs.position.x * 0.05 | ||
| * ); | ||
| * return inputs; | ||
| * }); | ||
| * }); | ||
| * } | ||
| * function draw() { | ||
| * background(255); | ||
| * shader(myShader); | ||
| * lights(); | ||
| * noStroke(); | ||
| * fill('red'); | ||
| * sphere(50); | ||
| * } | ||
| * </code> | ||
| * </div> | ||
| */ | ||
| /** | ||
| * @function combineColors | ||
| * @experimental | ||
| * @description | ||
| * 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). | ||
| * | ||
| * This hook is available in: | ||
| * - {@link p5.baseMaterialShader} | ||
| * - {@link p5.baseNormalShader} | ||
| * - {@link p5.baseColorShader} | ||
| * - {@link p5.baseStrokeShader} | ||
| * | ||
| * @param {function(ColorComponents): { color: {r: number, g: number, b: number}, opacity: number }} callback | ||
| * A callback function which receives a ColorComponents struct and returns the final color and opacity. | ||
| * | ||
| * @see {@link p5.baseMaterialShader} | ||
| * @see {@link p5.Shader#modify} | ||
| * | ||
| * @example | ||
| * <div modernizr='webgl'> | ||
| * <code> | ||
| * let myShader; | ||
| * function setup() { | ||
| * createCanvas(200, 200, WEBGL); | ||
| * myShader = baseMaterialShader().modify(() => { | ||
| * combineColors(components => { | ||
| * // Custom color combination: add a red tint | ||
| * let color = { | ||
| * r: components.baseColor.r * components.diffuse.r + | ||
| * components.ambientColor.r * components.ambient.r + | ||
| * components.specularColor.r * components.specular.r + | ||
| * components.emissive.r + 0.2, | ||
| * g: components.baseColor.g * components.diffuse.g + | ||
| * components.ambientColor.g * components.ambient.g + | ||
| * components.specularColor.g * components.specular.g + | ||
| * components.emissive.g, | ||
| * b: components.baseColor.b * components.diffuse.b + | ||
| * components.ambientColor.b * components.ambient.b + | ||
| * components.specularColor.b * components.specular.b + | ||
| * components.emissive.b | ||
| * }; | ||
| * return { color, opacity: components.opacity }; | ||
| * }); | ||
| * }); | ||
| * } | ||
| * function draw() { | ||
| * background(255); | ||
| * shader(myShader); | ||
| * lights(); | ||
| * noStroke(); | ||
| * fill('red'); | ||
| * sphere(50); | ||
| * } | ||
| * </code> | ||
| * </div> | ||
| */ | ||
| /** | ||
| * @function getPointSize | ||
| * @experimental | ||
| * @description | ||
| * 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). | ||
| * | ||
| * This hook is available in: | ||
| * - {@link p5.baseMaterialShader} | ||
| * - {@link p5.baseNormalShader} | ||
| * - {@link p5.baseColorShader} | ||
| * - {@link p5.baseStrokeShader} | ||
| * | ||
| * @param {function(size: number): number} callback | ||
| * A callback function which receives and returns the point size. | ||
| * | ||
| * @see {@link p5.baseMaterialShader} | ||
| * @see {@link p5.Shader#modify} | ||
| * | ||
| * @example | ||
| * <div modernizr='webgl'> | ||
| * <code> | ||
| * let myShader; | ||
| * function setup() { | ||
| * createCanvas(200, 200, WEBGL); | ||
| * myShader = baseMaterialShader().modify(() => { | ||
| * getPointSize(size => { | ||
| * // Make points pulse in size over time | ||
| * return size * (1.0 + 0.5 * sin(millis() * 0.002)); | ||
| * }); | ||
| * }); | ||
| * } | ||
| * function draw() { | ||
| * background(255); | ||
| * shader(myShader); | ||
| * strokeWeight(20); | ||
| * stroke('blue'); | ||
| * point(0, 0); | ||
| * } | ||
| * </code> | ||
| * </div> | ||
| */ |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.