Skip to content

Commit b9fc7dc

Browse files
authored
Merge pull request #1410 from johnhaddon/arnoldShaderTypeFix
USD ShaderAlgo : Improve shader type heuristics
2 parents 85ae0d7 + acc6091 commit b9fc7dc

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

Changes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
10.5.x.x (relative to 10.5.6.1)
22
========
33

4+
Fixes
5+
-----
46

7+
- USDScene : Fixed round-tripping of `ai:light` shader type for the output shader of light networks.
58

69
10.5.6.1 (relative to 10.5.6.0)
710
========

contrib/IECoreUSD/src/IECoreUSD/ShaderAlgo.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "pxr/usd/usd/schemaRegistry.h"
5050
#endif
5151

52+
#include "boost/algorithm/string/predicate.hpp"
5253
#include "boost/algorithm/string/replace.hpp"
5354
#include "boost/pointer_cast.hpp"
5455

@@ -391,22 +392,28 @@ IECoreScene::ShaderNetworkPtr IECoreUSD::ShaderAlgo::readShaderNetwork( const px
391392
IECoreScene::ShaderNetworkPtr result = new IECoreScene::ShaderNetwork();
392393
IECoreScene::ShaderNetwork::Parameter outputHandle = readShaderNetworkWalk( usdSource.GetPrim().GetParent().GetPath(), usdSource.GetOutput( usdSourceName ), *result );
393394

394-
// For the output shader, set the type to "ai:surface" if it is "ai:shader".
395-
// This is complete nonsense - there is nothing to suggest that this shader is
396-
// of type surface - it could be a simple texture or noise, or even a
397-
// displacement or volume shader.
395+
// If the output shader has type "ai:shader" then set its type to
396+
// "ai:surface" or "ai:light" as appropriate. This is just a heuristic,
397+
// needed because we don't write the type out in `writeShaderNetwork()`.
398+
// It's fragile because it is possible to assign `ai:shader` types as
399+
// displacements or volumes as well as surfaces. But in the majority of
400+
// cases this allows us to round-trip shader assignments as required by
401+
// Gaffer's conventions.
398402
//
399-
// But arbitrarily setting the type on the output to "ai:surface" matches our
400-
// current Gaffer convention, so it allows round-tripping.
401-
// In the long run, the fact this is working at all appears to indicate that we
402-
// don't use the suffix of the shader type for anything, and we should just set
403-
// everything to prefix:shader ( aside from lights, which are a bit of a
404-
// different question )
403+
/// \todo In the long run, we want to stop relying on shader types
404+
/// completely.
405405
const IECoreScene::Shader *outputShader = result->getShader( outputHandle.shader );
406406
if( outputShader->getType() == "ai:shader" )
407407
{
408408
IECoreScene::ShaderPtr o = outputShader->copy();
409-
o->setType( "ai:surface" );
409+
if( boost::ends_with( outputShader->getName(), "_light" ) )
410+
{
411+
o->setType( "ai:light" );
412+
}
413+
else
414+
{
415+
o->setType( "ai:surface" );
416+
}
410417
result->setShader( outputHandle.shader, std::move( o ) );
411418
}
412419

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3977,7 +3977,7 @@ def testRoundTripArnoldLight( self ) :
39773977

39783978
lightShader = IECoreScene.ShaderNetwork(
39793979
shaders = {
3980-
"light" : IECoreScene.Shader( "distant_light", parameters = { "exposure" : 2.0 } )
3980+
"light" : IECoreScene.Shader( "distant_light", "ai:light", parameters = { "exposure" : 2.0 } )
39813981
},
39823982
output = "light",
39833983
)

0 commit comments

Comments
 (0)