-
Notifications
You must be signed in to change notification settings - Fork 272
Add p5.strands translations for shader examples and rename original GLSL examples #1238
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ksen0
merged 4 commits into
processing:2.0
from
MissTipo:shader-translation-glsl-to-p5-strands-2.0
Mar 20, 2026
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
da3c890
feat(examples): add p5.strands translations for shader examples
MissTipo 83e9ec2
refactor(examples): update p5.strands shaders to flat hook API and di…
MissTipo 2e31ee3
docs(examples): feature p5.strands translations and add 2026 attribut…
MissTipo 4b98cd5
Merge branch '2.0' into shader-translation-glsl-to-p5-strands-2.0
ksen0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
39 changes: 39 additions & 0 deletions
39
src/content/examples/en/11_3D/07_Filter_Shader_p5strands/code.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,39 @@ | ||
| let video; | ||
| let displaceColors; | ||
|
|
||
| function setup() { | ||
| createCanvas(700, 400, WEBGL); | ||
| video = createVideo( | ||
| 'https://upload.wikimedia.org/wikipedia/commons/d/d2/DiagonalCrosswalkYongeDundas.webm' | ||
| ); | ||
| video.volume(0); | ||
| video.hide(); | ||
| video.loop(); | ||
| displaceColors = buildFilterShader(displaceColorsCallback); | ||
| describe( | ||
| 'A video of a city crosswalk, with colors getting more offset the further from the center they are' | ||
| ); | ||
| } | ||
|
|
||
| function displaceColorsCallback() { | ||
| function zoom(coord, amount) { | ||
| return (coord - 0.5) / amount + 0.5; | ||
| } | ||
| filterColor.begin(); | ||
| const uv = filterColor.texCoord; | ||
| const r = getTexture(filterColor.canvasContent, uv).r; | ||
| const g = getTexture(filterColor.canvasContent, zoom(uv, 1.05)).g; | ||
| const b = getTexture(filterColor.canvasContent, zoom(uv, 1.1)).b; | ||
| const a = getTexture(filterColor.canvasContent, uv).a; | ||
| filterColor.set([r, g, b, a]); | ||
| filterColor.end(); | ||
| } | ||
|
|
||
| function draw() { | ||
| background(255); | ||
| push(); | ||
| imageMode(CENTER); | ||
| image(video, 0, 0, width, height, 0, 0, video.width, video.height, COVER); | ||
| pop(); | ||
| filter(displaceColors); | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/content/examples/en/11_3D/07_Filter_Shader_p5strands/description.mdx
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,29 @@ | ||
| --- | ||
| featuredImage: "../../../images/featured/11_3D-04_Filter_Shader-thumbnail.png" | ||
| featuredImageAlt: A screenshot of a video of a city crosswalk, with offset colors. | ||
| title: Filter Shader (p5.strands) | ||
| oneLineDescription: Manipulate imagery with a shader, written in p5.strands. | ||
|
|
||
| remix: | ||
| - description: Created by | ||
| attribution: | ||
| - name: Dave Pagurek | ||
| URL: https://www.davepagurek.com/ | ||
| code: | ||
| - label: 2023 code | ||
| URL: https://github.com/processing/p5.js-example/tree/main/examples/11_3D/04_Filter_Shader | ||
|
|
||
| - description: Remixed by | ||
| attribution: | ||
| - name: Dorine Tipo | ||
| URL: https://dorinetipo.vercel.app/ | ||
| code: | ||
| - label: 2026 p5.strands translation | ||
| URL: https://github.com/processing/p5.js-website/tree/main/src/content/examples/en/11_3D/07_Filter_Shader_p5strands | ||
|
|
||
| - collectivelyAttributedSince: 2024 | ||
| --- | ||
|
|
||
| This is a p5.strands version of the Filter Shader example. Filter shaders apply | ||
| an effect to anything that is on the canvas. In this example, the effect is applied to | ||
| a video. |
39 changes: 39 additions & 0 deletions
39
src/content/examples/en/11_3D/08_Adjusting_Positions_With_A_Shader_p5strands/code.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,39 @@ | ||
| let wiggleShader; | ||
| let ribbon; | ||
|
|
||
| function setup() { | ||
| createCanvas(700, 400, WEBGL); | ||
| wiggleShader = buildColorShader(wiggleCallback); | ||
|
|
||
| let startColor = color('#F55'); | ||
| let endColor = color('#55F'); | ||
| ribbon = buildGeometry(() => { | ||
| noStroke(); | ||
| beginShape(QUAD_STRIP); | ||
| let numPoints = 50; | ||
| for (let currentPoint = 0; currentPoint < numPoints; currentPoint++) { | ||
| let x = map(currentPoint, 0, numPoints - 1, -width / 3, width / 3); | ||
| let y = map(currentPoint, 0, numPoints - 1, -height / 3, height / 3); | ||
| fill(lerpColor(startColor, endColor, currentPoint / (numPoints - 1))); | ||
| for (let z of [-50, 50]) { | ||
| vertex(x, y, z); | ||
| } | ||
| } | ||
| endShape(); | ||
| }); | ||
| describe('A red-to-blue ribbon that waves over time'); | ||
| } | ||
|
|
||
| function wiggleCallback() { | ||
| objectInputs.begin(); | ||
| objectInputs.position.y += 20 * sin(millis() * 0.01 + objectInputs.position.y * 0.1); | ||
| objectInputs.end(); | ||
| } | ||
|
|
||
| function draw() { | ||
| background(255); | ||
| noStroke(); | ||
| rotateX(PI * 0.1); | ||
| shader(wiggleShader); | ||
| model(ribbon); | ||
| } |
29 changes: 29 additions & 0 deletions
29
...xamples/en/11_3D/08_Adjusting_Positions_With_A_Shader_p5strands/description.mdx
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,29 @@ | ||
| --- | ||
| featuredImage: "../../../images/featured/11_3D-05_Adjusting_Positions_With_A_Shader-thumbnail.png" | ||
| featuredImageAlt: A red-to-blue waving ribbon on a white background. | ||
| title: Adjusting Positions with a Shader (p5.strands) | ||
| oneLineDescription: Use a shader to adjust shape vertices, written in p5.strands. | ||
|
|
||
| remix: | ||
| - description: Created by | ||
| attribution: | ||
| - name: Dave Pagurek | ||
| URL: https://www.davepagurek.com/ | ||
| code: | ||
| - label: 2023 code | ||
| URL: https://github.com/processing/p5.js-example/tree/main/examples/11_3D/05_Adjusting_Positions_With_A_Shader | ||
|
|
||
| - description: Remixed by | ||
| attribution: | ||
| - name: Dorine Tipo | ||
| URL: https://dorinetipo.vercel.app/ | ||
| code: | ||
| - label: 2026 p5.strands translation | ||
| URL: https://github.com/processing/p5.js-website/tree/main/src/content/examples/en/11_3D/08_Adjusting_Positions_With_A_Shader_p5strands | ||
|
|
||
| - collectivelyAttributedSince: 2024 | ||
| --- | ||
|
|
||
| This is a p5.strands version of the Adjusting Positions with a Shader example. | ||
| Shaders can adjust the positions of the vertices of shapes. | ||
| This lets you distort and animate 3D models. | ||
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
63 changes: 63 additions & 0 deletions
63
...content/examples/en/12_Advanced_Canvas_Rendering/03_Shader_As_A_Texture_p5strands/code.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,63 @@ | ||
| let theShader; | ||
|
|
||
| function setup() { | ||
| createCanvas(710, 400, WEBGL); | ||
| noStroke(); | ||
| angleMode(DEGREES); | ||
| theShader = buildMaterialShader(shaderAsTextureCallback); | ||
| describe('Sphere broken up into a square grid with a gradient in each grid.'); | ||
| } | ||
|
|
||
| function shaderAsTextureCallback() { | ||
| let position = sharedVec3(); | ||
|
|
||
| function rotate2D(st, angle) { | ||
| const c = cos(angle); | ||
| const s = sin(angle); | ||
| const x = st.x - 0.5; | ||
| const y = st.y - 0.5; | ||
| return [c * x - s * y + 0.5, s * x + c * y + 0.5]; | ||
| } | ||
|
|
||
| function tile(st, zoom) { | ||
| return fract(st * zoom); | ||
| } | ||
|
|
||
| function concentricCircles(st, radius, res, scale) { | ||
| return floor(distance(st, radius) * res) / scale; | ||
| } | ||
|
|
||
| cameraInputs.begin(); | ||
| position = cameraInputs.position; | ||
| cameraInputs.end(); | ||
|
|
||
| pixelInputs.begin(); | ||
| const fragCoord = position.xy + [width, height] * 0.5; | ||
| const safeMouse = [max(mouseX, 1), max(height - mouseY, 1)]; | ||
| const mst = fragCoord / safeMouse; | ||
| const mdist = distance([1, 1], mst); | ||
|
|
||
| const st = pixelInputs.texCoord; | ||
| const distToCenter = distance(st, [sin(millis() / 10000), cos(millis() / 10000)]); | ||
| let tiled = tile(st, 10); | ||
| tiled = rotate2D(tiled, distToCenter / (mdist / 5) * PI * 2); | ||
|
|
||
| const r = concentricCircles(tiled, [0, 0], 5, 5); | ||
| const g = concentricCircles(tiled, [0, 0], 10, 10); | ||
| const b = concentricCircles(tiled, [0, 0], 20, 10); | ||
|
|
||
| pixelInputs.color = [r, g, b, 1]; | ||
| pixelInputs.end(); | ||
| } | ||
|
|
||
| function draw() { | ||
| background(255); | ||
| shader(theShader); | ||
| translate(-150, 0, 0); | ||
| push(); | ||
| rotateX(-mouseY); | ||
| rotateY(-mouseX); | ||
| sphere(125); | ||
| pop(); | ||
| ellipse(260, 0, 200, 200, 100); | ||
| } |
39 changes: 39 additions & 0 deletions
39
...n/12_Advanced_Canvas_Rendering/03_Shader_As_A_Texture_p5strands/description.mdx
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,39 @@ | ||
| --- | ||
| featuredImage: "../../../images/featured/12_Advanced_Canvas_Rendering-02_Shader_As_A_Texture-thumbnail.png" | ||
| featuredImageAlt: Two spheres broken up into a square grid with a gradient in each grid. | ||
| title: Shader as a Texture (p5.strands) | ||
| oneLineDescription: Generate a texture for a 3D shape using a shader, written in p5.strands. | ||
|
|
||
| remix: | ||
| - description: Based on | ||
| attribution: | ||
| - name: p5.js Contributors | ||
| URL: https://github.com/processing/p5.js-website-legacy/blob/main/src/data/examples/en/20_3D/09_shader_as_a_texture.js | ||
| code: | ||
| - label: pre-2023 code | ||
| URL: https://github.com/processing/p5.js-website-legacy/blob/main/src/data/examples/en/20_3D/09_shader_as_a_texture.js | ||
|
|
||
| - description: Revised by | ||
| attribution: | ||
| - name: Caleb Foss | ||
| URL: https://github.com/calebfoss | ||
| code: | ||
| - label: 2023 code | ||
| URL: https://github.com/processing/p5.js-example/tree/main/examples/12_Advanced_Canvas_Rendering/02_Shader_As_A_Texture | ||
|
|
||
| - description: Remixed by | ||
| attribution: | ||
| - name: Dorine Tipo | ||
| URL: https://dorinetipo.vercel.app/ | ||
| code: | ||
| - label: 2026 p5.strands translation | ||
| URL: https://github.com/processing/p5.js-website/tree/main/src/content/examples/en/12_Advanced_Canvas_Rendering/03_Shader_As_A_Texture_p5strands | ||
|
|
||
| - collectivelyAttributedSince: 2024 | ||
| --- | ||
|
|
||
| This is a p5.strands version of the Shader as a Texture example. | ||
| Shaders can be applied to 2D/3D shapes as textures. | ||
|
|
||
| To learn more about using shaders in p5.js: | ||
| <a href="https://itp-xstory.github.io/p5js-shaders/">p5.js Shaders</a> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.