Skip to content

Commit 9c6fb2f

Browse files
committed
Order of crypto passes added is important. Making sure shaders have a unique name to be a part of the crypto material.
1 parent d42ed07 commit 9c6fb2f

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

src/GafferCycles/IECoreCyclesPreview/Renderer.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,6 +4403,8 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer
44034403
}
44044404
m_scene->film->cryptomatte_passes = cryptoPasses;
44054405

4406+
bool cryptoAsset, cryptoObject, cryptoMaterial = false;
4407+
44064408
for( auto &coutput : m_outputs )
44074409
{
44084410
if( coutput.second->m_passType == ccl::PASS_COMBINED )
@@ -4413,26 +4415,19 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer
44134415
{
44144416
if( coutput.second->m_data == "cryptomatte_asset" )
44154417
{
4418+
cryptoAsset = true;
44164419
m_scene->film->cryptomatte_passes = (ccl::CryptomatteType)( m_scene->film->cryptomatte_passes | ccl::CRYPT_ASSET );
44174420
}
44184421
else if( coutput.second->m_data == "cryptomatte_object" )
44194422
{
4423+
cryptoObject = true;
44204424
m_scene->film->cryptomatte_passes = (ccl::CryptomatteType)( m_scene->film->cryptomatte_passes | ccl::CRYPT_OBJECT );
44214425
}
44224426
else if( coutput.second->m_data == "cryptomatte_material" )
44234427
{
4428+
cryptoMaterial = true;
44244429
m_scene->film->cryptomatte_passes = (ccl::CryptomatteType)( m_scene->film->cryptomatte_passes | ccl::CRYPT_MATERIAL );
44254430
}
4426-
else
4427-
{
4428-
continue;
4429-
}
4430-
4431-
for( int i = 0; i < m_scene->film->cryptomatte_depth; ++i )
4432-
{
4433-
string cryptoFullName = ( boost::format( "%s%02i" ) % coutput.second->m_data % i ).str();
4434-
ccl::Pass::add( ccl::PASS_CRYPTOMATTE, m_bufferParamsModified.passes, cryptoFullName.c_str() );
4435-
}
44364431
continue;
44374432
}
44384433
else if(
@@ -4467,6 +4462,29 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer
44674462
}
44684463
}
44694464

4465+
// Order of adding these matters, hence why it was deferred to here
4466+
if( cryptoObject )
4467+
{
4468+
for( int i = 0; i < m_scene->film->cryptomatte_depth; ++i )
4469+
{
4470+
ccl::Pass::add( ccl::PASS_CRYPTOMATTE, m_bufferParamsModified.passes, ccl::string_printf("cryptomatte_object%02d", i).c_str() );
4471+
}
4472+
}
4473+
if( cryptoMaterial )
4474+
{
4475+
for( int i = 0; i < m_scene->film->cryptomatte_depth; ++i )
4476+
{
4477+
ccl::Pass::add( ccl::PASS_CRYPTOMATTE, m_bufferParamsModified.passes, ccl::string_printf("cryptomatte_material%02d", i).c_str() );
4478+
}
4479+
}
4480+
if( cryptoAsset )
4481+
{
4482+
for( int i = 0; i < m_scene->film->cryptomatte_depth; ++i )
4483+
{
4484+
ccl::Pass::add( ccl::PASS_CRYPTOMATTE, m_bufferParamsModified.passes, ccl::string_printf("cryptomatte_asset%02d", i).c_str() );
4485+
}
4486+
}
4487+
44704488
// Adaptive
44714489
if( m_sessionParams.adaptive_sampling )
44724490
{

src/GafferCycles/IECoreCyclesPreview/ShaderNetworkAlgo.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,11 @@ ccl::Shader *convert( const IECoreScene::ShaderNetwork *shaderNetwork, ccl::Shad
606606
convertWalk( shaderNetwork->getOutput(), shaderNetwork, namePrefix, shaderManager, graph, converted );
607607
}
608608
}
609-
609+
string shaderName(
610+
namePrefix +
611+
shaderNetwork->getOutput().shader.string()
612+
);
613+
result->name = ccl::ustring( shaderName.c_str() );
610614
result->set_graph( graph );
611615

612616
return result;

0 commit comments

Comments
 (0)