From 0dcee2e912cd7e948b61405132d8d71685adb5cc Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 23 Nov 2016 10:34:01 +0000 Subject: [PATCH 1/3] DependencyNode : Add todo. --- include/Gaffer/DependencyNode.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/Gaffer/DependencyNode.h b/include/Gaffer/DependencyNode.h index dc7a36b4a59..f067f98fac5 100644 --- a/include/Gaffer/DependencyNode.h +++ b/include/Gaffer/DependencyNode.h @@ -67,6 +67,9 @@ class DependencyNode : public Node /// for input or to place one in outputs as computations are always performed on the /// leaf level plugs only. Implementations of this method should call the base class /// implementation first. + /// \todo Make this protected, and add an accessor on the Plug class instead. + /// The general principle in effect elsewhere in Gaffer is that plugs provide + /// the public interface to the work done by nodes. virtual void affects( const Plug *input, AffectedPlugsContainer &outputs ) const = 0; /// @name Enable/Disable Behaviour From 082931f7c346b690ed6d19fd7faacb498e571426 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 23 Nov 2016 10:35:22 +0000 Subject: [PATCH 2/3] ArnoldDisplacement : Fix dirty propagation. --- include/GafferArnold/ArnoldDisplacement.h | 2 ++ .../GafferArnoldTest/ArnoldDisplacementTest.py | 16 ++++++++++++++++ src/GafferArnold/ArnoldDisplacement.cpp | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/include/GafferArnold/ArnoldDisplacement.h b/include/GafferArnold/ArnoldDisplacement.h index b5c3201e704..9efc2909a97 100644 --- a/include/GafferArnold/ArnoldDisplacement.h +++ b/include/GafferArnold/ArnoldDisplacement.h @@ -79,6 +79,8 @@ class ArnoldDisplacement : public GafferScene::Shader Gaffer::Plug *outPlug(); const Gaffer::Plug *outPlug() const; + virtual void affects( const Gaffer::Plug *input, AffectedPlugsContainer &outputs ) const; + virtual void attributesHash( IECore::MurmurHash &h ) const; virtual IECore::ConstCompoundObjectPtr attributes() const; diff --git a/python/GafferArnoldTest/ArnoldDisplacementTest.py b/python/GafferArnoldTest/ArnoldDisplacementTest.py index d88ebcbcf15..4d7964b90e8 100644 --- a/python/GafferArnoldTest/ArnoldDisplacementTest.py +++ b/python/GafferArnoldTest/ArnoldDisplacementTest.py @@ -38,6 +38,7 @@ import IECore +import GafferTest import GafferSceneTest import GafferArnold @@ -72,6 +73,21 @@ def test( self ) : d["enabled"].setValue( False ) self.assertEqual( d.attributes(), IECore.CompoundObject() ) + def testDirtyPropagation( self ) : + + n = GafferArnold.ArnoldShader() + n.loadShader( "noise" ) + + d = GafferArnold.ArnoldDisplacement() + cs = GafferTest.CapturingSlot( d.plugDirtiedSignal() ) + + d["height"].setValue( 10 ) + self.assertTrue( d["out"] in [ x[0] for x in cs ] ) + + del cs[:] + d["map"].setInput( n["out"] ) + self.assertTrue( d["out"] in [ x[0] for x in cs ] ) + def testNoInput( self ) : d = GafferArnold.ArnoldDisplacement() diff --git a/src/GafferArnold/ArnoldDisplacement.cpp b/src/GafferArnold/ArnoldDisplacement.cpp index fc868130feb..25a3b28ebb2 100644 --- a/src/GafferArnold/ArnoldDisplacement.cpp +++ b/src/GafferArnold/ArnoldDisplacement.cpp @@ -128,6 +128,22 @@ const Gaffer::Plug *ArnoldDisplacement::outPlug() const return getChild( g_firstPlugIndex + 5 ); } +void ArnoldDisplacement::affects( const Gaffer::Plug *input, AffectedPlugsContainer &outputs ) const +{ + Shader::affects( input, outputs ); + + if( + input == mapPlug() || + input == heightPlug() || + input == paddingPlug() || + input == zeroValuePlug() || + input == autoBumpPlug() + ) + { + outputs.push_back( outPlug() ); + } +} + void ArnoldDisplacement::attributesHash( IECore::MurmurHash &h ) const { h.append( typeId() ); From 3708c81b335e0b13a3fe57df4b81a85a7de45616 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Wed, 23 Nov 2016 11:16:38 +0000 Subject: [PATCH 3/3] ArnoldDisplacement : Accept OSLShader inputs to map plug. --- .../ArnoldDisplacementTest.py | 25 +++++++++++++++++++ src/GafferArnold/ArnoldDisplacement.cpp | 17 ++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/python/GafferArnoldTest/ArnoldDisplacementTest.py b/python/GafferArnoldTest/ArnoldDisplacementTest.py index 4d7964b90e8..f6afc025cf7 100644 --- a/python/GafferArnoldTest/ArnoldDisplacementTest.py +++ b/python/GafferArnoldTest/ArnoldDisplacementTest.py @@ -40,6 +40,7 @@ import GafferTest import GafferSceneTest +import GafferOSL import GafferArnold class ArnoldDisplacementTest( GafferSceneTest.SceneTestCase ) : @@ -88,6 +89,30 @@ def testDirtyPropagation( self ) : d["map"].setInput( n["out"] ) self.assertTrue( d["out"] in [ x[0] for x in cs ] ) + def testOSLShaderInput( self ) : + + n = GafferOSL.OSLShader() + n.loadShader( "Pattern/Noise" ) + + d = GafferArnold.ArnoldDisplacement() + + d["map"].setInput( n["out"] ) + self.assertTrue( d["map"].getInput().isSame( n["out"] ) ) + + na = n.attributes() + da = d.attributes() + + self.assertEqual( + da, + IECore.CompoundObject( { + "ai:disp_map" : na["osl:shader"], + "ai:disp_height" : IECore.FloatData( 1 ), + "ai:disp_padding" : IECore.FloatData( 0 ), + "ai:disp_zero_value" : IECore.FloatData( 0 ), + "ai:disp_autobump" : IECore.BoolData( False ), + } ) + ) + def testNoInput( self ) : d = GafferArnold.ArnoldDisplacement() diff --git a/src/GafferArnold/ArnoldDisplacement.cpp b/src/GafferArnold/ArnoldDisplacement.cpp index 25a3b28ebb2..6ac878e8517 100644 --- a/src/GafferArnold/ArnoldDisplacement.cpp +++ b/src/GafferArnold/ArnoldDisplacement.cpp @@ -45,12 +45,12 @@ using namespace GafferArnold; IE_CORE_DEFINERUNTIMETYPED( ArnoldDisplacement ); size_t ArnoldDisplacement::g_firstPlugIndex = 0; -static IECore::InternedString g_surfaceAttributeName = "ai:surface"; static IECore::InternedString g_mapAttributeName = "ai:disp_map"; static IECore::InternedString g_paddingAttributeName = "ai:disp_padding"; static IECore::InternedString g_heightAttributeName = "ai:disp_height"; static IECore::InternedString g_zeroValueAttributeName = "ai:disp_zero_value"; static IECore::InternedString g_autoBumpAttributeName = "ai:disp_autobump"; +static IECore::InternedString g_mapInputAttributeNames[] = { "ai:surface", "osl:shader", "" } ; ArnoldDisplacement::ArnoldDisplacement( const std::string &name ) : Shader( name ) @@ -169,11 +169,16 @@ IECore::ConstCompoundObjectPtr ArnoldDisplacement::attributes() const CompoundObject::ObjectMap &m = result->members(); m = mapPlug()->attributes()->members(); - CompoundObject::ObjectMap::iterator it = m.find( g_surfaceAttributeName ); - if( it != m.end() ) + + for( InternedString *n = g_mapInputAttributeNames; *n != InternedString(); ++n ) { - m[g_mapAttributeName] = it->second; - m.erase( it ); + CompoundObject::ObjectMap::iterator it = m.find( *n ); + if( it != m.end() ) + { + m[g_mapAttributeName] = it->second; + m.erase( it ); + break; + } } m[g_heightAttributeName] = new FloatData( heightPlug()->getValue() ); @@ -200,7 +205,7 @@ bool ArnoldDisplacement::acceptsInput( const Gaffer::Plug *plug, const Gaffer::P { if( const GafferScene::Shader *shader = runTimeCast( inputPlug->source()->node() ) ) { - return runTimeCast( shader ); + return runTimeCast( shader ) || shader->isInstanceOf( "GafferOSL::OSLShader" ); } }