Skip to content

Commit

Permalink
3Delight ShaderNetworkAlgo : Initial support for translating colorspace
Browse files Browse the repository at this point in the history
`{param}_meta_colorspace` is a 3Delight convention for declaring the input colorspace of the texture at `{param}`.

From the 3Delight docs:

In NSI `textureName.meta.colorspace` indicates the color space for the texture designated by `textureName`. Any available OCIO color space can be used. The following presets are recognised: linear, rec.709, sRGB.
  • Loading branch information
murraystevenson authored and johnhaddon committed Apr 30, 2024
1 parent 05939bf commit b7ce3a4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/IECoreDelightTest/ShaderNetworkAlgoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def testConvertSimpleUSDUVTexture( self ) :
self.assertEqual( texture.parameters["file"].value, "test.png" )
self.assertEqual( texture.parameters["wrapS"].value, "useMetadata" )
self.assertEqual( texture.parameters["wrapT"].value, "repeat" )
self.assertEqual( texture.parameters["file_meta_colorspace"].value, "auto" )

def testConvertSimpleUSDNormalTexture( self ) :

Expand Down Expand Up @@ -391,6 +392,7 @@ def testConvertSimpleUSDNormalTexture( self ) :
self.assertEqual( texture.parameters["file"].value, "test.png" )
self.assertEqual( texture.parameters["wrapS"].value, "useMetadata" )
self.assertEqual( texture.parameters["wrapT"].value, "repeat" )
self.assertEqual( texture.parameters["file_meta_colorspace"].value, "raw" )

def testConvertTransformedUSDUVTexture( self ) :

Expand Down Expand Up @@ -440,6 +442,7 @@ def testConvertTransformedUSDUVTexture( self ) :
self.assertEqual( texture.parameters["file"].value, "test.png" )
self.assertEqual( texture.parameters["wrapS"].value, "repeat" )
self.assertEqual( texture.parameters["wrapT"].value, "repeat" )
self.assertEqual( texture.parameters["file_meta_colorspace"].value, "auto" )

uvReader = convertedNetwork.getShader( "uvReader" )
self.assertEqual( uvReader.name, "dlPrimitiveAttribute" )
Expand Down
1 change: 1 addition & 0 deletions shaders/__usd/__usdUVTexture.osl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ string convertWrap( string wrap )
shader __usdUVTexture
(
string file = "",
string file_meta_colorspace = "",
float uvCoord[2] = {0, 0},
string wrapS = "default",
string wrapT = "default",
Expand Down
3 changes: 3 additions & 0 deletions src/IECoreDelight/ShaderNetworkAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ const InternedString g_exposureParameter( "exposure" );
const InternedString g_fallbackParameter( "fallback" );
const InternedString g_fallbackValueParameter( "fallback_value" );
const InternedString g_fileParameter( "file" );
const InternedString g_fileMetaColorSpaceParameter( "file_meta_colorspace" );
const InternedString g_gParameter( "g" );
const InternedString g_heightParameter( "height" );
const InternedString g_inParameter( "in" );
Expand Down Expand Up @@ -462,6 +463,7 @@ const InternedString g_roughnessParameter( "roughness" );
const InternedString g_scaleParameter( "scale" );
const InternedString g_shapingConeAngleParameter( "shaping:cone:angle" );
const InternedString g_shapingConeSoftnessParameter( "shaping:cone:softness" );
const InternedString g_sourceColorSpaceParameter( "sourceColorSpace" );
const InternedString g_specularParameter( "specular" );
const InternedString g_specularColorParameter( "specularColor" );
const InternedString g_specularColorDelightParameter( "specular_color" );
Expand Down Expand Up @@ -750,6 +752,7 @@ void convertUSDUVTextures( ShaderNetwork *network )

ShaderPtr imageShader = new Shader( "__usd/__usdUVTexture", "osl:shader" );
transferUSDParameter( network, handle, shader.get(), g_fileParameter, imageShader.get(), g_fileParameter, std::string() );
transferUSDParameter( network, handle, shader.get(), g_sourceColorSpaceParameter, imageShader.get(), g_fileMetaColorSpaceParameter, std::string( "auto" ) );

transferUSDParameter( network, handle, shader.get(), g_fallbackParameter, imageShader.get(), g_fallbackParameter, Color4f( 0, 0, 0, 1 ) );
transferUSDParameter( network, handle, shader.get(), g_scaleParameter, imageShader.get(), g_scaleParameter, Color4f( 1 ) );
Expand Down

0 comments on commit b7ce3a4

Please sign in to comment.