Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GafferCycles : Custom AOV fix + unit test #5044

Merged
merged 3 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
1.1.x.x (relative to 1.1.6.1)
=======

Fixes
-----

- Cycles :
- Fixed custom AOVs not being created properly for SVM shading mode only, OSL is not supported. (#5044).

1.1.6.1 (relative to 1.1.6.0)
=======

Expand Down
115 changes: 113 additions & 2 deletions python/GafferCyclesTest/IECoreCyclesPreviewTest/RendererTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,15 +1130,19 @@ def testShaderSubstitutions( self ) :
self.assertEqual( self.__colorAtUV( image, imath.V2f( 0.48, 0.5 ) ), imath.Color4f( 1, 0, 0, 1 ) )
self.assertEqual( self.__colorAtUV( image, imath.V2f( 0.52, 0.5 ) ), imath.Color4f( 0, 1, 0, 1 ) )

def __colorAtUV( self, image, uv ) :
def __colorAtUV( self, image, uv, channelName = "" ) :

dimensions = image.dataWindow.size() + imath.V2i( 1 )

ix = int( uv.x * ( dimensions.x - 1 ) )
iy = int( uv.y * ( dimensions.y - 1 ) )
i = iy * dimensions.x + ix

return imath.Color4f( image["R"][i], image["G"][i], image["B"][i], image["A"][i] )
c = channelName
if c != "":
c = "%s." % channelName

return imath.Color4f( image[c+"R"][i], image[c+"G"][i], image[c+"B"][i], image[c+"A"][i] )

def __testCustomAttributeType( self, primitive, prefix, customAttribute, outputPlug, data, expectedResult, maxDifference = 0.0 ) :

Expand Down Expand Up @@ -1429,5 +1433,112 @@ def testSurfaceAttributeWithGenericShaderType( self ) :

del plane

def __valueAtUV( self, image, uv, channelName ) :

dimensions = image.dataWindow.size() + imath.V2i( 1 )

ix = int( uv.x * ( dimensions.x - 1 ) )
iy = int( uv.y * ( dimensions.y - 1 ) )
i = iy * dimensions.x + ix

return image[channelName][i]

def testCustomAOV( self ) :

renderer = GafferScene.Private.IECoreScenePreview.Renderer.create(
"Cycles",
GafferScene.Private.IECoreScenePreview.Renderer.RenderType.Interactive,
)

# Custom AOVs are currently not supported in OSL mode.
# See https://developer.blender.org/T73266 for further updates
# for when OSL will eventually support custom AOVs.
renderer.option( "cycles:shadingsystem", IECore.StringData( "SVM" ) )

renderer.output(
"testValueOutput",
IECoreScene.Output(
"testValue",
"ieDisplay",
"float myValueAOV",
{
"driverType" : "ImageDisplayDriver",
"handle" : "testCustomValueAOV",
}
)
)

renderer.output(
"testColorOutput",
IECoreScene.Output(
"testColor",
"ieDisplay",
"color myColorAOV",
{
"driverType" : "ImageDisplayDriver",
"handle" : "testCustomColorAOV",
}
)
)

plane = renderer.object(
"/plane",
IECoreScene.MeshPrimitive.createPlane(
imath.Box2f( imath.V2f( -1 ), imath.V2f( 1 ) ),
),
renderer.attributes( IECore.CompoundObject ( {
"cycles:surface" : IECoreScene.ShaderNetwork(
shaders = {
"output" : IECoreScene.Shader(
"principled_bsdf", "cycles:shader",
),
},
output = "output",
),
"cycles:aov:myValueAOV" : IECoreScene.ShaderNetwork(
shaders = {
"aov_value" : IECoreScene.Shader(
"aov_output", "cycles:shader",
{ "name" : "myValueAOV", "value" : 0.5 }
),
},
output = "aov_value",
),
"cycles:aov:myColorAOV" : IECoreScene.ShaderNetwork(
shaders = {
"aov_color" : IECoreScene.Shader(
"aov_output", "cycles:shader",
{ "name" : "myColorAOV", "color" : imath.Color3f( 1, 0, 1 ) }
),
},
output = "aov_color",
)
} ) )
)
## \todo Default camera is facing down +ve Z but should be facing
# down -ve Z.
plane.transform( imath.M44f().translate( imath.V3f( 0, 0, 1 ) ) )

renderer.render()
time.sleep( 2 )

image = IECoreImage.ImageDisplayDriver.storedImage( "testCustomValueAOV" )
self.assertIsInstance( image, IECoreImage.ImagePrimitive )

# Slightly off-centre, to avoid triangle edge artifact in centre of image.
testPixel = self.__valueAtUV( image, imath.V2f( 0.55 ), "myValueAOV" )
self.assertEqual( testPixel, 0.5 )

image = IECoreImage.ImageDisplayDriver.storedImage( "testCustomColorAOV" )
self.assertIsInstance( image, IECoreImage.ImagePrimitive )

# Slightly off-centre, to avoid triangle edge artifact in centre of image.
testPixel = self.__colorAtUV( image, imath.V2f( 0.55 ), "myColorAOV" )
self.assertEqual( testPixel.r, 1 )
self.assertEqual( testPixel.g, 0 )
self.assertEqual( testPixel.b, 1 )

del plane

if __name__ == "__main__":
unittest.main()
36 changes: 18 additions & 18 deletions src/GafferCycles/IECoreCyclesPreview/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,32 @@ class CyclesOutput : public IECore::RefCounted
}
else if( tokens.size() == 2 )
{
if( tokens[0] == "aovv" )
if( tokens[0] == "float" && tokens[1] == "Z" )
{
m_data = tokens[1];
p["name"] = new StringData( tokens[1] );
p["type"] = new StringData( "depth" );
passType = "depth";
}
else if( tokens[0] == "uint" && tokens[1] == "id" )
{
m_data = tokens[1];
p["name"] = new StringData( tokens[1] );
p["type"] = new StringData( "object_id" );
passType = "object_id";
}
else if( tokens[0] == "float" )
{
p["name"] = m_denoise ? new StringData( ccl::string_printf( "%s_denoised", tokens[1].c_str() ) ) : new StringData( tokens[1] );
p["type"] = new StringData( "aov_value" );
passType = tokens[1];
passType = "aov_value";
m_data = tokens[1];
}
else if( tokens[0] == "aovc" )
else if( tokens[0] == "color" )
{
p["name"] = m_denoise ? new StringData( ccl::string_printf( "%s_denoised", tokens[1].c_str() ) ) : new StringData( tokens[1] );
p["type"] = new StringData( "aov_color" );
passType = tokens[1];
passType = "aov_color";
m_data = tokens[1];
}
else if( tokens[0] == "lg" )
Expand All @@ -357,20 +371,6 @@ class CyclesOutput : public IECore::RefCounted
p["type"] = new StringData( tokens[0] );
passType = tokens[0];
}
else if( tokens[0] == "float" && tokens[1] == "Z" )
{
m_data = tokens[1];
p["name"] = new StringData( tokens[1] );
p["type"] = new StringData( "depth" );
passType = "depth";
}
else if( tokens[0] == "uint" && tokens[1] == "id" )
{
m_data = tokens[1];
p["name"] = new StringData( tokens[1] );
p["type"] = new StringData( "object_id" );
passType = "object_id";
}
}

if( typeEnum.exists( passType ) )
Expand Down
4 changes: 2 additions & 2 deletions startup/gui/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ def __registerOutputs( aovs, halfFloat = False, denoise = False ) :
label = "Light_Group"

if data == "aov_color" :
data = "aovc aov_color"
data = "color aov_color"

if data == "aov_value" :
data = "aovv aov_value"
data = "float aov_value"

if data.startswith( "cryptomatte" ) :
data = data.replace( "_", " " )
Expand Down