Skip to content

Commit 80297f9

Browse files
committed
USDScene : Fix attributesHash() to consider UsdLuxLights
This fixes problems where the light shaders weren't loading in Gaffer at all, because the hash matched other locations where there was no light.
1 parent 0844525 commit 80297f9

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

contrib/IECoreUSD/src/IECoreUSD/USDScene.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,15 @@ void USDScene::attributesHash( double time, IECore::MurmurHash &h ) const
14231423
// Kind can not be animated so no need to update `mightBeTimeVarying`.
14241424
}
14251425

1426+
#if PXR_VERSION >= 2111
1427+
if( m_location->prim.HasAPI<pxr::UsdLuxLightAPI>() )
1428+
{
1429+
/// \todo Consider time-varying lights - see comment below
1430+
/// for materials.
1431+
haveAttributes = true;
1432+
}
1433+
#endif
1434+
14261435
auto doubleSidedAttr = pxr::UsdGeomGprim( m_location->prim ).GetDoubleSidedAttr();
14271436
if( doubleSidedAttr && doubleSidedAttr.HasAuthoredValue() )
14281437
{

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,5 +3186,30 @@ def assertExpected( root ) :
31863186
roundTripRoot = IECoreScene.SceneInterface.create( roundTripFileName, IECore.IndexedIO.OpenMode.Read )
31873187
assertExpected( roundTripRoot )
31883188

3189+
def testMultipleLights( self ) :
3190+
3191+
scene = IECoreScene.SceneInterface.create(
3192+
os.path.join( os.path.dirname( __file__ ), "data", "twoLights.usda" ),
3193+
IECore.IndexedIO.OpenMode.Read
3194+
)
3195+
3196+
self.assertIn( "__lights", scene.setNames() )
3197+
self.assertEqual( scene.readSet( "__lights" ), IECore.PathMatcher( [ "/Light1", "/Light2" ] ) )
3198+
3199+
hashes = {
3200+
scene.child( n ).hash( scene.HashType.AttributesHash, 0 )
3201+
for n in [ "NoLight", "Light1", "Light2" ]
3202+
}
3203+
self.assertEqual( len( hashes ), 3 )
3204+
3205+
for light, exposure in [
3206+
( "Light1", 1 ),
3207+
( "Light2", 2 ),
3208+
] :
3209+
self.assertEqual( scene.child( light ).attributeNames(), [ "light" ] )
3210+
attribute = scene.child( light ).readAttribute( "light", 0 )
3211+
self.assertIsInstance( attribute, IECoreScene.ShaderNetwork )
3212+
self.assertEqual( attribute.outputShader().parameters["exposure"], IECore.FloatData( exposure ) )
3213+
31893214
if __name__ == "__main__":
31903215
unittest.main()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#usda 1.0
2+
3+
def Xform "NoLight" ()
4+
{
5+
}
6+
7+
def SphereLight "Light1" (
8+
)
9+
{
10+
float inputs:exposure = 1
11+
}
12+
13+
def SphereLight "Light2" (
14+
)
15+
{
16+
float inputs:exposure = 2
17+
}

0 commit comments

Comments
 (0)