Skip to content

Commit aead080

Browse files
ShaderNetwork : Allow escaped string substitutions to work correctly
1 parent b44492f commit aead080

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

Changes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Improvements
66

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

9+
Fixes
10+
-----
11+
12+
- ShaderNetwork::hashSubstitutions : Fixed shader string substitutions that are escaped with backslashes ( ie. `myText\<substitutionHandledByArnold\>` ).
13+
914
10.6.1.0 (relative to 10.6.0.2)
1015
========
1116

include/IECoreScene/ShaderNetwork.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class IECORESCENE_API ShaderNetwork : public IECore::BlindDataHolder
197197
///
198198
/// We support special syntax that allows you to substitute string attributes
199199
/// into the values of string parameters on shaders.
200-
///
200+
///
201201
/// If a string parameter, or string vector parameter, contains the token
202202
/// <attr:PARAMETER_NAME>, then it will be subsituted with the value of a
203203
/// string attribute named PARAMETER_NAME. If there is no attribute named
@@ -208,7 +208,7 @@ class IECORESCENE_API ShaderNetwork : public IECore::BlindDataHolder
208208
/// you can escape the angle brackets with backslashes, like
209209
/// "\<attr:PARAMETER_NAME\>"
210210

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

214214
/// Apply substitutions to all string and string vector parameters in the network,

src/IECoreScene/ShaderNetwork.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,13 @@ class ShaderNetwork::Implementation
447447
h.append( 0 );
448448
}
449449
}
450+
451+
if( m_parmsNeedingSubstitution.size() && !m_neededSubstitutions.size() )
452+
{
453+
// We don't depend on any attributes, but some parameters have escaped substitutions.
454+
// Modify hash to reflect the fact that applySubstitutions() will remove the escaping.
455+
h.append( true );
456+
}
450457
}
451458

452459
void applySubstitutions( const CompoundObject *attributes )

test/IECoreScene/ShaderNetworkTest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,8 @@ def testSubstitutions( self ) :
591591
} ) )
592592
( h6, sSubst6 ) = self.__hashAndSubstitution( s, {} )
593593
( h7, sSubst7 ) = self.__hashAndSubstitution( s, allAttributes )
594+
self.assertNotEqual( h6, IECore.MurmurHash() )
595+
self.assertNotEqual( h7, IECore.MurmurHash() )
594596
self.assertEqual( h6, h7 )
595597
self.assertEqual( sSubst6, sSubst7 )
596598
self.assertEqual( sSubst6.parameters["a"].value, "pre<attr:fred>post" )

0 commit comments

Comments
 (0)