From b7ce3a4ff931b0dc58e0d79d2d9bbdc241b3a1ff Mon Sep 17 00:00:00 2001 From: Murray Stevenson <50844517+murraystevenson@users.noreply.github.com> Date: Fri, 19 Apr 2024 13:07:34 -0700 Subject: [PATCH] 3Delight ShaderNetworkAlgo : Initial support for translating colorspace `{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. --- python/IECoreDelightTest/ShaderNetworkAlgoTest.py | 3 +++ shaders/__usd/__usdUVTexture.osl | 1 + src/IECoreDelight/ShaderNetworkAlgo.cpp | 3 +++ 3 files changed, 7 insertions(+) diff --git a/python/IECoreDelightTest/ShaderNetworkAlgoTest.py b/python/IECoreDelightTest/ShaderNetworkAlgoTest.py index 01e7a368ff7..bac4cdbb855 100644 --- a/python/IECoreDelightTest/ShaderNetworkAlgoTest.py +++ b/python/IECoreDelightTest/ShaderNetworkAlgoTest.py @@ -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 ) : @@ -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 ) : @@ -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" ) diff --git a/shaders/__usd/__usdUVTexture.osl b/shaders/__usd/__usdUVTexture.osl index 1924d2cefeb..22aeeb4fffc 100644 --- a/shaders/__usd/__usdUVTexture.osl +++ b/shaders/__usd/__usdUVTexture.osl @@ -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", diff --git a/src/IECoreDelight/ShaderNetworkAlgo.cpp b/src/IECoreDelight/ShaderNetworkAlgo.cpp index f208044a367..275646a4742 100644 --- a/src/IECoreDelight/ShaderNetworkAlgo.cpp +++ b/src/IECoreDelight/ShaderNetworkAlgo.cpp @@ -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" ); @@ -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" ); @@ -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 ) );