From 9c6fb2f3c770fb5bc2ba5b2c018f88aed40f1a8a Mon Sep 17 00:00:00 2001 From: Alex Fuller Date: Sun, 31 May 2020 00:00:20 -0700 Subject: [PATCH] Order of crypto passes added is important. Making sure shaders have a unique name to be a part of the crypto material. --- .../IECoreCyclesPreview/Renderer.cpp | 38 ++++++++++++++----- .../IECoreCyclesPreview/ShaderNetworkAlgo.cpp | 6 ++- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/GafferCycles/IECoreCyclesPreview/Renderer.cpp b/src/GafferCycles/IECoreCyclesPreview/Renderer.cpp index 7bfa5cb..b358a7c 100644 --- a/src/GafferCycles/IECoreCyclesPreview/Renderer.cpp +++ b/src/GafferCycles/IECoreCyclesPreview/Renderer.cpp @@ -4403,6 +4403,8 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer } m_scene->film->cryptomatte_passes = cryptoPasses; + bool cryptoAsset, cryptoObject, cryptoMaterial = false; + for( auto &coutput : m_outputs ) { if( coutput.second->m_passType == ccl::PASS_COMBINED ) @@ -4413,26 +4415,19 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer { if( coutput.second->m_data == "cryptomatte_asset" ) { + cryptoAsset = true; m_scene->film->cryptomatte_passes = (ccl::CryptomatteType)( m_scene->film->cryptomatte_passes | ccl::CRYPT_ASSET ); } else if( coutput.second->m_data == "cryptomatte_object" ) { + cryptoObject = true; m_scene->film->cryptomatte_passes = (ccl::CryptomatteType)( m_scene->film->cryptomatte_passes | ccl::CRYPT_OBJECT ); } else if( coutput.second->m_data == "cryptomatte_material" ) { + cryptoMaterial = true; m_scene->film->cryptomatte_passes = (ccl::CryptomatteType)( m_scene->film->cryptomatte_passes | ccl::CRYPT_MATERIAL ); } - else - { - continue; - } - - for( int i = 0; i < m_scene->film->cryptomatte_depth; ++i ) - { - string cryptoFullName = ( boost::format( "%s%02i" ) % coutput.second->m_data % i ).str(); - ccl::Pass::add( ccl::PASS_CRYPTOMATTE, m_bufferParamsModified.passes, cryptoFullName.c_str() ); - } continue; } else if( @@ -4467,6 +4462,29 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer } } + // Order of adding these matters, hence why it was deferred to here + if( cryptoObject ) + { + for( int i = 0; i < m_scene->film->cryptomatte_depth; ++i ) + { + ccl::Pass::add( ccl::PASS_CRYPTOMATTE, m_bufferParamsModified.passes, ccl::string_printf("cryptomatte_object%02d", i).c_str() ); + } + } + if( cryptoMaterial ) + { + for( int i = 0; i < m_scene->film->cryptomatte_depth; ++i ) + { + ccl::Pass::add( ccl::PASS_CRYPTOMATTE, m_bufferParamsModified.passes, ccl::string_printf("cryptomatte_material%02d", i).c_str() ); + } + } + if( cryptoAsset ) + { + for( int i = 0; i < m_scene->film->cryptomatte_depth; ++i ) + { + ccl::Pass::add( ccl::PASS_CRYPTOMATTE, m_bufferParamsModified.passes, ccl::string_printf("cryptomatte_asset%02d", i).c_str() ); + } + } + // Adaptive if( m_sessionParams.adaptive_sampling ) { diff --git a/src/GafferCycles/IECoreCyclesPreview/ShaderNetworkAlgo.cpp b/src/GafferCycles/IECoreCyclesPreview/ShaderNetworkAlgo.cpp index 0dd2b47..ec1b576 100644 --- a/src/GafferCycles/IECoreCyclesPreview/ShaderNetworkAlgo.cpp +++ b/src/GafferCycles/IECoreCyclesPreview/ShaderNetworkAlgo.cpp @@ -606,7 +606,11 @@ ccl::Shader *convert( const IECoreScene::ShaderNetwork *shaderNetwork, ccl::Shad convertWalk( shaderNetwork->getOutput(), shaderNetwork, namePrefix, shaderManager, graph, converted ); } } - + string shaderName( + namePrefix + + shaderNetwork->getOutput().shader.string() + ); + result->name = ccl::ustring( shaderName.c_str() ); result->set_graph( graph ); return result;