2.3.1 Hex codes in shaders and continued p5.strands development; tint() and other fixes; HDR renamed to P3
This patch introduces new p5.strands features, improvements to shapes & SVG handling, and bugfixes across WebGL and WebGPU. It also renames the color space previously called HDR to P3 for accuracy.
- Fixes for loading SVG files and bad URLs with
loadImage(), applyingtint()to images in 2D mode, framebuffers with custom pixel densities,orbitControl()after swiping outside the canvas,mouseIsPressedbehavior after clicking DOM elements, andline(),point(),triangle(),quad(),rect()(including with rounded corners, like in the example below) - In shaders and p5.strands code, this patch adds
randomGaussian()andcolor()support inside p5.strands shader code,instanceIndexfor instanced rendering,TRIANGLE_FANdrawing in both WebGL and WebGPU, custom shaders that setuSamplerviasetUniform(), hooks that return objects should work, custom shaders should be able to use version directives, andmouseXandwidthin instance mode with p5.strands shaders
Warning
This release renames the color space previously called HDR to P3 for accuracy. If you use HDR color space constants in your code, please update them to P3. The maintainers felt this correction was important to make now. If you have concerns about backward compatibility, you can share them on the linked pull request discussion.
You can start using this updated version in this starter sketch! Or load both p5.js and WebGPU mode by adding these two script tags to your sketch:
<script src="https://cdn.jsdelivr.net/npm/p5@2.3.1/lib/p5.js"></script>
<script src="https://cdn.jsdelivr.net/npm/p5@2.3.1/lib/p5.webgpu.js"></script>To use WebGPU mode in createCanvas note the async/await, which is needed for WebGPU but not WebGL:
async function setup() {
await createCanvas(400, 400, WEBGPU);
}What's new in p5.strands
randomGaussian() is available in p5.strands code - see the static example in the starter sketch or below, which also shows more p5.js-style, beginner-friendly colors.
- Add p5.strands support for randomGaussian() by @harshiltewari2004 in #8800
- Replace randomness-related noise usage in strands example by @VikasKSingh05 in #8824
- feat(strands): add color() support for beginner-friendly color inputs by @LalitNarayanYadav in #8822
- Add instanceIndex alias for instanceID by @aashu2006 in #8912
- fix builtin global accessors for instance mode in strands shaders by @aashu2006 in #8878
- Add p5.strands documentation and examples for color functions by @Yashisinghal285 in #8965
async function setup() {
//for normal 2D or WEBGL stuff
createCanvas(400, 400, WEBGL);
//for WEBGPU stuff
// await createCanvas(400, 400, WEBGPU);
myShader = buildMaterialShader(myShaderBuilder);
}
function myShaderBuilder(){
finalColor.begin();
let coord = finalColor.texCoord;
// color() and randomGaussian() available in p5.strands
let c = color('#eeff22');
finalColor.set([c.r, c.g, c.b, randomGaussian()*0.1 + 0.3]);
finalColor.end();
}
function draw() {
stroke(255);
background("#f1678e");
shader(myShader);
orbitControl();
// rect with rounded corners
rect(-50, -50, 100, 100, 50, 10);
translate(0,0,50);
rect(-50, -50, 100, 100, 3);
translate(0,0,50);
rect(-50, -50, 100, 100, 0, 20, 30, 20);
translate(0,0,50);
rect(-50, -50, 100, 100);
}Custom shader bugfixes
- Fix WebGL shader version regex by @eupthere in #8857
- fix: preserve user-set uSampler uniform for custom shaders by @BHARATH0153 in #8869
Ongoing work on shapes & SVG
- fix : other shape use the shape class also add new roundrect Primitive by @VANSH3104 in #8899
- Fix
loadImageSVG file loading regression by @gfrancine in #8937
Other bugfixes
- Fix memory leak on loadImage failure by @gfrancine in #8958
- Fix framebuffer texture size clamping using wrong pixel density by @NalinDalal in #8964
- Fix TRIANGLE_FAN immediate mode support by @davepagurek in #8974
- fix: convert tint to RGBA array in _getTintedImageCanvas by @SarthakRawat-1 in #8934
- Fix orbitControl() breaking after touch swipe outside canvas. by @perminder-17 in #8863
- Fix object returns in p5.strands hooks by @davepagurek in #8950
- fixing-mouseClick by @perminder-17 in #8917
- Add mat2 uniform support to WebGL setUniform, fixing silent no-op (#8… by @harshiltewari2004 in #8978
Other documentation & error messages updates
- Rename HDR to P3 by @limzykenneth in #8975
- Add friendly FES error for dimension mismatch on shared variable assi… by @harshiltewari2004 in #8823
- Add shader examples to trigonometric functions by @SOUMITRO-SAHA in #8801
- Mark private methods as private by @ksen0 in #8854
- note strokeweight isn't scaled in webgl/webgpu by @Nixxx19 in #8850
- feat: add friendly error for cross-hook property access (#8813) by @BHARATH0153 in #8862
- Expose dimensions property on Vector by @ksen0 in #8874
- fix: correct textToContours and textToModel reference documentation (#8623) by @gourijain029-del in #8626
- Update 2.x top level docs to match main by @ksen0 in #8892
- Stewards workflow in main by @ksen0 in #8906
- Add shader examples for math functions by @SOUMITRO-SAHA in #8802
- Update release workflow to check for prerelease by @ksen0 in #8956
- docs: add gfrancine as a contributor for code by @allcontributors[bot] in #8959
- docs: add slash-init as a contributor for bug by @allcontributors[bot] in #8967
- docs: add Theresa-Em as a contributor for translation by @allcontributors[bot] in #8989
- docs: add SihongShen as a contributor for translation by @allcontributors[bot] in #8988
- docs: add zmuen as a contributor for translation by @allcontributors[bot] in #8986
- Fixed missing images in unit_testing.md by @MarsGray in #8995
- docs: add Nwakaego-Ego as a contributor for bug, code, and 2 more by @allcontributors[bot] in #8977
- docs: add Chiuye as a contributor for translation by @allcontributors[bot] in #8987
- docs: add XiaoPingArchive as a contributor for translation by @allcontributors[bot] in #8982
- fix: replace beta.p5js.org links with p5js.org in contributor docs by @Nwakaego-Ego in #8966
New Contributors
Welcome to the community! 🎉
- @VikasKSingh05 made their first contribution in #8824
- @BHARATH0153 made their first contribution in #8862
- @gourijain029-del made their first contribution in #8626
- @SarthakRawat-1 made their first contribution in #8934
- @gfrancine made their first contribution in #8937
- @MarsGray made their first contribution in #8995
- @Yashisinghal285 made their first contribution in #8965
- @Nwakaego-Ego made their first contribution in #8966
Stewards
Stewards who reviewed and commented on PRs in this release - thank you for your effort!