Skip to content

Commit

Permalink
Order of crypto passes added is important. Making sure shaders have a…
Browse files Browse the repository at this point in the history
… unique name to be a part of the crypto material.
  • Loading branch information
boberfly committed May 31, 2020
1 parent d42ed07 commit 9c6fb2f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
38 changes: 28 additions & 10 deletions src/GafferCycles/IECoreCyclesPreview/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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(
Expand Down Expand Up @@ -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 )
{
Expand Down
6 changes: 5 additions & 1 deletion src/GafferCycles/IECoreCyclesPreview/ShaderNetworkAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9c6fb2f

Please sign in to comment.