Skip to content

Commit

Permalink
ArnoldDisplacement : Accept OSLShader inputs to map plug.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Nov 24, 2016
1 parent 082931f commit 3708c81
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
25 changes: 25 additions & 0 deletions python/GafferArnoldTest/ArnoldDisplacementTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import GafferTest
import GafferSceneTest
import GafferOSL
import GafferArnold

class ArnoldDisplacementTest( GafferSceneTest.SceneTestCase ) :
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 11 additions & 6 deletions src/GafferArnold/ArnoldDisplacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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() );
Expand All @@ -200,7 +205,7 @@ bool ArnoldDisplacement::acceptsInput( const Gaffer::Plug *plug, const Gaffer::P
{
if( const GafferScene::Shader *shader = runTimeCast<const GafferScene::Shader>( inputPlug->source<Plug>()->node() ) )
{
return runTimeCast<const ArnoldShader>( shader );
return runTimeCast<const ArnoldShader>( shader ) || shader->isInstanceOf( "GafferOSL::OSLShader" );
}
}

Expand Down

0 comments on commit 3708c81

Please sign in to comment.