@@ -475,6 +475,73 @@ def testSerialisation( self ) :
475
475
self .assertIsNone ( scriptNode ["target" ]["parameters" ]["b1" ].getInput () )
476
476
self .assertEqual ( str ( scriptNode ["target" ]["parameters" ]["b2" ].getInput () ), str ( q ["out" ][1 ]["exists" ] ) )
477
477
478
+ def testInheritedGlobalShader ( self ) :
479
+
480
+ sphere = GafferScene .Sphere ()
481
+
482
+ globalSurface = GafferSceneTest .TestShader ( "surface" )
483
+ globalSurface ["type" ].setValue ( "test:surface" )
484
+ globalSurface ["parameters" ]["i" ].setValue ( 2 )
485
+ globalSurface ["parameters" ]["c" ].setValue ( imath .Color3f ( 0.3 , 0.4 , 0.5 ) )
486
+
487
+ globalAttributes = GafferScene .CustomAttributes ()
488
+ globalAttributes ["in" ].setInput ( sphere ["out" ] )
489
+ globalAttributes ["global" ].setValue ( True )
490
+ globalAttributes ["extraAttributes" ].setValue ( IECore .CompoundObject ( { "test:surface" : globalSurface .attributes ()["test:surface" ] } ) )
491
+
492
+ surface = GafferSceneTest .TestShader ( "surface" )
493
+ surface ["type" ].setValue ( "test:surface" )
494
+ surface ["parameters" ]["i" ].setValue ( 3 )
495
+ surface ["parameters" ]["c" ].setValue ( imath .Color3f ( 0.6 , 0.7 , 0.8 ) )
496
+
497
+ shaderAssignment = GafferScene .ShaderAssignment ()
498
+ shaderAssignment ["in" ].setInput ( globalAttributes ["out" ] )
499
+ shaderAssignment ["shader" ].setInput ( surface ["out" ] )
500
+ shaderAssignment ["enabled" ].setValue ( False )
501
+
502
+ query = GafferScene .ShaderQuery ()
503
+ query ["scene" ].setInput ( shaderAssignment ["out" ] )
504
+ query ["location" ].setValue ( "/sphere" )
505
+ query ["shader" ].setValue ( "test:surface" )
506
+
507
+ v1 = query .addQuery ( Gaffer .IntPlug ( "i" , Gaffer .Plug .Direction .Out , 1 ), "i" )
508
+ v2 = query .addQuery ( Gaffer .Color3fPlug ( "c3f" , Gaffer .Plug .Direction .Out , imath .Color3f ( 0.1 , 0.2 , 0.3 ) ), "c" )
509
+
510
+ self .assertFalse ( query ["out" ][0 ]["exists" ].getValue () )
511
+ self .assertFalse ( query ["out" ][1 ]["exists" ].getValue () )
512
+
513
+ query ["inherit" ].setValue ( True )
514
+
515
+ self .assertTrue ( query ["out" ][0 ]["exists" ].getValue () )
516
+ self .assertTrue ( query ["out" ][1 ]["exists" ].getValue () )
517
+
518
+ self .assertEqual ( query ["out" ][0 ]["value" ].getValue (), 2 )
519
+ self .assertEqual ( query ["out" ][1 ]["value" ].getValue (), imath .Color3f ( 0.3 , 0.4 , 0.5 ) )
520
+
521
+ globalSurface ["parameters" ]["i" ].setValue ( 10 )
522
+ globalAttributes ["extraAttributes" ].setValue ( IECore .CompoundObject ( { "test:surface" : globalSurface .attributes ()["test:surface" ] } ) )
523
+
524
+ self .assertTrue ( query ["out" ][0 ]["exists" ].getValue () )
525
+ self .assertTrue ( query ["out" ][1 ]["exists" ].getValue () )
526
+
527
+ self .assertEqual ( query ["out" ][0 ]["value" ].getValue (), 10 )
528
+ self .assertEqual ( query ["out" ][1 ]["value" ].getValue (), imath .Color3f ( 0.3 , 0.4 , 0.5 ) )
529
+
530
+ shaderAssignment ["enabled" ].setValue ( True )
531
+
532
+ self .assertTrue ( query ["out" ][0 ]["exists" ].getValue () )
533
+ self .assertTrue ( query ["out" ][1 ]["exists" ].getValue () )
534
+
535
+ self .assertEqual ( query ["out" ][0 ]["value" ].getValue (), 3 )
536
+ self .assertEqual ( query ["out" ][1 ]["value" ].getValue (), imath .Color3f ( 0.6 , 0.7 , 0.8 ) )
537
+
538
+ query ["inherit" ].setValue ( False )
539
+
540
+ self .assertTrue ( query ["out" ][0 ]["exists" ].getValue () )
541
+ self .assertTrue ( query ["out" ][1 ]["exists" ].getValue () )
542
+
543
+ self .assertEqual ( query ["out" ][0 ]["value" ].getValue (), 3 )
544
+ self .assertEqual ( query ["out" ][1 ]["value" ].getValue (), imath .Color3f ( 0.6 , 0.7 , 0.8 ) )
478
545
479
546
if __name__ == "__main__" :
480
547
unittest .main ()
0 commit comments