コード例 #1
0
	def __init__( self, name = "ArnoldShaderBall" ) :

		GafferScene.ShaderBall.__init__( self, name )

		self["environment"] = Gaffer.StringPlug( defaultValue = "${GAFFER_ROOT}/resources/hdri/studio.exr" )

		self["__envMap"] = GafferArnold.ArnoldShader()
		self["__envMap"].loadShader( "image" )
		self["__envMap"]["parameters"]["filename"].setInput( self["environment"] )

		self["__skyDome"] = GafferArnold.ArnoldLight()
		self["__skyDome"].loadShader( "skydome_light" )
		self["__skyDome"]["parameters"]["color"].setInput( self["__envMap"]["out"] )
		self["__skyDome"]["parameters"]["format"].setValue( "latlong" )
		self["__skyDome"]["parameters"]["camera"].setValue( 0 )

		self["__parentLights"] = GafferScene.Parent()
		self["__parentLights"]["in"].setInput( self._outPlug().getInput() )
		self["__parentLights"]["children"][0].setInput( self["__skyDome"]["out"] )
		self["__parentLights"]["parent"].setValue( "/" )

		self["__arnoldOptions"] = GafferArnold.ArnoldOptions()
		self["__arnoldOptions"]["in"].setInput( self["__parentLights"]["out"] )
		self["__arnoldOptions"]["options"]["aaSamples"]["enabled"].setValue( True )
		self["__arnoldOptions"]["options"]["aaSamples"]["value"].setValue( 3 )

		self.addChild(
			self["__arnoldOptions"]["options"]["threads"].createCounterpart( "threads", Gaffer.Plug.Direction.In )
		)
		self["__arnoldOptions"]["options"]["threads"].setInput( self["threads"] )

		self._outPlug().setInput( self["__arnoldOptions"]["out"] )
コード例 #2
0
	def testFrameAndAASeed( self ) :

		options = GafferArnold.ArnoldOptions()

		render = GafferArnold.ArnoldRender()
		render["in"].setInput( options["out"] )
		render["mode"].setValue( render.Mode.SceneDescriptionMode )
		render["fileName"].setValue( self.temporaryDirectory() + "/test.ass" )

		for frame in ( 1, 2, 2.8, 3.2 ) :
			for seed in ( None, 3, 4 ) :
				with Gaffer.Context() as c :

					c.setFrame( frame )

					options["options"]["aaSeed"]["enabled"].setValue( seed is not None )
					options["options"]["aaSeed"]["value"].setValue( seed or 1 )

					render["task"].execute()

					with IECoreArnold.UniverseBlock( writable = True ) :

						arnold.AiASSLoad( self.temporaryDirectory() + "/test.ass" )

						self.assertEqual(
							arnold.AiNodeGetInt( arnold.AiUniverseGetOptions(), "AA_seed" ),
							seed or round( frame )
						)
コード例 #3
0
    def testValidity(self):

        o = GafferArnold.ArnoldOptions()

        o["out"].transform("/")
        self.failUnless(
            isinstance(o["out"].childNames("/"),
                       IECore.InternedStringVectorData))
コード例 #4
0
	def testSerialisation( self ) :

		s = Gaffer.ScriptNode()
		s["o"] = GafferArnold.ArnoldOptions()
		s["o"]["options"]["aaSamples"]["value"].setValue( 1 )
		names = s["o"]["options"].keys()

		s2 = Gaffer.ScriptNode()
		s2.execute( s.serialise() )

		self.assertEqual( s2["o"]["options"].keys(), names )
		self.assertTrue( "options1" not in s2["o"] )
		self.assertEqual( s2["o"]["options"]["aaSamples"]["value"].getValue(), 1 )
