@@ -1128,6 +1128,40 @@ suite('p5.Shader', function() {
11281128 const pixelColor = myp5 . get ( 25 , 25 ) ;
11291129 assert . approximately ( pixelColor [ 0 ] , 127 , 5 ) ; // 0.5 * 255 ≈ 127
11301130 } ) ;
1131+
1132+ test ( 'handle statements after for loop before return' , ( ) => {
1133+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
1134+
1135+ const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
1136+ myp5 . getPixelInputs ( inputs => {
1137+ let avg = myp5 . vec3 ( 0.0 ) ;
1138+ let total = 0.0 ;
1139+
1140+ // Simulate blur-like accumulation in for loop
1141+ for ( let i = 0 ; i < 3 ; i ++ ) {
1142+ const sample = myp5 . vec3 ( 0.2 , 0.1 , 0.3 ) ;
1143+ const weight = 1.0 ;
1144+ avg += weight * sample ;
1145+ total += weight ;
1146+ }
1147+
1148+ const blended = avg / total ;
1149+
1150+ inputs . color = [ blended . x , blended . y , blended . z , 1.0 ] ;
1151+ return inputs ;
1152+ } ) ;
1153+ } , { myp5 } ) ;
1154+
1155+ myp5 . noStroke ( ) ;
1156+ myp5 . shader ( testShader ) ;
1157+ myp5 . plane ( myp5 . width , myp5 . height ) ;
1158+
1159+ // Expected result: (3 * [0.2, 0.1, 0.3]) / 3 = [0.2, 0.1, 0.3]
1160+ const pixelColor = myp5 . get ( 25 , 25 ) ;
1161+ assert . approximately ( pixelColor [ 0 ] , 51 , 5 ) ; // 0.2 * 255 ≈ 51
1162+ assert . approximately ( pixelColor [ 1 ] , 25 , 5 ) ; // 0.1 * 255 ≈ 25
1163+ assert . approximately ( pixelColor [ 2 ] , 77 , 5 ) ; // 0.3 * 255 ≈ 77
1164+ } ) ;
11311165 } ) ;
11321166
11331167 suite ( 'passing data between shaders' , ( ) => {
0 commit comments