Skip to content

Commit be83869

Browse files
committed
USD ShaderAlgo : Ensure lights load with light shader type
Although we are generally trying to follow OSL's lead and treat shader type as irrelevant, we still have a few dependencies on it. One is in Gaffer's StandardLightVisualiser, where it is used to look up the metadata used to visualise a light, so it's worth getting this right.
1 parent 9afe1de commit be83869

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

contrib/IECoreUSD/src/IECoreUSD/ShaderAlgo.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,24 @@ namespace
5858

5959
pxr::TfToken g_adapterLabelToken( IECoreScene::ShaderNetworkAlgo::componentConnectionAdapterLabel().string() );
6060

61-
pxr::TfToken shaderId( const pxr::UsdShadeConnectableAPI &connectable )
61+
std::pair<pxr::TfToken, std::string> shaderIdAndType( const pxr::UsdShadeConnectableAPI &connectable )
6262
{
63-
pxr::TfToken result;
63+
pxr::TfToken id;
64+
std::string type;
6465
if( auto shader = pxr::UsdShadeShader( connectable ) )
6566
{
66-
shader.GetShaderId( &result );
67+
shader.GetShaderId( &id );
68+
type = "surface";
6769
}
6870
#if PXR_VERSION >= 2111
6971
else if( auto light = pxr::UsdLuxLightAPI( connectable ) )
7072
{
71-
light.GetShaderIdAttr().Get( &result );
73+
light.GetShaderIdAttr().Get( &id );
74+
type = "light";
7275
}
7376
#endif
7477

75-
return result;
78+
return std::make_pair( id, type );
7679
}
7780

7881
void readAdditionalLightParameters( const pxr::UsdPrim &prim, IECore::CompoundDataMap &parameters )
@@ -106,9 +109,8 @@ IECore::InternedString readShaderNetworkWalk( const pxr::SdfPath &anchorPath, co
106109
return handle;
107110
}
108111

109-
const pxr::TfToken id = shaderId( usdShader );
112+
auto [id, shaderType] = shaderIdAndType( usdShader );
110113
std::string shaderName = "defaultsurface";
111-
std::string shaderType = "surface";
112114
if( id.size() )
113115
{
114116
std::string name = id.GetString();

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,6 +3022,9 @@ def testLightAttribute( self ) :
30223022
self.assertEqual( shader.size(), 1 )
30233023
self.assertEqual( shader.getOutput(), "SpotLight23" )
30243024

3025+
self.assertEqual( shader.getShader( "SpotLight23" ).name, "SphereLight" )
3026+
self.assertEqual( shader.getShader( "SpotLight23" ).type, "light" )
3027+
30253028
self.assertEqual(
30263029
shader.getShader( "SpotLight23" ).parameters,
30273030
IECore.CompoundData( {

0 commit comments

Comments
 (0)