Skip to content

Commit b06027f

Browse files
FIX : ShaderNetworkAlgo : PR Feedback
1 parent a6f62c2 commit b06027f

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/IECoreScene/ShaderNetworkAlgo.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,16 @@ std::pair< size_t, size_t > getEndPointDuplication( const T &basis )
813813
}
814814

815815
std::tuple< const std::string*, const std::string*, const std::string*, const std::string*, const std::string* >
816-
lookupSplinePlugSuffixes( const std::string &shaderBaseName )
816+
lookupSplinePlugSuffixes( const std::string &shaderName )
817817
{
818818
// We seem to be able to identify shaders that should use the PRMan convention by whether they start
819-
// with one of the PRMan prefixes
820-
if( boost::starts_with( shaderBaseName, "Pxr" ) || boost::starts_with( shaderBaseName, "Lama" ) )
819+
// with one of the PRMan prefixes.
820+
// NOTE : This will fail if a shader is loaded from an explicit path, rather than being found in the
821+
// search path, because the shader name will include the full file path. We consider this an
822+
// acceptable failure, because shaders should be found in the search paths.
823+
if( boost::starts_with( shaderName, "Pxr" ) || boost::starts_with( shaderName, "Lama" ) )
821824
{
825+
// The convention used by the PRMan shader library.
822826
static const std::string positions( "_Knots" );
823827
static const std::string floatValues( "_Floats" );
824828
static const std::string colorValues( "_Colors" );
@@ -828,6 +832,7 @@ lookupSplinePlugSuffixes( const std::string &shaderBaseName )
828832
}
829833
else
830834
{
835+
// The convention used by the OSL shaders that we ship with Gaffer.
831836
static const std::string positions( "Positions" );
832837
static const std::string values( "Values" );
833838
static const std::string basis( "Basis" );
@@ -836,7 +841,7 @@ lookupSplinePlugSuffixes( const std::string &shaderBaseName )
836841
}
837842

838843
template<typename Spline>
839-
void expandSpline( const InternedString &name, const Spline &spline, CompoundDataMap &newParameters, const std::string &shaderBaseName )
844+
void expandSpline( const InternedString &name, const Spline &spline, CompoundDataMap &newParameters, const std::string &shaderName )
840845
{
841846
const char *basis = "catmull-rom";
842847
if( spline.basis == Spline::Basis::bezier() )
@@ -890,7 +895,7 @@ void expandSpline( const InternedString &name, const Spline &spline, CompoundDat
890895
}
891896
}
892897

893-
auto [ positionsSuffix, floatValuesSuffix, colorValuesSuffix, basisSuffix, countSuffix ] = lookupSplinePlugSuffixes( shaderBaseName );
898+
auto [ positionsSuffix, floatValuesSuffix, colorValuesSuffix, basisSuffix, countSuffix ] = lookupSplinePlugSuffixes( shaderName );
894899

895900
newParameters[ name.string() + *positionsSuffix ] = positionsData;
896901
if constexpr( std::is_same_v< typename Spline::YType, float > )
@@ -980,10 +985,10 @@ void ensureParametersCopy(
980985
}
981986
}
982987

983-
IECore::ConstCompoundDataPtr collapseSplineParametersInternal( const IECore::ConstCompoundDataPtr &parametersData, const std::string &shaderBaseName )
988+
IECore::ConstCompoundDataPtr collapseSplineParametersInternal( const IECore::ConstCompoundDataPtr &parametersData, const std::string &shaderName )
984989
{
985990

986-
auto [ positionsSuffix, floatValuesSuffix, colorValuesSuffix, basisSuffix, countSuffix ] = lookupSplinePlugSuffixes( shaderBaseName );
991+
auto [ positionsSuffix, floatValuesSuffix, colorValuesSuffix, basisSuffix, countSuffix ] = lookupSplinePlugSuffixes( shaderName );
987992

988993
const CompoundDataMap &parameters( parametersData->readable() );
989994
CompoundDataPtr newParametersData;
@@ -1022,7 +1027,7 @@ IECore::ConstCompoundDataPtr collapseSplineParametersInternal( const IECore::Con
10221027
IECore::InternedString countName = prefix + *countSuffix;
10231028
const auto countIter = parameters.find( countName );
10241029
const IntData *countData = nullptr;
1025-
if( countIter == parameters.end() )
1030+
if( countIter != parameters.end() )
10261031
{
10271032
countData = runTimeCast<const IntData>( countIter->second.get() );
10281033
}
@@ -1166,11 +1171,6 @@ std::pair< InternedString, int > createSplineInputAdapter(
11661171
return std::make_pair( adapterHandle, getEndPointDuplication( splineData->readable().basis ).first );
11671172
}
11681173

1169-
std::string shaderBaseNameFromPath( const std::string shaderName )
1170-
{
1171-
return std::filesystem::path( shaderName ).filename().string();
1172-
}
1173-
11741174
} // namespace
11751175

11761176
void ShaderNetworkAlgo::collapseSplines( ShaderNetwork *network, std::string targetPrefix )
@@ -1195,12 +1195,12 @@ void ShaderNetworkAlgo::collapseSplines( ShaderNetwork *network, std::string tar
11951195
}
11961196

11971197
// For nodes which aren't spline adapters, we just need to deal with any parameters that are splines
1198-
ConstCompoundDataPtr collapsed = collapseSplineParametersInternal( shader->parametersData(), shaderBaseNameFromPath( shader->getName() ) );
1198+
ConstCompoundDataPtr collapsed = collapseSplineParametersInternal( shader->parametersData(), shader->getName() );
11991199
if( collapsed != shader->parametersData() )
12001200
{
12011201
// \todo - this const_cast is ugly, although safe because if the return from collapseSplineParameterInternals
12021202
// doesn't match the input, it is freshly allocated. Once collapseSplineParameters is fully
1203-
// deprecated, and no longer visible publicly, an internal version of collapseSplineParametersInternal could
1203+
// deprecated, and no longer visible publicly, collapseSplineParametersInternal could
12041204
// just return a non-const new parameter data, or nullptr if no changes are needed.
12051205
network->setShader( name, std::move( new Shader( shader->getName(), shader->getType(), const_cast< CompoundData *>( collapsed.get() ) ) ) );
12061206
}
@@ -1322,13 +1322,13 @@ void ShaderNetworkAlgo::expandSplines( ShaderNetwork *network, std::string targe
13221322
{
13231323
ensureParametersCopy( origParameters, newParametersData, newParameters );
13241324
newParameters->erase( name );
1325-
expandSpline( name, colorSpline->readable(), *newParameters, shaderBaseNameFromPath( s.second->getName() ) );
1325+
expandSpline( name, colorSpline->readable(), *newParameters, s.second->getName() );
13261326
}
13271327
else if( const SplineffData *floatSpline = runTimeCast<const SplineffData>( value.get() ) )
13281328
{
13291329
ensureParametersCopy( origParameters, newParametersData, newParameters );
13301330
newParameters->erase( name );
1331-
expandSpline( name, floatSpline->readable(), *newParameters, shaderBaseNameFromPath( s.second->getName() ) );
1331+
expandSpline( name, floatSpline->readable(), *newParameters, s.second->getName() );
13321332
}
13331333
}
13341334

0 commit comments

Comments
 (0)