@@ -272,8 +272,37 @@ visualSuite("WebGPU", function () {
272272 p5 . filter ( invert ) ;
273273 await screenshot ( ) ;
274274 } ) ;
275+
276+ visualTest ( 'instanceID in fragment hook colors instances (WebGPU)' , async function ( p5 , screenshot ) {
277+ await p5 . createCanvas ( 50 , 50 , p5 . WEBGPU ) ;
278+ const numInstances = 4 ;
279+ const shader = p5 . baseMaterialShader ( ) . modify ( ( ) => {
280+ // Vertex hook: position instances in a horizontal row
281+ p5 . getWorldInputs ( ( inputs ) => {
282+ const id = p5 . instanceID ( ) ;
283+ const spacing = 12 ;
284+ const offset = ( id - ( numInstances - 1 ) / 2.0 ) * spacing ;
285+ inputs . position . x += offset ;
286+ return inputs ;
287+ } ) ;
288+ // Fragment hook: color each instance based on instanceID
289+ p5 . getFinalColor ( ( color ) => {
290+ const id = p5 . instanceID ( ) ;
291+ const t = id / ( numInstances - 1.0 ) ;
292+ color = [ t , t , t , 1 ] ;
293+ return color ;
294+ } ) ;
295+ } , { p5, numInstances } ) ;
296+ p5 . background ( 128 ) ;
297+ p5 . noStroke ( ) ;
298+ p5 . shader ( shader ) ;
299+ const obj = p5 . buildGeometry ( ( ) => p5 . circle ( 0 , 0 , 10 ) ) ;
300+ p5 . model ( obj , numInstances ) ;
301+ await screenshot ( ) ;
302+ } ) ;
275303 } ) ;
276304
305+
277306 visualSuite ( 'filters' , function ( ) {
278307 const setupSketch = async ( p5 ) => {
279308 await p5 . createCanvas ( 50 , 50 , p5 . WEBGPU ) ;
0 commit comments