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" ); } }