コード例 #5
0
	def testEncapsulateDeformationBlur( self ) :

		s = Gaffer.ScriptNode()

		# Make a sphere where the red channel has the value of the current frame.

		s["sphere"] = GafferScene.Sphere()

		s["sphereFilter"] = GafferScene.PathFilter()
		s["sphereFilter"]["paths"].setValue( IECore.StringVectorData( [ "/sphere" ] ) )

		s["frame"] = GafferTest.FrameNode()

		s["flat"] = GafferArnold.ArnoldShader()
		s["flat"].loadShader( "flat" )
		s["flat"]["parameters"]["color"].setValue( imath.Color3f( 0 ) )
		s["flat"]["parameters"]["color"]["r"].setInput( s["frame"]["output"] )

		s["assignment"] = GafferScene.ShaderAssignment()
		s["assignment"]["in"].setInput( s["sphere"]["out"] )
		s["assignment"]["shader"].setInput( s["flat"]["out"] )
		s["assignment"]["filter"].setInput( s["sphereFilter"]["out"] )

		# Put the sphere in a capsule.

		s["group"] = GafferScene.Group()
		s["group"]["in"][0].setInput( s["assignment"]["out"] )

		s["groupFilter"] = GafferScene.PathFilter()
		s["groupFilter"]["paths"].setValue( IECore.StringVectorData( [ "/group" ] ) )

		s["encapsulate"] = GafferScene.Encapsulate()
		s["encapsulate"]["in"].setInput( s["group"]["out"] )
		s["encapsulate"]["filter"].setInput( s["groupFilter"]["out"] )

		# Do a render at frame 1, with deformation blur off.

		s["outputs"] = GafferScene.Outputs()
		s["outputs"].addOutput(
			"beauty",
			IECoreScene.Output(
				os.path.join( self.temporaryDirectory(), "deformationBlurOff.exr" ),
				"exr",
				"rgba",
				{
				}
			)
		)
		s["outputs"]["in"].setInput( s["encapsulate"]["out"] )

		s["options"] = GafferScene.StandardOptions()
		s["options"]["in"].setInput( s["outputs"]["out"] )

		s["arnoldOptions"] = GafferArnold.ArnoldOptions()
		s["arnoldOptions"]["in"].setInput( s["options"]["out"] )
		s["arnoldOptions"]["options"]["aaSamples"]["enabled"].setValue( True )
		s["arnoldOptions"]["options"]["aaSamples"]["value"].setValue( 6 )

		s["render"] = GafferArnold.ArnoldRender()
		s["render"]["in"].setInput( s["arnoldOptions"]["out"] )
		s["render"]["task"].execute()

		# Do another render at frame 1, but with deformation blur on.

		s["options"]["options"]["deformationBlur"]["enabled"].setValue( True )
		s["options"]["options"]["deformationBlur"]["value"].setValue( True )
		s["options"]["options"]["shutter"]["enabled"].setValue( True )
		s["options"]["options"]["shutter"]["value"].setValue( imath.V2f( -0.5, 0.5 ) )
		s["outputs"]["outputs"][0]["fileName"].setValue( os.path.join( self.temporaryDirectory(), "deformationBlurOn.exr" ) )
		s["render"]["task"].execute()

		# Check that the renders are the same.

		s["deformationOff"] = GafferImage.ImageReader()
		s["deformationOff"]["fileName"].setValue( os.path.join( self.temporaryDirectory(), "deformationBlurOff.exr" ) )

		s["deformationOn"] = GafferImage.ImageReader()
		s["deformationOn"]["fileName"].setValue( os.path.join( self.temporaryDirectory(), "deformationBlurOn.exr" ) )

		# The `maxDifference` is huge to account for noise and watermarks, but is still low enough to check what
		# we want, since if the Encapsulate was sampled at shutter open and not the frame, the difference would be
		# 0.5.
		self.assertImagesEqual( s["deformationOff"]["out"], s["deformationOn"]["out"], maxDifference = 0.25, ignoreMetadata = True )
