Skip to content

Commit df4c546

Browse files
Refactor fn.noise() to use early return guard for cleaner structure
1 parent 09f307d commit df4c546

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/webgl/ShaderGenerator.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,15 +1632,16 @@ function shadergenerator(p5, fn) {
16321632
}
16331633
};
16341634
fn.noise = function (...args) {
1635-
if (GLOBAL_SHADER?.isGenerating) {
1636-
GLOBAL_SHADER.output.vertexDeclarations.add(noiseGLSL);
1637-
GLOBAL_SHADER.output.fragmentDeclarations.add(noiseGLSL);
1638-
return fnNodeConstructor('noise', args, { args: ['vec2'], returnType: 'float' });
1639-
} else {
1635+
if (!GLOBAL_SHADER?.isGenerating) {
16401636
p5._friendlyError(
1641-
`It looks like you've called noise() outside of a shader's modify() function.`
1642-
);
1643-
}
1637+
`It looks like you've called noise() outside of a shader's modify() function.`
1638+
);
1639+
return;
1640+
}
1641+
1642+
GLOBAL_SHADER.output.vertexDeclarations.add(noiseGLSL);
1643+
GLOBAL_SHADER.output.fragmentDeclarations.add(noiseGLSL);
1644+
return fnNodeConstructor('noise', args, { args: ['vec2'], returnType: 'float' });
16441645
};
16451646
}
16461647

0 commit comments

Comments
 (0)