@@ -1070,6 +1070,7 @@ suite('p5.Shader', function() {
10701070 suite ( 'passing data between shaders' , ( ) => {
10711071 test ( 'handle passing a value from a vertex hook to a fragment hook' , ( ) => {
10721072 myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
1073+ myp5 . pixelDensity ( 1 ) ;
10731074
10741075 const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
10751076 let worldPos = myp5 . varyingVec3 ( ) ;
@@ -1100,8 +1101,9 @@ suite('p5.Shader', function() {
11001101 assert . approximately ( cornerColor [ 2 ] , 0 , 5 ) ;
11011102 } ) ;
11021103
1103- test ( 'handle passing a value from a vertex hook to a fragment hook' , ( ) => {
1104+ test ( 'handle passing a value from a vertex hook to a fragment hook with swizzle assignment ' , ( ) => {
11041105 myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
1106+ myp5 . pixelDensity ( 1 ) ;
11051107
11061108 const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
11071109 let worldPos = myp5 . varyingVec3 ( ) ;
@@ -1134,6 +1136,7 @@ suite('p5.Shader', function() {
11341136
11351137 test ( 'handle passing a value from a vertex hook to a fragment hook as part of hook output' , ( ) => {
11361138 myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
1139+ myp5 . pixelDensity ( 1 ) ;
11371140
11381141 const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
11391142 let worldPos = myp5 . varyingVec3 ( ) ;
@@ -1164,6 +1167,34 @@ suite('p5.Shader', function() {
11641167 assert . approximately ( cornerColor [ 1 ] , 255 , 5 ) ;
11651168 assert . approximately ( cornerColor [ 2 ] , 0 , 5 ) ;
11661169 } ) ;
1170+
1171+ test ( 'handle passing a value between fragment hooks only' , ( ) => {
1172+ myp5 . createCanvas ( 50 , 50 , myp5 . WEBGL ) ;
1173+ myp5 . pixelDensity ( 1 ) ;
1174+
1175+ const testShader = myp5 . baseMaterialShader ( ) . modify ( ( ) => {
1176+ let processedNormal = myp5 . sharedVec3 ( ) ;
1177+ myp5 . getPixelInputs ( ( inputs ) => {
1178+ processedNormal = myp5 . normalize ( inputs . normal ) ;
1179+ return inputs ;
1180+ } ) ;
1181+ myp5 . getFinalColor ( ( c ) => {
1182+ // Use the processed normal to create a color - should be [0, 0, 1] for plane facing camera
1183+ return [ myp5 . abs ( processedNormal ) , 1 ] ;
1184+ } ) ;
1185+ } , { myp5 } ) ;
1186+
1187+ myp5 . background ( 255 , 0 , 0 ) ; // Red background to distinguish from result
1188+ myp5 . noStroke ( ) ;
1189+ myp5 . shader ( testShader ) ;
1190+ myp5 . plane ( myp5 . width , myp5 . height ) ;
1191+
1192+ // Normal of plane facing camera should be [0, 0, 1], so color should be [0, 0, 255]
1193+ const centerColor = myp5 . get ( 25 , 25 ) ;
1194+ assert . approximately ( centerColor [ 0 ] , 0 , 5 ) ; // Red component
1195+ assert . approximately ( centerColor [ 1 ] , 0 , 5 ) ; // Green component
1196+ assert . approximately ( centerColor [ 2 ] , 255 , 5 ) ; // Blue component
1197+ } ) ;
11671198 } ) ;
11681199
11691200 suite ( 'filter shader hooks' , ( ) => {
0 commit comments