@@ -426,6 +426,54 @@ suite('p5.Shader', function() {
426426 myp5 . plane ( myp5 . width , myp5 . height ) ;
427427 } ) . not . toThrowError ( ) ;
428428 } ) ;
429+
430+ test ( 'handle custom uniform names with automatic values' , ( ) => {
431+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
432+ const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
433+ // Variable name is 'brightness' but uniform name is 'customBrightness'
434+ const brightness = myp5 . uniformFloat ( 'customBrightness' , ( ) => 0.8 ) ;
435+ myp5 . getPixelInputs ( inputs => {
436+ inputs . color = [ brightness , brightness , brightness , 1.0 ] ;
437+ return inputs ;
438+ } ) ;
439+ } , { myp5 } ) ;
440+
441+ myp5 . noStroke ( ) ;
442+ myp5 . shader ( testShader ) ;
443+ myp5 . plane ( myp5 . width , myp5 . height ) ;
444+
445+ // Check that the shader uses the automatic value (0.8)
446+ const pixelColor = myp5 . get ( 25 , 25 ) ;
447+ assert . approximately ( pixelColor [ 0 ] , 204 , 5 ) ; // 0.8 * 255 = 204
448+ assert . approximately ( pixelColor [ 1 ] , 204 , 5 ) ;
449+ assert . approximately ( pixelColor [ 2 ] , 204 , 5 ) ;
450+ } ) ;
451+
452+ test ( 'handle custom uniform names with manual setUniform' , ( ) => {
453+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
454+ const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
455+ // Variable name is 'brightness' but uniform name is 'customBrightness'
456+ const brightness = myp5 . uniformFloat ( 'customBrightness' ) ;
457+ myp5 . getPixelInputs ( inputs => {
458+ inputs . color = [ brightness , brightness , brightness , 1.0 ] ;
459+ return inputs ;
460+ } ) ;
461+ } , { myp5 } ) ;
462+
463+ // Set the uniform using the custom name
464+ testShader . setUniform ( 'customBrightness' , 0.6 ) ;
465+
466+ myp5 . noStroke ( ) ;
467+ myp5 . shader ( testShader ) ;
468+ myp5 . plane ( myp5 . width , myp5 . height ) ;
469+
470+ // Check that the shader uses the manual value (0.6)
471+ const pixelColor = myp5 . get ( 25 , 25 ) ;
472+ assert . approximately ( pixelColor [ 0 ] , 153 , 5 ) ; // 0.6 * 255 = 153
473+ assert . approximately ( pixelColor [ 1 ] , 153 , 5 ) ;
474+ assert . approximately ( pixelColor [ 2 ] , 153 , 5 ) ;
475+ } ) ;
476+
429477 suite ( 'if statement conditionals' , ( ) => {
430478 test ( 'handle simple if statement with true condition' , ( ) => {
431479 myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
0 commit comments