|
7 | 7 | import { parse } from 'acorn'; |
8 | 8 | import { ancestor } from 'acorn-walk'; |
9 | 9 | import escodegen from 'escodegen'; |
| 10 | +import noiseGLSL from './shaders/functions/noiseGLSL.glsl'; |
10 | 11 |
|
11 | 12 | function shadergenerator(p5, fn) { |
12 | 13 |
|
@@ -1578,6 +1579,7 @@ function shadergenerator(p5, fn) { |
1578 | 1579 | ], |
1579 | 1580 | 'sqrt': { args: ['genType'], returnType: 'genType', isp5Function: true}, |
1580 | 1581 | 'step': { args: ['genType', 'genType'], returnType: 'genType', isp5Function: false}, |
| 1582 | + 'noise': { args: ['vec2'], returnType: 'float', isp5Function: false }, |
1581 | 1583 | 'trunc': { args: ['genType'], returnType: 'genType', isp5Function: false}, |
1582 | 1584 |
|
1583 | 1585 | ////////// Vector ////////// |
@@ -1629,10 +1631,19 @@ function shadergenerator(p5, fn) { |
1629 | 1631 | return originalLerp.apply(this, args); // Fallback to normal p5.js lerp |
1630 | 1632 | } |
1631 | 1633 | }; |
| 1634 | + const originalNoise = fn.noise; |
| 1635 | + fn.noise = function (...args) { |
| 1636 | + if (!GLOBAL_SHADER?.isGenerating) { |
| 1637 | + return originalNoise.apply(this, args); // fallback to regular p5.js noise |
| 1638 | + } |
| 1639 | + |
| 1640 | + GLOBAL_SHADER.output.vertexDeclarations.add(noiseGLSL); |
| 1641 | + GLOBAL_SHADER.output.fragmentDeclarations.add(noiseGLSL); |
| 1642 | + return fnNodeConstructor('noise', args, { args: ['vec2'], returnType: 'float' }); |
| 1643 | + }; |
1632 | 1644 | } |
1633 | 1645 |
|
1634 | 1646 |
|
1635 | | - |
1636 | 1647 | export default shadergenerator; |
1637 | 1648 |
|
1638 | 1649 | if (typeof p5 !== 'undefined') { |
|
0 commit comments