@@ -116,28 +116,28 @@ export function initGlobalStrandsAPI(p5, fn, strandsContext) {
116116
117117 // Add GLSL noise. TODO: Replace this with a backend-agnostic implementation
118118 const originalNoise = fn . noise ;
119- fn . noise = function ( ...args ) {
119+ const originalNoiseDetail = fn . noiseDetail ;
120+
121+ strandsContext . _noiseOctaves = null ;
122+ strandsContext . _noiseAmpFalloff = null ;
123+
124+ fn . noiseDetail = function ( lod , falloff ) {
120125 if ( ! strandsContext . active ) {
121- return originalNoise . apply ( this , args ) ; // fallback to regular p5.js noise
126+ return originalNoiseDetail . apply ( this , arguments ) ;
122127 }
123128
124- const hasNoiseUniforms = strandsContext . uniforms . some ( u => u . name === 'uNoiseOctaves' ) ;
125- if ( ! hasNoiseUniforms ) {
126- strandsContext . uniforms . push ( {
127- name : 'uNoiseOctaves' ,
128- typeInfo : DataType . int1 ,
129- defaultValue : ( ) => p5 . _getNoiseOctaves ( )
130- } ) ;
131- strandsContext . uniforms . push ( {
132- name : 'uNoiseAmpFalloff' ,
133- typeInfo : DataType . float1 ,
134- defaultValue : ( ) => p5 . _getNoiseAmpFalloff ( )
135- } ) ;
129+ strandsContext . _noiseOctaves = lod ;
130+ strandsContext . _noiseAmpFalloff = falloff ;
131+ } ;
132+
133+ fn . noise = function ( ...args ) {
134+ if ( ! strandsContext . active ) {
135+ return originalNoise . apply ( this , args ) ;
136136 }
137137
138138 strandsContext . vertexDeclarations . add ( noiseGLSL ) ;
139139 strandsContext . fragmentDeclarations . add ( noiseGLSL ) ;
140- // Handle noise(x, y) as noise(vec2)
140+
141141 let nodeArgs ;
142142 if ( args . length === 3 ) {
143143 nodeArgs = [ fn . vec3 ( args [ 0 ] , args [ 1 ] , args [ 2 ] ) ] ;
@@ -147,10 +147,20 @@ export function initGlobalStrandsAPI(p5, fn, strandsContext) {
147147 nodeArgs = args ;
148148 }
149149
150+ const octaves = strandsContext . _noiseOctaves !== null
151+ ? strandsContext . _noiseOctaves
152+ : p5 . _getNoiseOctaves ( ) ;
153+ const falloff = strandsContext . _noiseAmpFalloff !== null
154+ ? strandsContext . _noiseAmpFalloff
155+ : p5 . _getNoiseAmpFalloff ( ) ;
156+
157+ nodeArgs . push ( octaves ) ;
158+ nodeArgs . push ( falloff ) ;
159+
150160 const { id, dimension } = build . functionCallNode ( strandsContext , 'noise' , nodeArgs , {
151161 overloads : [ {
152- params : [ DataType . float3 ] ,
153- returnType : DataType . float1 ,
162+ params : [ DataType . float3 , DataType . int1 , DataType . float1 ] ,
163+ returnType : DataType . float1
154164 } ]
155165 } ) ;
156166 return createStrandsNode ( id , dimension , strandsContext ) ;
0 commit comments