Skip to content

Commit 4cbf98f

Browse files
Add custom fn.noise() in p5.strands with conditional GLSL injection
1 parent 9cf4424 commit 4cbf98f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/webgl/ShaderGenerator.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,11 +1631,19 @@ function shadergenerator(p5, fn) {
16311631
return originalLerp.apply(this, args); // Fallback to normal p5.js lerp
16321632
}
16331633
};
1634+
fn.noise = function (...args) {
1635+
if (GLOBAL_SHADER?.isGenerating) {
1636+
GLOBAL_SHADER.output.fragmentDeclarations.add(noiseGLSL);
1637+
return fnNodeConstructor('noise', args, { args: ['vec2'], returnType: 'float' });
1638+
} else {
1639+
p5._friendlyError(
1640+
`It looks like you've called noise() outside of a shader's modify() function.`
1641+
);
1642+
}
1643+
};
16341644
}
16351645

16361646

1637-
GLOBAL_SHADER.output.fragmentDeclarations.add(noiseGLSL);
1638-
16391647
export default shadergenerator;
16401648

16411649
if (typeof p5 !== 'undefined') {

0 commit comments

Comments
 (0)