@@ -978,6 +978,38 @@ suite('WebGPU p5.Shader', function() {
978978 assert . approximately ( centerColor [ 2 ] , 255 , 5 ) ; // Blue component
979979 } ) ;
980980
981+ test ( 'handle passing a value between fragment hooks only while having a vertex hook' , async ( ) => {
982+ await myp5 . createCanvas ( 50 , 50 , myp5 . WEBGPU ) ;
983+ myp5 . pixelDensity ( 1 ) ;
984+
985+ const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
986+ let processedNormal = myp5 . sharedVec3 ( ) ;
987+ myp5 . objectInputs . begin ( ) ;
988+ myp5 . objectInputs . position += [ 0 , 0 , 0 ] ;
989+ myp5 . objectInputs . end ( ) ;
990+
991+ myp5 . pixelInputs . begin ( ) ;
992+ processedNormal = myp5 . normalize ( myp5 . pixelInputs . normal ) ;
993+ myp5 . pixelInputs . end ( ) ;
994+
995+ myp5 . finalColor . begin ( ) ;
996+ // Use the processed normal to create a color - should be [0, 0, 1] for plane facing camera
997+ myp5 . finalColor . set ( [ myp5 . abs ( processedNormal ) , 1 ] ) ;
998+ myp5 . finalColor . end ( ) ;
999+ } , { myp5 } ) ;
1000+
1001+ myp5 . background ( 255 , 0 , 0 ) ; // Red background to distinguish from result
1002+ myp5 . noStroke ( ) ;
1003+ myp5 . shader ( testShader ) ;
1004+ myp5 . plane ( myp5 . width , myp5 . height ) ;
1005+
1006+ // Normal of plane facing camera should be [0, 0, 1], so color should be [0, 0, 255]
1007+ const centerColor = await myp5 . get ( 25 , 25 ) ;
1008+ assert . approximately ( centerColor [ 0 ] , 0 , 5 ) ; // Red component
1009+ assert . approximately ( centerColor [ 1 ] , 0 , 5 ) ; // Green component
1010+ assert . approximately ( centerColor [ 2 ] , 255 , 5 ) ; // Blue component
1011+ } ) ;
1012+
9811013 test ( 'handle passing a value from a vertex hook to a fragment hook using shared*' , async ( ) => {
9821014 await myp5 . createCanvas ( 50 , 50 , myp5 . WEBGPU ) ;
9831015 myp5 . pixelDensity ( 1 ) ;
0 commit comments