Skip to content

Commit

Permalink
Merge pull request GafferHQ#5615 from gkocov/3dl_shaderattributes
Browse files Browse the repository at this point in the history
3Delight NSI shaderattributes support
  • Loading branch information
johnhaddon authored Jan 16, 2024
2 parents b90c4b1 + f932799 commit df92b37
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Improvements
- 3Delight :
- Added camera overscan support.
- NSI scene description export format is now based on file extension - `.nsi` for binary and `.nsia` for ASCII.
- Added support for reading `dl:` and `user:` attributes from shaders.

Fixes
-----
Expand Down
6 changes: 6 additions & 0 deletions python/IECoreDelightTest/RendererTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,13 +731,19 @@ def testShaderAttributes( self ) :
self.assertEqual( len( allAttributes ), 1 )
attributes = allAttributes[next( iter( allAttributes ) )]

allTransforms = { k: v for k, v in nsi.items() if nsi[k]["nodeType"] == "transform" }
self.assertEqual( len( allTransforms ), 1 )
transforms = allTransforms[next( iter( allTransforms ) )]

self.assertIn( "surfaceshader", attributes )
self.assertIn( "volumeshader", attributes )
self.assertIn( "displacementshader", attributes )
self.assertIn( "shaderattributes", transforms )

self.assertGreater( len( attributes["surfaceshader"] ), 0 )
self.assertGreater( len( attributes["volumeshader"] ), 0 )
self.assertGreater( len( attributes["displacementshader"] ), 0 )
self.assertGreater( len( transforms["shaderattributes"] ), 0 )

surfaceShader = self.__connectionSource( attributes["surfaceshader"][0], nsi )
volumeShader = self.__connectionSource( attributes["volumeshader"][0], nsi )
Expand Down
18 changes: 17 additions & 1 deletion src/IECoreDelight/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,10 @@ class DelightAttributes : public IECoreScenePreview::Renderer::AttributesInterfa
}
else if( boost::starts_with( m.first.string(), "user:" ) )
{
msg( Msg::Warning, "DelightRenderer", fmt::format( "User attribute \"{}\" not supported", m.first.string() ) );
if( const Data *d = reportedCast<const IECore::Data>( m.second.get(), "attribute", m.first ) )
{
params.add( m.first.c_str(), d, true );
}
}
else if( boost::contains( m.first.string(), ":" ) )
{
Expand Down Expand Up @@ -992,6 +995,11 @@ class DelightObject : public IECoreScenePreview::Renderer::ObjectInterface
m_attributes->handle().name(), "",
m_transformHandle.name(), "geometryattributes"
);
NSIDisconnect(
m_transformHandle.context(),
m_attributes->handle().name(), "",
m_transformHandle.name(), "shaderattributes"
);
}

m_attributes = static_cast<const DelightAttributes *>( attributes );
Expand All @@ -1002,6 +1010,14 @@ class DelightObject : public IECoreScenePreview::Renderer::ObjectInterface
0, nullptr

);
NSIConnect(
m_transformHandle.context(),
m_attributes->handle().name(), "",
m_transformHandle.name(), "shaderattributes",
0, nullptr

);

return true;
}

Expand Down

0 comments on commit df92b37

Please sign in to comment.