From f932799bc8e0579710d5df70055827fc891524b5 Mon Sep 17 00:00:00 2001 From: Goran Kocov Date: Sun, 7 Jan 2024 17:21:17 -0500 Subject: [PATCH] 3Delight : Support NSI `shaderattributes` --- Changes.md | 1 + python/IECoreDelightTest/RendererTest.py | 6 ++++++ src/IECoreDelight/Renderer.cpp | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Changes.md b/Changes.md index 743ea44b744..bb37075283c 100644 --- a/Changes.md +++ b/Changes.md @@ -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 ----- diff --git a/python/IECoreDelightTest/RendererTest.py b/python/IECoreDelightTest/RendererTest.py index de8d8407d63..d3d29996ffe 100644 --- a/python/IECoreDelightTest/RendererTest.py +++ b/python/IECoreDelightTest/RendererTest.py @@ -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 ) diff --git a/src/IECoreDelight/Renderer.cpp b/src/IECoreDelight/Renderer.cpp index 2ea8893f57f..1cd9513aa07 100644 --- a/src/IECoreDelight/Renderer.cpp +++ b/src/IECoreDelight/Renderer.cpp @@ -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( m.second.get(), "attribute", m.first ) ) + { + params.add( m.first.c_str(), d, true ); + } } else if( boost::contains( m.first.string(), ":" ) ) { @@ -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( attributes ); @@ -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; }