Skip to content

Commit

Permalink
fixup! 3Delight ShaderNetworkAlgo : Translate UsdPreviewSurface to 3D…
Browse files Browse the repository at this point in the history
…elight

Fix opacity cutoff
  • Loading branch information
murraystevenson committed Apr 26, 2024
1 parent 39f0c2e commit 95db579
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions python/IECoreDelightTest/ShaderNetworkAlgoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ def testConvertUSDOpacity( self ) :
#
# https://github.com/usd-wg/assets/tree/main/test_assets/AlphaBlendModeTest
#
# > Note : the leftmost texture is incorrect, because USD expects the texture
# > (which has unpremultiplied alpha) to be loaded unmodified, but OIIO/Cycles
# > appear to premultiply it during loading.
# > Note : the "cutoff" positions are incorrect, because 3Delight's colorspace
# > transformation of the sRGB PNG textures also affects their alpha channel.
# > Loading these textures with `sourceColorSpace`=`raw` results in the correct
# > cutoff positions.

for opacity in ( 0.25, 1.0, None ) :
for opacityThreshold in ( 0.0, 0.5, None ) :
Expand Down Expand Up @@ -184,7 +185,7 @@ def testConvertUSDOpacity( self ) :
)
for c in "XYZ" :
multiplyInput = convertedNetwork.input( ( "previewSurfaceOpacityMultiply", "input2{}".format( c ) ) )
self.assertEqual( multiplyInput, "previewSurfaceOpacityCompare" )
self.assertEqual( multiplyInput, ( "previewSurfaceOpacityCompare", "success" ) )

self.assertEqual(
convertedNetwork.input( ( "previewSurfaceOpacityCompare", "a" ) ),
Expand Down
7 changes: 4 additions & 3 deletions src/IECoreDelight/ShaderNetworkAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ const InternedString g_specularColorDelightParameter( "specular_color" );
const InternedString g_specularIORParameter( "specular_IOR" );
const InternedString g_specularRoughnessParameter( "specular_roughness" );
const InternedString g_stParameter( "st" );
const InternedString g_successParameter( "success" );
const InternedString g_textureFileParameter( "texture:file" );
const InternedString g_textureFormatParameter( "texture:format" );
const InternedString g_textureOutputParameter( "outColor" );
Expand Down Expand Up @@ -845,9 +846,9 @@ void convertUSDShaders( ShaderNetwork *shaderNetwork )
ShaderPtr multiplyShader = new Shader( "multiplyDivide" );
const InternedString multiplyHandle = shaderNetwork->addShader( handle.string() + "OpacityMultiply", std::move( multiplyShader ) );
shaderNetwork->addConnection( ShaderNetwork::Connection( opacityInput, { multiplyHandle, g_input1Parameter } ) );
shaderNetwork->addConnection( ShaderNetwork::Connection( compareHandle, { multiplyHandle, g_input2XParameter } ) );
shaderNetwork->addConnection( ShaderNetwork::Connection( compareHandle, { multiplyHandle, g_input2YParameter } ) );
shaderNetwork->addConnection( ShaderNetwork::Connection( compareHandle, { multiplyHandle, g_input2ZParameter } ) );
shaderNetwork->addConnection( ShaderNetwork::Connection( { compareHandle, g_successParameter }, { multiplyHandle, g_input2XParameter } ) );
shaderNetwork->addConnection( ShaderNetwork::Connection( { compareHandle, g_successParameter }, { multiplyHandle, g_input2YParameter } ) );
shaderNetwork->addConnection( ShaderNetwork::Connection( { compareHandle, g_successParameter }, { multiplyHandle, g_input2ZParameter } ) );
shaderNetwork->removeConnection( ShaderNetwork::Connection( opacityInput, { handle, g_opacityParameter } ) );
shaderNetwork->addConnection( ShaderNetwork::Connection( { multiplyHandle, g_oOutputParameter }, { handle, g_opacityParameter } ) );
}
Expand Down

0 comments on commit 95db579

Please sign in to comment.