コード例 #6
0
    def runInteractive(self, useUI, useBlur, resolution):

        script = Gaffer.ScriptNode()

        script["Camera"] = GafferScene.Camera()
        script["Camera"]["transform"]["translate"]["z"].setValue(6)

        script["Sphere"] = GafferScene.Sphere("Sphere")
        script["Sphere"]["radius"].setValue(10)

        script["ImageShader"] = GafferArnold.ArnoldShader()
        script["ImageShader"].loadShader("image")
        script["ImageShader"]["parameters"]["filename"].setValue(
            os.path.dirname(__file__) +
            "/../GafferImageTest/images/GafferChecker.exr")
        script["ImageShader"]["parameters"]["sscale"].setValue(16)
        script["ImageShader"]["parameters"]["tscale"].setValue(16)

        script["ShaderAssignment"] = GafferScene.ShaderAssignment()
        script["ShaderAssignment"]["in"].setInput(script["Sphere"]["out"])
        script["ShaderAssignment"]["shader"].setInput(
            script["ImageShader"]["out"])

        script["Group"] = GafferScene.Group()
        script["Group"]["in"][0].setInput(script["Camera"]["out"])
        script["Group"]["in"][1].setInput(script["ShaderAssignment"]["out"])

        script["StandardOptions"] = GafferScene.StandardOptions()
        script["StandardOptions"]["in"].setInput(script["Group"]["out"])
        script["StandardOptions"]["options"]["renderCamera"]["value"].setValue(
            '/group/camera')
        script["StandardOptions"]["options"]["renderCamera"][
            "enabled"].setValue(True)
        script["StandardOptions"]["options"]["renderResolution"][
            "value"].setValue(imath.V2i(resolution, resolution))
        script["StandardOptions"]["options"]["renderResolution"][
            "enabled"].setValue(True)

        script["ArnoldOptions"] = GafferArnold.ArnoldOptions("ArnoldOptions")
        script["ArnoldOptions"]["in"].setInput(
            script["StandardOptions"]["out"])
        # Make sure we leave some CPU available for Gaffer
        script["ArnoldOptions"]["options"]["threads"]["value"].setValue(-1)
        script["ArnoldOptions"]["options"]["threads"]["enabled"].setValue(True)

        script["Outputs"] = GafferScene.Outputs()
        script["Outputs"].addOutput(
            "beauty",
            IECoreScene.Output(
                "Interactive/Beauty", "ieDisplay", "rgba", {
                    "quantize":
                    IECore.IntVectorData([0, 0, 0, 0]),
                    "driverType":
                    'ClientDisplayDriver',
                    "displayHost":
                    'localhost',
                    "displayPort":
                    str(GafferImage.Catalogue.displayDriverServer().portNumber(
                    )),
                    "remoteDisplayType":
                    'GafferImage::GafferDisplayDriver',
                    "filter":
                    'box',
                }))
        script["Outputs"]["in"].setInput(script["ArnoldOptions"]["out"])

        script[
            "InteractiveArnoldRender"] = GafferArnold.InteractiveArnoldRender(
            )
        script["InteractiveArnoldRender"]["in"].setInput(
            script["Outputs"]["out"])

        script["Catalogue"] = GafferImage.Catalogue("Catalogue")
        script["Catalogue"]["directory"].setValue(self.temporaryDirectory() +
                                                  "/catalogues/test")

        script["Blur"] = GafferImage.Blur("Blur")
        script["Blur"]["in"].setInput(script["Catalogue"]["out"])
        script["Blur"]["radius"]["x"].setValue(1.0)
        script["Blur"]["radius"]["y"].setValue(1.0)

        watchNode = script["Blur"] if useBlur else script["Catalogue"]

        if useUI:

            with GafferUI.Window() as window:
                window.setFullScreen(True)
                viewer = GafferUI.Viewer(script)

            window.setVisible(True)
            viewer.setNodeSet(Gaffer.StandardSet([watchNode]))

            script['InteractiveArnoldRender']['state'].setValue(
                GafferScene.InteractiveRender.State.Running)
            self.waitForIdle(10)

            viewer.view().viewportGadget().frame(
                viewer.view().viewportGadget().getPrimaryChild().bound(),
                imath.V3f(0, 0, 1))

            frameCounter = {'i': 0}

            def testFunc():
                frameCounter['i'] += 1
                script["Camera"]["transform"]["translate"]["x"].setValue(
                    math.sin(frameCounter['i'] * 0.1))
                if frameCounter['i'] >= 50:
                    GafferUI.EventLoop.mainEventLoop().stop()

            timer = QtCore.QTimer()
            timer.setInterval(20)
            timer.timeout.connect(testFunc)

            GafferImageUI.ImageGadget.resetTileUpdateCount()
            timer.start()

            with GafferTest.TestRunner.PerformanceScope() as ps:
                GafferUI.EventLoop.mainEventLoop().start()
                ps.setNumIterations(
                    GafferImageUI.ImageGadget.tileUpdateCount())

            script['InteractiveArnoldRender']['state'].setValue(
                GafferScene.InteractiveRender.State.Stopped)

            del window, viewer, timer
            self.waitForIdle(10)

        else:
            with GafferTest.ParallelAlgoTest.UIThreadCallHandler() as h:

                with IECore.CapturingMessageHandler() as mh:
                    script['InteractiveArnoldRender']['state'].setValue(
                        GafferScene.InteractiveRender.State.Running)
                    h.waitFor(2)
                arnoldStartupErrors = mh.messages

                tc = Gaffer.ScopedConnection(
                    GafferImageTest.connectProcessTilesToPlugDirtiedSignal(
                        watchNode["out"]))

                with GafferTest.TestRunner.PerformanceScope() as ps:
                    with Gaffer.PerformanceMonitor() as m:
                        for i in range(250):
                            script["Camera"]["transform"]["translate"][
                                "x"].setValue(math.sin((i + 1) * 0.1))
                            h.waitFor(0.02)

                    ps.setNumIterations(
                        m.plugStatistics(
                            watchNode["out"]
                            ["channelData"].source()).computeCount)

                script['InteractiveArnoldRender']['state'].setValue(
                    GafferScene.InteractiveRender.State.Stopped)
