Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
10.6.x.x (relative to 10.6.1.0)
========

Improvements
------------

- ShaderNetwork : Optimised applySubstitutions() for cases where not all shaders need them.

Fixes
-----

- ShaderNetwork::hashSubstitutions : Fixed shader string substitutions that are escaped with backslashes ( ie. `myText\<substitutionHandledByArnold\>` ).

10.6.1.0 (relative to 10.6.0.2)
========
Expand Down
4 changes: 2 additions & 2 deletions include/IECoreScene/ShaderNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class IECORESCENE_API ShaderNetwork : public IECore::BlindDataHolder
///
/// We support special syntax that allows you to substitute string attributes
/// into the values of string parameters on shaders.
///
///
/// If a string parameter, or string vector parameter, contains the token
/// <attr:PARAMETER_NAME>, then it will be subsituted with the value of a
/// string attribute named PARAMETER_NAME. If there is no attribute named
Expand All @@ -208,7 +208,7 @@ class IECORESCENE_API ShaderNetwork : public IECore::BlindDataHolder
/// you can escape the angle brackets with backslashes, like
/// "\<attr:PARAMETER_NAME\>"

/// Appends all attributes used by `applySubstitutions()` into the hash.
/// Appends to the hash to reflect all changes made by applySubstitutions( attributes ).
void hashSubstitutions( const IECore::CompoundObject *attributes, IECore::MurmurHash &h ) const;

/// Apply substitutions to all string and string vector parameters in the network,
Expand Down
12 changes: 11 additions & 1 deletion src/IECoreScene/ShaderNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ class ShaderNetwork::Implementation
h.append( 0 );
}
}

if( m_parmsNeedingSubstitution.size() && !m_neededSubstitutions.size() )
{
// We don't depend on any attributes, but some parameters have escaped substitutions.
// Modify hash to reflect the fact that applySubstitutions() will remove the escaping.
h.append( true );
}
}

void applySubstitutions( const CompoundObject *attributes )
Expand Down Expand Up @@ -745,7 +752,10 @@ class ShaderNetwork::Implementation
}
}

m_parmsNeedingSubstitution[ node.handle ] = parmsNeedingSub;
if( parmsNeedingSub.size() )
{
m_parmsNeedingSubstitution[ node.handle ] = parmsNeedingSub;
}
}

m_hash.append( m_output.shader );
Expand Down
2 changes: 2 additions & 0 deletions test/IECoreScene/ShaderNetworkTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ def testSubstitutions( self ) :
} ) )
( h6, sSubst6 ) = self.__hashAndSubstitution( s, {} )
( h7, sSubst7 ) = self.__hashAndSubstitution( s, allAttributes )
self.assertNotEqual( h6, IECore.MurmurHash() )
self.assertNotEqual( h7, IECore.MurmurHash() )
self.assertEqual( h6, h7 )
self.assertEqual( sSubst6, sSubst7 )
self.assertEqual( sSubst6.parameters["a"].value, "pre<attr:fred>post" )
Expand Down