From 604e10ca64db71803b53dc0f44b11667f71f3589 Mon Sep 17 00:00:00 2001 From: Lalit Narayan Yadav <162928571+LalitNarayanYadav@users.noreply.github.com> Date: Mon, 28 Jul 2025 16:07:05 +0530 Subject: [PATCH 1/2] Add mouse, resolution, and time-based uniforms to bloomShaderCallback --- preview/global/sketch.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/preview/global/sketch.js b/preview/global/sketch.js index b0cd6c8045..d3c0d6e0c6 100644 --- a/preview/global/sketch.js +++ b/preview/global/sketch.js @@ -71,15 +71,27 @@ function pixellizeShaderCallback() { function bloomShaderCallback() { const preBlur = uniformTexture(() => originalFrameBuffer); + const mouse = uniformVec2(() => [mouseX, mouseY]); + const resolution = uniformVec2(() => [width, height]); + const millisUniform = uniformFloat(() => millis()); + const frameCountUniform = uniformFloat(() => frameCount); + const deltaTimeUniform = uniformFloat(() => deltaTime); + getColor((input, canvasContent) => { - const blurredCol = texture(canvasContent, input.texCoord); - const originalCol = texture(preBlur, input.texCoord); - const brightPass = max(originalCol, 0.3) * 1.5; - const bloom = originalCol + blurredCol * brightPass; - return bloom; + const uv = input.texCoord; + const blurredCol = texture(canvasContent, uv); + const originalCol = texture(preBlur, uv); + + // Simple animated bloom effect + const brightness = dot(originalCol.rgb, vec3(0.2126, 0.7152, 0.0722)); + const pulse = sin(millisUniform * 0.001 + uv.x * 10.0); + const bloomGlow = originalCol.rgb * smoothstep(0.8, 1.0, brightness * pulse); + + return vec4(originalCol.rgb + bloomGlow, originalCol.a); }); } + async function setup(){ createCanvas(windowWidth, windowHeight, WEBGL); stars = buildGeometry(() => sphere(30, 4, 2)) From 5c65e285d9832e8e31169a44b97ecffe1f1a1e69 Mon Sep 17 00:00:00 2001 From: Lalit Narayan Yadav <162928571+LalitNarayanYadav@users.noreply.github.com> Date: Wed, 30 Jul 2025 20:03:43 +0530 Subject: [PATCH 2/2] Add JSDoc for built-in time and input uniforms for p5.strands shaders --- src/webgl/ShaderGenerator.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/webgl/ShaderGenerator.js b/src/webgl/ShaderGenerator.js index 58b3c7cc34..9f1fa5eb57 100644 --- a/src/webgl/ShaderGenerator.js +++ b/src/webgl/ShaderGenerator.js @@ -54,6 +54,23 @@ function shadergenerator(p5, fn) { } } + /** + * Built-in uniforms for p5.strands shaders: + * + * These uniforms are automatically available in shaders created + * using p5.strands (e.g., baseFilterShader().modify(...)): + * + * - `mouse`: A vec2 uniform containing the current mouse position (mouseX, mouseY) + * - `resolution`: A vec2 uniform of the current canvas size (width, height) + * - `millis`: A float uniform representing elapsed time in milliseconds + * - `frameCount`: A float uniform counting total frames rendered + * - `deltaTime`: A float uniform for time difference between frames + * + * These allow shader authors to access common time/input data + * without manually setting them via setUniform(). + */ + + // AST Transpiler Callbacks and helper functions function replaceBinaryOperator(codeSource) { switch (codeSource) {