Skip to content

Commit 5e2d470

Browse files
Alex Fullerboberfly
authored andcommitted
IECoreUSD::ShaderAlgo : Round-trip ColorSpace data on shader parameters.
1 parent 88b5af7 commit 5e2d470

File tree

4 files changed

+54
-91
lines changed

4 files changed

+54
-91
lines changed

Changes

Lines changed: 5 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
10.6.x.x (relative to 10.6.0.1)
22
========
33

4+
Features
5+
--------
6+
7+
- IECoreUSD::ShaderAlgo : Round-trip ColorSpace data that is stored on USD Attributes by storing an additional parameter with the `_colorspace` suffix.
8+
49
API
510
---
611

@@ -52,94 +57,6 @@ Breaking Changes
5257
- SmoothSkinningData : Removed, along with all associated Ops and Parameters.
5358

5459
10.5.x.x (relative to 10.5.15.4)
55-
=======
56-
57-
58-
59-
10.5.15.4 (relative to 10.5.15.3)
60-
========
61-
62-
Improvements
63-
-----
64-
65-
- IECoreUSD: Added support for root level tags (reading/writing) to our IECoreUSD::SceneCacheData plugin.
66-
67-
Fixes
68-
-----
69-
70-
- IECoreUSD: Fixed crash when using invalid file path with IECoreUSD::SceneCacheFileFormat.
71-
72-
10.5.15.3 (relative to 10.5.15.2)
73-
=========
74-
75-
Fixes
76-
-----
77-
78-
- USDScene : Worked around numerical imprecision when converting between time and UsdTimeCode.
79-
80-
10.5.15.2 (relative to 10.5.15.1)
81-
=========
82-
83-
Fixes
84-
-----
85-
86-
- VDBObject : Fixed worldBound() result when bbox metadata not already present.
87-
88-
API
89-
---
90-
91-
- SConstruct : Install "private" headers.
92-
- VDBObject : Marked metadata() as deprecated.
93-
94-
10.5.15.1 (relative to 10.5.15.0)
95-
=========
96-
97-
Fixes
98-
-----
99-
100-
- USDScene : Fixed reading of bounds from prims with `extentsHint` and model `kind` but without UsdGeomModelAPI applied.
101-
102-
10.5.15.0 (relative to 10.5.14.1)
103-
=========
104-
105-
Improvements
106-
------------
107-
108-
- USDScene : Added loading of ArnoldAlembic, ArnoldUsd and ArnoldProceduralCustom prims as Cortex ExternalProcedural objects.
109-
110-
Fixes
111-
-----
112-
113-
- USDScene : Fixed loading of instanced UsdSkel geometry with unique animation applied.
114-
115-
10.5.14.1 (relative to 10.5.14.0)
116-
=========
117-
118-
Fixes
119-
-----
120-
121-
- Boost : Fixed compatibility with Boost 1.82.
122-
123-
10.5.14.0 (relative to 10.5.13.1)
124-
=========
125-
126-
Features
127-
--------
128-
129-
- ObjectMatrix : Added new class providing an object that holds a matrix of child objects.
130-
131-
Fixes
132-
-----
133-
134-
- Alembic : Fixed crashes caused by invalid UVs.
135-
136-
10.5.13.1 (relative to 10.5.13.0)
137-
=========
138-
139-
Fixes
140-
-----
141-
142-
- USD : Fixed compatibility with USD 25.05.
14360

14461
10.5.13.0 (relative to 10.5.12.0)
14562
=========

contrib/IECoreUSD/src/IECoreUSD/ShaderAlgo.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ IECore::InternedString readShaderNetworkWalk( const pxr::SdfPath &anchorPath, co
244244
if( IECore::DataPtr d = IECoreUSD::DataAlgo::fromUSD( pxr::UsdAttribute( valueAttribute ) ) )
245245
{
246246
parameters[fromUSDParameterName( i.GetBaseName() )] = d;
247+
// If there's colorspace data on the parameter, we can store this as
248+
// `<name>_colorspace`, this is how MaterialX stores colorspace on
249+
// generated OSL nodes so we match here the same behaviour.
250+
if( pxr::UsdAttribute( valueAttribute ).HasColorSpace() )
251+
{
252+
const IECore::InternedString colorSpace( pxr::UsdAttribute( valueAttribute ).GetColorSpace().GetString() );
253+
const IECore::InternedString paramName(
254+
( boost::format( "%s_colorspace" ) % fromUSDParameterName( i.GetBaseName() ).string() ).str() );
255+
parameters[paramName] = new IECore::InternedStringData( colorSpace );
256+
}
247257
}
248258
}
249259

@@ -334,6 +344,13 @@ void writeShaderParameterValues( const IECoreScene::Shader *shader, pxr::UsdShad
334344
continue;
335345
}
336346

