@@ -714,6 +714,52 @@ suite('p5.Shader', function() {
714714 assert . approximately ( pixelColor [ 1 ] , 255 , 5 ) ; // Green channel should be 255
715715 assert . approximately ( pixelColor [ 2 ] , 255 , 5 ) ; // Blue channel should be 255
716716 } ) ;
717+ test ( 'handle if statement with || (OR) operator' , ( ) => {
718+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
719+ const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
720+ myp5 . getPixelInputs ( inputs => {
721+ let c = [ 1 , 1 , 1 , 1 ] ;
722+ if ( myp5 . abs ( inputs . texCoord . x - 0.5 ) > 0.2 || myp5 . abs ( inputs . texCoord . y - 0.5 ) > 0.2 ) {
723+ c = [ 1 , 0 , 0 , 1 ] ;
724+ }
725+ inputs . color = c ;
726+ return inputs ;
727+ } ) ;
728+ } , { myp5 } ) ;
729+ myp5 . noStroke ( ) ;
730+ myp5 . shader ( testShader ) ;
731+ myp5 . plane ( myp5 . width , myp5 . height ) ;
732+ const centerPixel = myp5 . get ( 25 , 25 ) ;
733+ assert . approximately ( centerPixel [ 0 ] , 255 , 5 ) ;
734+ assert . approximately ( centerPixel [ 1 ] , 255 , 5 ) ;
735+ assert . approximately ( centerPixel [ 2 ] , 255 , 5 ) ;
736+ const edgePixel = myp5 . get ( 5 , 25 ) ;
737+ assert . approximately ( edgePixel [ 0 ] , 255 , 5 ) ;
738+ assert . approximately ( edgePixel [ 1 ] , 0 , 5 ) ;
739+ assert . approximately ( edgePixel [ 2 ] , 0 , 5 ) ;
740+ } ) ;
741+ test ( 'handle if statement with && (AND) operator' , ( ) => {
742+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
743+ const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
744+ const condition1 = myp5 . uniformFloat ( ( ) => 1.0 ) ;
745+ const condition2 = myp5 . uniformFloat ( ( ) => 1.0 ) ;
746+ myp5 . getPixelInputs ( inputs => {
747+ let color = myp5 . float ( 0.0 ) ;
748+ if ( condition1 > 0.5 && condition2 > 0.5 ) {
749+ color = myp5 . float ( 1.0 ) ;
750+ }
751+ inputs . color = [ color , color , color , 1.0 ] ;
752+ return inputs ;
753+ } ) ;
754+ } , { myp5 } ) ;
755+ myp5 . noStroke ( ) ;
756+ myp5 . shader ( testShader ) ;
757+ myp5 . plane ( myp5 . width , myp5 . height ) ;
758+ const pixelColor = myp5 . get ( 25 , 25 ) ;
759+ assert . approximately ( pixelColor [ 0 ] , 255 , 5 ) ;
760+ assert . approximately ( pixelColor [ 1 ] , 255 , 5 ) ;
761+ assert . approximately ( pixelColor [ 2 ] , 255 , 5 ) ;
762+ } ) ;
717763 // Keep one direct API test for completeness
718764 test ( 'handle direct StrandsIf API usage' , ( ) => {
719765 myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
0 commit comments