コード例 #7
0
    def __init__(self, name="LDTShaderBallScene"):

        GafferScene.SceneNode.__init__(self, name)

        # Public plugs

        self["shader"] = GafferScene.ShaderPlug()
        self["resolution"] = Gaffer.IntPlug(defaultValue=512, minValue=0)

        #Gaffer.Metadata.registerValue(self["scene"], "nodule:type", "")
        #Gaffer.Metadata.registerValue(
        #    self["scene"], "plugValueWidget:type", "GafferUI.PresetsPlugValueWidget"
        #)
        #Gaffer.Metadata.registerValue(self["scene"], "preset:shaderBall", 0)
        #Gaffer.Metadata.registerValue(self["scene"], "preset:customGeo", 1)

        # Private internal network

        # Camera
        self["__camera"] = GafferScene.Camera()
        self["__camera"]["transform"]["translate"].setValue(
            imath.V3f(0, 86, 225))
        self["__camera"]["transform"]["rotate"].setValue(imath.V3f(-16, 0, 0))
        self["__camera"]["fieldOfView"].setValue(20.0)

        # Env
        self["__envMapFilename"] = Gaffer.StringPlug(
            defaultValue="${GAFFER_ROOT}/resources/hdri/studio.exr")

        # SkyDome
        self["__envMap"] = GafferArnold.ArnoldShader()
        self["__envMap"].loadShader("image")
        self["__envMap"]["parameters"]["filename"].setInput(
            self["__envMapFilename"])

        self["__skyDome"] = GafferArnold.ArnoldLight()
        self["__skyDome"].loadShader("skydome_light")
        self["__skyDome"]["parameters"]["color"].setInput(
            self["__envMap"]["out"])
        self["__skyDome"]["parameters"]["format"].setValue("latlong")

        # Expose Plugs
        self.addChild(
            self["__skyDome"]["parameters"]["exposure"].createCounterpart(
                "exposure", Gaffer.Plug.Direction.In))
        self["__skyDome"]["parameters"]["exposure"].setInput(self["exposure"])

        # Join ShaderBall and Camera
        self["__parent"] = GafferScene.Parent()
        #self["__parent"]["in"].setInput(self["__shaderBallReference"]["out"])
        self["__parent"]['children']['child0'].setInput(
            self["__camera"]["out"])
        self["__parent"]['children']['child1'].setInput(
            self["__skyDome"]["out"])
        self["__parent"]["parent"].setValue("/")

        self["__shaderAssignment"] = GafferScene.ShaderAssignment()
        self["__shaderAssignment"]["in"].setInput(self["__parent"]["out"])
        self["__shaderAssignment"]["shader"].setInput(self["shader"])
        self["__shaderAssignmentFilter"] = GafferScene.SetFilter("SetFilter")
        self["__shaderAssignmentFilter"]["setExpression"].setValue(
            "ShaderBall:material")

        self["__shaderAssignment"]["filter"].setInput(
            self["__shaderAssignmentFilter"]["out"])

        # Standard Options

        self["__options"] = GafferScene.StandardOptions()
        self["__options"]["in"].setInput(self["__shaderAssignment"]["out"])

        self["__options"]["options"]["renderCamera"]["enabled"].setValue(True)
        self["__options"]["options"]["renderCamera"]["value"].setValue(
            "/camera")
        self["__options"]["options"]["renderResolution"]["enabled"].setValue(
            True)
        # Expose Plugs
        self["__options"]["options"]["renderResolution"]["value"][0].setInput(
            self["resolution"])
        self["__options"]["options"]["renderResolution"]["value"][1].setInput(
            self["resolution"])

        # Arnold Options
        self["__arnoldOptions"] = GafferArnold.ArnoldOptions()
        self["__arnoldOptions"]["in"].setInput(self["__options"]["out"])
        self["__arnoldOptions"]["options"]["aaSamples"]["enabled"].setValue(
            True)
        self["__arnoldOptions"]["options"]["aaSamples"]["value"].setValue(3)
        # Expose Plugs
        self.addChild(
            self["__arnoldOptions"]["options"]["threads"].createCounterpart(
                "threads", Gaffer.Plug.Direction.In))
        self["__arnoldOptions"]["options"]["threads"].setInput(self["threads"])

        self["__emptyScene"] = GafferScene.ScenePlug()
        self["__enabler"] = Gaffer.Switch()
        self["__enabler"].setup(GafferScene.ScenePlug())
        self["__enabler"]["in"][0].setInput(self["__emptyScene"])
        self["__enabler"]["in"][1].setInput(self["__arnoldOptions"]["out"])
        self["__enabler"]["enabled"].setInput(self["enabled"])
        self["__enabler"]["index"].setValue(1)

        self["out"].setFlags(Gaffer.Plug.Flags.Serialisable, False)
        self["out"].setInput(self["__enabler"]["out"])