@@ -368,35 +368,50 @@ export function createShaderHooksFunctions(strandsContext, fn, shader) {
368368 CFG . pushBlock ( cfg , entryBlockID ) ;
369369 const args = createHookArguments ( strandsContext , hookType . parameters ) ;
370370 const userReturned = hookUserCallback ( ...args ) ;
371+
372+ // Auto-return input if types match and user didn't return anything
373+ let effectiveReturn = userReturned ;
374+ if ( userReturned === undefined ) {
375+ const expected = hookType . returnType ;
376+ if ( isStructType ( expected . typeName ) ) {
377+ if ( hookType . parameters . length === 1 ) {
378+ const paramType = hookType . parameters [ 0 ] . type . typeName ;
379+ if ( paramType === expected . typeName ) {
380+ effectiveReturn = args [ 0 ] ;
381+ }
382+ }
383+ }
384+ }
385+
371386 const expectedReturnType = hookType . returnType ;
372387 let rootNodeID = null ;
373388 if ( isStructType ( expectedReturnType . typeName ) ) {
374389 const expectedStructType = structType ( expectedReturnType ) ;
375- if ( userReturned instanceof StrandsNode ) {
376- const returnedNode = getNodeDataFromID ( strandsContext . dag , userReturned . id ) ;
390+ if ( effectiveReturn instanceof StrandsNode ) {
391+ const returnedNode = getNodeDataFromID ( strandsContext . dag , effectiveReturn . id ) ;
377392 if ( returnedNode . baseType !== expectedStructType . typeName ) {
378- FES . userError ( "type error" , `You have returned a ${ userReturned . baseType } from ${ hookType . name } when a ${ expectedStructType . typeName } was expected.` ) ;
393+ FES . userError ( "type error" , `You have returned a ${ effectiveReturn . baseType } from ${ hookType . name } when a ${ expectedStructType . typeName } was expected.` ) ;
379394 }
380395 const newDeps = returnedNode . dependsOn . slice ( ) ;
381396 for ( let i = 0 ; i < expectedStructType . properties . length ; i ++ ) {
382397 const expectedType = expectedStructType . properties [ i ] . dataType ;
383- const receivedNode = createStrandsNode ( returnedNode . dependsOn [ i ] , dag . dependsOn [ userReturned . id ] , strandsContext ) ;
398+ const receivedNode = createStrandsNode ( returnedNode . dependsOn [ i ] , dag . dependsOn [ effectiveReturn . id ] , strandsContext ) ;
384399 newDeps [ i ] = enforceReturnTypeMatch ( strandsContext , expectedType , receivedNode , hookType . name ) ;
385400 }
386- dag . dependsOn [ userReturned . id ] = newDeps ;
387- rootNodeID = userReturned . id ;
401+ dag . dependsOn [ effectiveReturn . id ] = newDeps ;
402+ rootNodeID = effectiveReturn . id ;
388403 }
389404 else {
390405 const expectedProperties = expectedStructType . properties ;
391406 const newStructDependencies = [ ] ;
392407 for ( let i = 0 ; i < expectedProperties . length ; i ++ ) {
393408 const expectedProp = expectedProperties [ i ] ;
394409 const propName = expectedProp . name ;
395- const receivedValue = userReturned [ propName ] ;
410+ const receivedValue = effectiveReturn [ propName ] ;
396411 if ( receivedValue === undefined ) {
397412 FES . userError ( 'type error' , `You've returned an incomplete struct from ${ hookType . name } .\n` +
398413 `Expected: { ${ expectedReturnType . properties . map ( p => p . name ) . join ( ', ' ) } }\n` +
399- `Received: { ${ Object . keys ( userReturned ) . join ( ', ' ) } }\n` +
414+ `Received: { ${ Object . keys ( effectiveReturn ) . join ( ', ' ) } }\n` +
400415 `All of the properties are required!` ) ;
401416 }
402417 const expectedTypeInfo = expectedProp . dataType ;
@@ -409,7 +424,7 @@ export function createShaderHooksFunctions(strandsContext, fn, shader) {
409424 }
410425 else /*if(isNativeType(expectedReturnType.typeName))*/ {
411426 const expectedTypeInfo = TypeInfoFromGLSLName [ expectedReturnType . typeName ] ;
412- rootNodeID = enforceReturnTypeMatch ( strandsContext , expectedTypeInfo , userReturned , hookType . name ) ;
427+ rootNodeID = enforceReturnTypeMatch ( strandsContext , expectedTypeInfo , effectiveReturn , hookType . name ) ;
413428 }
414429 const fullHookName = `${ hookType . returnType . typeName } ${ hookType . name } ` ;
415430 const hookInfo = availableHooks [ fullHookName ] ;
0 commit comments