@@ -616,11 +616,45 @@ suite('p5.Shader', function() {
616616 myp5 . noStroke ( ) ;
617617 myp5 . shader ( testShader ) ;
618618 myp5 . plane ( myp5 . width , myp5 . height ) ;
619- // Check that the center pixel is gray (medium condition was true)
619+ // Check that the center pixel is black (else condition was true)
620+ const pixelColor = myp5 . get ( 25 , 25 ) ;
621+ assert . approximately ( pixelColor [ 0 ] , 0 , 5 ) ;
622+ assert . approximately ( pixelColor [ 1 ] , 0 , 5 ) ;
623+ assert . approximately ( pixelColor [ 2 ] , 0 , 5 ) ;
624+ } ) ;
625+ test ( 'handle conditional assignment in if-else-if chains' , ( ) => {
626+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
627+ const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
628+ const val = myp5 . uniformFloat ( ( ) => Math . PI * 8 ) ;
629+ myp5 . getPixelInputs ( inputs => {
630+ let shininess = 0
631+ let color = 0
632+ if ( val > 5 ) {
633+ const elevation = myp5 . sin ( val )
634+ if ( elevation > 0.4 ) {
635+ shininess = 0 ;
636+ } else if ( elevation > 0.25 ) {
637+ shininess = 30 ;
638+ } else {
639+ color = 1 ;
640+ shininess = 100 ;
641+ }
642+ } else {
643+ shininess += 25 ;
644+ }
645+ inputs . shininess = shininess ;
646+ inputs . color = [ color , color , color , 1 ] ;
647+ return inputs ;
648+ } ) ;
649+ } , { myp5 } ) ;
650+ myp5 . noStroke ( ) ;
651+ myp5 . shader ( testShader ) ;
652+ myp5 . plane ( myp5 . width , myp5 . height ) ;
653+ // Check that the center pixel is 255 (hit nested else statement)
620654 const pixelColor = myp5 . get ( 25 , 25 ) ;
621- assert . approximately ( pixelColor [ 0 ] , 0 , 5 ) ; // Red channel should be ~127 (gray)
622- assert . approximately ( pixelColor [ 1 ] , 0 , 5 ) ; // Green channel should be ~127
623- assert . approximately ( pixelColor [ 2 ] , 0 , 5 ) ; // Blue channel should be ~127
655+ assert . approximately ( pixelColor [ 0 ] , 255 , 5 ) ;
656+ assert . approximately ( pixelColor [ 1 ] , 255 , 5 ) ;
657+ assert . approximately ( pixelColor [ 2 ] , 255 , 5 ) ;
624658 } ) ;
625659 test ( 'handle nested if statements' , ( ) => {
626660 myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
@@ -1192,7 +1226,7 @@ suite('p5.Shader', function() {
11921226 // Normal of plane facing camera should be [0, 0, 1], so color should be [0, 0, 255]
11931227 const centerColor = myp5 . get ( 25 , 25 ) ;
11941228 assert . approximately ( centerColor [ 0 ] , 0 , 5 ) ; // Red component
1195- assert . approximately ( centerColor [ 1 ] , 0 , 5 ) ; // Green component
1229+ assert . approximately ( centerColor [ 1 ] , 0 , 5 ) ; // Green component
11961230 assert . approximately ( centerColor [ 2 ] , 255 , 5 ) ; // Blue component
11971231 } ) ;
11981232
0 commit comments