Skip to content

Commit

Permalink
3Delight extended outputlayer attributes support
Browse files Browse the repository at this point in the history
  • Loading branch information
gkocov committed May 5, 2024
1 parent 0a7ded2 commit 19e42c5
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 14 deletions.
56 changes: 53 additions & 3 deletions python/IECoreDelightTest/RendererTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def testOutput( self ) :
"rgba",
{
"filter" : "gaussian",
"filterwidth" : imath.V2f( 3.5 ),
"filterwidth" : 3.5,
}
)
)
Expand Down Expand Up @@ -156,7 +156,7 @@ def testAOVs( self ) :
data,
{
"filter" : "gaussian",
"filterwidth" : imath.V2f( 3.5 ),
"filterwidth" : 3.5,
}
)
)
Expand Down Expand Up @@ -1498,7 +1498,7 @@ def testOutputLayerNames( self ) :

renderer.output(
"customLayerName",
IECoreScene.Output( "customLayerName.exr", "exr", "color shader:diffuse.direct", { "layerName" : "myLayerName" } )
IECoreScene.Output( "customLayerName.exr", "exr", "color shader:diffuse.direct", { "layername" : "myLayerName" } )
)

renderer.render()
Expand All @@ -1510,6 +1510,56 @@ def testOutputLayerNames( self ) :
self.assertEqual( nsi["outputLayer:directDiffuse"]["layername"], "diffuse_direct" )
self.assertEqual( nsi["outputLayer:customLayerName"]["layername"], "myLayerName" )

def testOutputLayerAttributes( self ) :

for data, expected in {
"rgba" : {
"variablename": "Ci",
"variablesource": "shader",
"layertype": "color",
"withalpha": 1,
"filter": "gaussian",
"filterwidth": 3.5,
"scalarformat": "half",
"colorprofile": "sRGB",
"layername": "Test",
"dithering": 1
},
}.items() :

r = GafferScene.Private.IECoreScenePreview.Renderer.create(
"3Delight",
GafferScene.Private.IECoreScenePreview.Renderer.RenderType.SceneDescription,
str( self.temporaryDirectory() / "test.nsia" )
)

r.output(
"test",
IECoreScene.Output(
"beauty.exr",
"exr",
data,
{
"filter": "gaussian",
"filterwidth": 3.5,
"scalarformat": "half",
"colorprofile": "sRGB",
"layername": "Test",
"dithering": 1
}
)
)

r.render()
del r

nsi = self.__parseDict( self.temporaryDirectory() / "test.nsia" )
self.assertIn( "outputLayer:test", nsi )
self.assertEqual( nsi["outputLayer:test"]["nodeType"], "outputlayer")
for k, v in expected.items() :
self.assertIn( k, nsi["outputLayer:test"] )
self.assertEqual( nsi["outputLayer:test"][k], v )

# Helper methods used to check that NSI files we write contain what we
# expect. The 3delight API only allows values to be set, not queried,
# so we build a simple dictionary-based node graph for now.
Expand Down
26 changes: 19 additions & 7 deletions src/IECoreDelight/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ class DelightOutput : public IECore::RefCounted
ParameterList driverParams;
for( const auto &[parameterName, parameterValue] : output->parameters() )
{
// We can't pass `filter` to the driver, because although it's not
// documented as an attribute (and it _is_ documented that additional
// arbitrary attributes are allowed), 3Delight complains.
if( parameterName != "filter" )
if( parameterName != "filter" && parameterName != "filterwidth" && parameterName != "scalarformat" && parameterName != "colorprofile" && parameterName != "layername" && parameterName != "withalpha" )
{
driverParams.add( parameterName.c_str(), parameterValue.get() );
}
Expand Down Expand Up @@ -371,7 +368,7 @@ class DelightOutput : public IECore::RefCounted
scalarFormat = "float";
}

layerName = parameter<string>( output->parameters(), "layerName", layerName );
layerName = parameter<string>( output->parameters(), "layername", layerName );

ParameterList layerParams;