347+
// Skip colorspace parameters, these will be set using SetColorSpace() on the
348+
// USD attribue that it corresponds to.
349+
if( boost::ends_with( p.first.string(), "_colorspace" ) )
350+
{
351+
continue;
352+
}
353+
337354
const pxr::TfToken usdParameterName = toUSDParameterName( p.first );
338355
pxr::UsdShadeInput input = usdShader.GetInput( usdParameterName );
339356
if( !input )
@@ -364,6 +381,17 @@ void writeShaderParameterValues( const IECoreScene::Shader *shader, pxr::UsdShad
364381
}
365382
}
366383
input.Set( IECoreUSD::DataAlgo::toUSD( p.second.get() ) );
384+
385+
// Make sure to set any colorspace parameters onto the attribute
386+
// if any exist.
387+
auto it = shader->parameters().find( ( boost::format( "%s_colorspace" ) % p.first.string() ).str() );
388+
if( it != shader->parameters().end() )
389+
{
390+
if( auto *s = IECore::runTimeCast<IECore::InternedStringData>( it->second.get() ) )
391+
{
392+
pxr::UsdAttribute( input ).SetColorSpace( pxr::TfToken( s->readable().string() ) );
393+
}
394+
}
367395
}
368396

369397
if( shader->blindData()->readable().size() )

contrib/IECoreUSD/test/IECoreUSD/USDSceneTest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2932,6 +2932,7 @@ def testShaders( self ) :
29322932

29332933
texture = IECoreScene.Shader( "texture", "ai:shader" )
29342934
texture.parameters["filename"] = IECore.StringData( "sometexture.tx" )
2935+
texture.parameters["filename_colorspace"] = IECore.InternedStringData( "ACEScg" )
29352936

29362937
oneShaderNetwork = IECoreScene.ShaderNetwork()
29372938
oneShaderNetwork.addShader( "foo", surface )
@@ -3119,6 +3120,8 @@ def testShaders( self ) :
31193120
textureUsd = pxr.UsdShade.Shader( add1Source[0].GetPrim() )
31203121
self.assertEqual( textureUsd.GetShaderId(), "arnold:texture" )
31213122
self.assertEqual( textureUsd.GetInput( "filename" ).Get(), "sometexture.tx" )
3123+
self.assertEqual( add1Source[0].GetPrim().GetAttribute( "inputs:filename" ).GetColorSpace(), "ACEScg" )
3124+
self.assertEqual( add1Source[0].GetPrim().HasAttribute( "inputs:filename_colorspace" ), False )
31223125

31233126

31243127
# Read via SceneInterface, and check that we've round-tripped successfully.
@@ -3395,6 +3398,15 @@ def testTextureParameters( self ) :
33953398
os.path.normcase( os.path.normpath( network.getShader( "udimTexture" ).parameters["file"].value ) ),
33963399
os.path.normcase( os.path.normpath( "/full/path/to/myTexture.<UDIM>.tx" ) )
33973400
)
3401+
self.assertEqual(
3402+
network.getShader( "relativeTexture" ).parameters["file_colorspace"].value, "ACEScg"
3403+
)
3404+
self.assertEqual(
3405+
network.getShader( "relativeUDIMTexture" ).parameters["file_colorspace"].value, "lin_rec709_scene"
3406+
)
3407+
self.assertEqual(
3408+
network.getShader( "udimTexture" ).parameters["file_colorspace"].value, "srgb_rec709_scene"
3409+
)
33983410

33993411
def testExposedShaderInput( self ) :
34003412

contrib/IECoreUSD/test/IECoreUSD/data/textureParameters.usda

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,28 @@ def "model"
2929
def Shader "relativeTexture"
3030
{
3131
uniform token info:id = "UsdUVTexture"
32-
asset inputs:file = @../myTexture.tx@
32+
asset inputs:file = @../myTexture.tx@ (
33+
colorSpace = "ACEScg"
34+
)
3335
vector3f outputs:rgb
3436
}
3537

3638
def Shader "relativeUDIMTexture"
3739
{
3840
uniform token info:id = "UsdUVTexture"
39-
asset inputs:file = @../myTexture.<UDIM>.tx@
41+
asset inputs:file = @../myTexture.<UDIM>.tx@ (
42+
colorSpace = "lin_rec709_scene"
43+
)
4044
vector3f outputs:rgb
4145

4246
}
4347

4448
def Shader "udimTexture"
4549
{
4650
uniform token info:id = "UsdUVTexture"
47-
asset inputs:file = @/full/path/to/myTexture.<UDIM>.tx@
51+
asset inputs:file = @/full/path/to/myTexture.<UDIM>.tx@ (
52+
colorSpace = "srgb_rec709_scene"
53+
)
4854
float outputs:r
4955
}
5056
}

0 commit comments

Comments
 (0)