Expand All @@ -381,7 +378,8 @@ class DelightOutput : public IECore::RefCounted
layerParams.add( "layername", layerName );
layerParams.add( { "withalpha", &withAlpha, NSITypeInteger, 0, 1, 0 } );

string colorProfile = "linear";
scalarFormat = parameter<string>( output->parameters(), "scalarformat", scalarFormat );
string colorProfile = parameter<string>( output->parameters(), "colorprofile", "linear" );
if( scalarFormat.empty() )
{
scalarFormat = this->scalarFormat( output );
Expand All @@ -397,6 +395,20 @@ class DelightOutput : public IECore::RefCounted
}
layerParams.add( "filter", filter );

const double filterWidth = parameter<float>( output->parameters(), "filterwidth", 3.0 );
if( filterWidth != 3.0 )
{
layerParams.add( { "filterwidth", &filterWidth, NSITypeDouble, 0, 1, 0 } );
}

for( const auto &[parameterName, parameterValue] : output->parameters() )
{
if( parameterName != "filter" && parameterName != "filterwidth" && parameterName != "scalarformat" && parameterName != "colorprofile" && parameterName != "layername" )
{
layerParams.add( parameterName.c_str(), parameterValue.get() );
}
}

m_layerHandle = DelightHandle( context, "outputLayer:" + name, ownership, "outputlayer", layerParams );

NSIConnect(
Expand Down Expand Up @@ -425,7 +437,7 @@ class DelightOutput : public IECore::RefCounted
{
return "uint8";
}
else if( quantize == vector<int>( { 0, 65536, 0, 65536 } ) )
else if( quantize == vector<int>( { 0, 65535, 0, 65535 } ) )
{
return "uint16";
}
Expand Down
28 changes: 24 additions & 4 deletions startup/gui/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
# See `contrib/scripts/3delightOutputs.py` in this repository for a helper script.

for name, displayName, source, dataType in [
( "rgba", "Beauty", "", "" ),
( "Ci", "Ci", "shader", "color" ),
( "Ci.direct", "Ci (direct)", "shader", "color" ),
( "Ci.indirect", "Ci (indirect)", "shader", "color" ),
Expand Down Expand Up @@ -225,27 +226,46 @@
( "motionvector", "Motion Vector", "builtin", "point" ),
( "occlusion", "Ambient Occlusion", "shader", "color" ),
] :
if name == "rgba" :
space = ""
separator = ""
slash = ""
else :
space = " "
separator = ":"
slash ="/"

GafferScene.Outputs.registerOutput(
"Interactive/3Delight/{}/{}".format( source.capitalize(), displayName ),
"Interactive/3Delight/{}{}{}".format( source.capitalize(), slash, displayName ),
IECoreScene.Output(
name,
"ieDisplay",
"{} {}:{}".format( dataType, source, name ),
"{}{}{}{}{}".format( dataType, space, source, separator, name ),
{
"driverType" : "ClientDisplayDriver",
"displayHost" : "localhost",
"displayPort" : "${image:catalogue:port}",
"remoteDisplayType" : "GafferImage::GafferDisplayDriver",
"scalarformat" : "half",
"colorprofile" : "linear",
"filter" : "blackman-harris",
"filterwidth" : 3.0,
}
)
)

GafferScene.Outputs.registerOutput(
"Batch/3Delight/{}/{}".format( source.capitalize(), displayName ),
"Batch/3Delight/{}{}{}".format( source.capitalize(), slash, displayName ),
IECoreScene.Output(
"${project:rootDirectory}/renders/${script:name}/${renderPass}/%s/%s.####.exr" % ( name, name ),
"exr",
"{} {}:{}".format( dataType, source, name ),
"{}{}{}{}{}".format( dataType, space, source, separator, name ),
{
"scalarformat" : "half",
"colorprofile" : "linear",
"filter" : "blackman-harris",
"filterwidth" : 3.0,
}
)
)

Expand Down

0 comments on commit 19e42c5

Please sign in to comment.