Esempio n. 1
0
    def testRender(self):

        s = Gaffer.ScriptNode()

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("pointlight")
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))
        s["l"]["transform"]["translate"]["z"].setValue(1)

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["l"]["out"])
        s["g"]["in1"].setInput(s["p"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("matte")
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display("/tmp/testRenderManLight.exr", "exr", "rgba",
                           {"quantize": IECore.FloatVectorData([0, 0, 0, 0])}))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.RenderManRender()
        s["r"]["ribFileName"].setValue("/tmp/testRenderManLight.rib")
        s["r"]["in"].setInput(s["o"]["out"])

        # must save the script for the procedural to load it
        # in the render process. if we were using a dispatcher,
        # that would have saved the script for us, but we're
        # calling execute() directly so it is our responsibility.
        s["fileName"].setValue("/tmp/testRenderManLight.gfr")
        s.save()

        s["r"].execute()

        i = IECore.EXRImageReader("/tmp/testRenderManLight.exr").read()
        e = IECore.ImagePrimitiveEvaluator(i)
        r = e.createResult()
        e.pointAtUV(IECore.V2f(0.5), r)

        self.assertEqual(r.floatPrimVar(e.R()), 1)
        self.assertEqual(r.floatPrimVar(e.G()), 0.5)
        self.assertEqual(r.floatPrimVar(e.B()), 0.25)
Esempio n. 2
0
    def testRender(self):

        s = Gaffer.ScriptNode()
        s["fileName"].setValue("/tmp/testRenderManLight.gfr")

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("pointlight")
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))
        s["l"]["transform"]["translate"]["z"].setValue(1)

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["l"]["out"])
        s["g"]["in1"].setInput(s["p"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("matte")
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Displays()
        s["d"].addDisplay(
            "beauty",
            IECore.Display("/tmp/testRenderManLight.exr", "exr", "rgba",
                           {"quantize": IECore.FloatVectorData([0, 0, 0, 0])}))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.RenderManRender()
        s["r"]["ribFileName"].setValue("/tmp/testRenderManLight.rib")
        s["r"]["in"].setInput(s["o"]["out"])

        ## \todo This fails because ExecutableRender::execute() doesn't wait for the
        # subprocess to complete as it should. We need to make it wait, but we can't
        # do that until we're using the LocalDespatcher in gui applications.
        s["r"].execute([Gaffer.Context.current()])

        i = IECore.EXRImageReader("/tmp/testRenderManLight.exr").read()
        e = IECore.ImagePrimitiveEvaluator(i)
        r = e.createResult()
        e.pointAtUV(IECore.V2f(0.5), r)

        self.assertEqual(r.floatPrimVar(e.R()), 1)
        self.assertEqual(r.floatPrimVar(e.G()), 0.5)
        self.assertEqual(r.floatPrimVar(e.B()), 0.25)
Esempio n. 3
0
def __nodeCreator( nodeName, shaderName ) :

	shader = GafferRenderMan.RenderManShader.shaderLoader().read( shaderName + ".sdl" )
	if shader.type == "light" :
		node = GafferRenderMan.RenderManLight( nodeName )
	else :
		node = GafferRenderMan.RenderManShader( nodeName )
	
	node.loadShader( shaderName )
	
	return node
Esempio n. 4
0
    def test(self):

        n = GafferRenderMan.RenderManLight()
        n.loadShader("pointlight")

        light = n["out"].object("/light")
        self.assertTrue(isinstance(light, IECore.Light))
        self.assertEqual(light.parameters["intensity"].value, 1)

        n["parameters"]["intensity"].setValue(10)
        light = n["out"].object("/light")
        self.assertEqual(light.parameters["intensity"].value, 10)
Esempio n. 5
0
    def testHiddenLight(self):

        s = Gaffer.ScriptNode()
        s["fileName"].setValue(self.temporaryDirectory() + "/test.gfr")

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"]["name"].setValue("myLight")
        s["l"].loadShader("pointlight")

        s["g"] = GafferScene.Group()
        s["g"]["in"][0].setInput(s["l"]["out"])

        s["f1"] = GafferScene.PathFilter()
        s["f2"] = GafferScene.PathFilter()

        s["a1"] = GafferScene.StandardAttributes()
        s["a1"]["attributes"]["visibility"]["enabled"].setValue(True)
        s["a1"]["attributes"]["visibility"]["value"].setValue(False)
        s["a1"]["in"].setInput(s["g"]["out"])
        s["a1"]["filter"].setInput(s["f1"]["out"])

        s["a2"] = GafferScene.StandardAttributes()
        s["a2"]["attributes"]["visibility"]["enabled"].setValue(True)
        s["a2"]["attributes"]["visibility"]["value"].setValue(True)
        s["a2"]["in"].setInput(s["a1"]["out"])
        s["a2"]["filter"].setInput(s["f2"]["out"])

        s["r"] = GafferRenderMan.RenderManRender()
        s["r"]["mode"].setValue("generate")
        s["r"]["ribFileName"].setValue(self.temporaryDirectory() + "/test.rib")
        s["r"]["in"].setInput(s["a2"]["out"])

        s["r"].execute()
        rib = "\n".join(
            file(self.temporaryDirectory() + "/test.rib").readlines())
        self.assertTrue("LightSource \"pointlight\"" in rib)

        s["f1"]["paths"].setValue(IECore.StringVectorData(["/group"
                                                           ]))  # hide group

        s["r"].execute()
        rib = "\n".join(
            file(self.temporaryDirectory() + "/test.rib").readlines())
        self.assertTrue("LightSource \"pointlight\"" not in rib)

        s["f2"]["paths"].setValue(IECore.StringVectorData(
            ["/group/myLight"]))  # show coordsys (but parent still hidden)

        s["r"].execute()
        rib = "\n".join(
            file(self.temporaryDirectory() + "/test.rib").readlines())
        self.assertTrue("LightSource \"pointlight\"" not in rib)
Esempio n. 6
0
	def __init__( self, name = "RenderManShaderBall" ) :

		GafferScene.ShaderBall.__init__( self, name )

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

		self["__envLight"] = GafferRenderMan.RenderManLight()
		self["__envLight"].loadShader( "envlight" )
		self["__envLight"]["parameters"]["envmap"].setInput( self["environment"] )

		self["__parentLights"] = GafferScene.Parent()
		self["__parentLights"]["in"].setInput( self._outPlug().getInput() )
		self["__parentLights"]["child"].setInput( self["__envLight"]["out"] )
		self["__parentLights"]["parent"].setValue( "/" )

		self._outPlug().setInput( self["__parentLights"]["out"] )
Esempio n. 7
0
    def testLights(self):

        s = Gaffer.ScriptNode()

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("pointlight")
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))
        s["l"]["transform"]["translate"]["z"].setValue(1)

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["l"]["out"])
        s["g"]["in1"].setInput(s["p"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("matte")
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 0.5, 0.25))

        # adjust a parameter, give it time to update, and check the output

        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(0.25, 0.5, 1))

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[2], IECore.Color3f(0.25, 0.5, 1))

        # pause it, adjust a parameter, wait, and check that nothing changed

        s["r"]["state"].setValue(s["r"].State.Paused)
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[2], IECore.Color3f(0.25, 0.5, 1))

        # unpause it, wait, and check that the update happened

        s["r"]["state"].setValue(s["r"].State.Running)
        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 0.5, 0.25))

        # turn off light updates, adjust a parameter, wait, and check nothing happened

        s["r"]["updateLights"].setValue(False)
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(0.25, 0.5, 1))

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 0.5, 0.25))

        # turn light updates back on and check that it updates

        s["r"]["updateLights"].setValue(True)

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[2], IECore.Color3f(0.25, 0.5, 1))

        # stop the render, tweak a parameter and check that nothing happened

        s["r"]["state"].setValue(s["r"].State.Stopped)
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))
        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[2], IECore.Color3f(0.25, 0.5, 1))
Esempio n. 8
0
    def testHideLight(self):

        s = Gaffer.ScriptNode()

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("pointlight")
        s["l"]["transform"]["translate"]["z"].setValue(1)

        s["v"] = GafferScene.StandardAttributes()
        s["v"]["attributes"]["visibility"]["enabled"].setValue(True)
        s["v"]["in"].setInput(s["l"]["out"])

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["v"]["out"])
        s["g"]["in1"].setInput(s["p"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("matte")
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertNotEqual(c[0], 0.0)

        # remove the light by hiding it

        s["v"]["attributes"]["visibility"]["value"].setValue(False)
        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c[0], 0.0)

        # put the light back by showing it

        s["v"]["attributes"]["visibility"]["value"].setValue(True)
        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertNotEqual(c[0], 0.0)
Esempio n. 9
0
    def testAddLight(self):

        s = Gaffer.ScriptNode()

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("pointlight")
        s["l"]["parameters"]["lightcolor"].setValue(IECore.Color3f(1, 0, 0))
        s["l"]["transform"]["translate"]["z"].setValue(1)

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["l"]["out"])
        s["g"]["in1"].setInput(s["p"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("matte")
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 0, 0))

        # add a light

        s["l2"] = GafferRenderMan.RenderManLight()
        s["l2"].loadShader("pointlight")
        s["l2"]["parameters"]["lightcolor"].setValue(IECore.Color3f(0, 1, 0))
        s["l2"]["transform"]["translate"]["z"].setValue(1)

        s["g"]["in3"].setInput(s["l2"]["out"])

        # give it time to update, and check the output

        time.sleep(1)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c / c[0], IECore.Color3f(1, 1, 0))
Esempio n. 10
0
    def testScopesDontLeak(self):

        s = Gaffer.ScriptNode()

        s["p"] = GafferScene.Plane()
        s["p"]["transform"]["translate"].setValue(IECore.V3f(-0.6, -0.1, 0))

        s["p1"] = GafferScene.Plane()
        s["p1"]["transform"]["translate"].setValue(IECore.V3f(0.6, 0.1, 0))

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(2)

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("ambientlight")

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["p"]["out"])
        s["g"]["in1"].setInput(s["p1"]["out"])
        s["g"]["in2"].setInput(s["c"]["out"])
        s["g"]["in3"].setInput(s["l"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("checker")
        s["s"]["parameters"]["blackcolor"].setValue(IECore.Color3f(1, 0, 0))
        s["s"]["parameters"]["Ka"].setValue(1)
        s["s"]["parameters"]["frequency"].setValue(1)

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

        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])
        s["a"]["filter"].setInput(s["f"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlanes",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["options"]["renderResolution"]["value"].setValue(
            IECore.V2i(512))
        s["o"]["options"]["renderResolution"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output.
        # we should have a red plane on the left, and a facing ratio
        # shaded plane on the right, because we attached no shader to the
        # second plane.

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlanes"),
            IECore.V2f(0.25, 0.5),
        )
        self.assertEqual(c, IECore.Color3f(1, 0, 0))

        c1 = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlanes"),
            IECore.V2f(0.75, 0.5),
        )
        self.assertTrue(c1[0] > 0.9)
        self.assertEqual(c1[0], c1[1])
        self.assertEqual(c1[0], c1[2])

        # adjust a shader parameter, wait, and check that the plane
        # on the left changed. check that the plane on the right didn't
        # change at all.

        s["s"]["parameters"]["blackcolor"].setValue(IECore.Color3f(0, 1, 0))
        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlanes"),
            IECore.V2f(0.25, 0.5),
        )
        self.assertEqual(c, IECore.Color3f(0, 1, 0))

        c1 = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlanes"),
            IECore.V2f(0.75, 0.5),
        )
        self.assertTrue(c1[0] > 0.9)
        self.assertEqual(c1[0], c1[1])
        self.assertEqual(c1[0], c1[2])
Esempio n. 11
0
    def testAttributes(self):

        s = Gaffer.ScriptNode()

        s["p"] = GafferScene.Plane()
        s["p"]["transform"]["translate"].setValue(IECore.V3f(-0.1, -0.1, 0))

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("ambientlight")

        s["g"] = GafferScene.Group()
        s["g"]["in"].setInput(s["p"]["out"])
        s["g"]["in1"].setInput(s["c"]["out"])
        s["g"]["in2"].setInput(s["l"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("checker")
        s["s"]["parameters"]["blackcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))
        s["s"]["parameters"]["Ka"].setValue(1)
        s["s"]["parameters"]["frequency"].setValue(1)

        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                "test", "ieDisplay", "rgba", {
                    "quantize": IECore.FloatVectorData([0, 0, 0, 0]),
                    "driverType": "ImageDisplayDriver",
                    "handle": "myLovelyPlane",
                }))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.InteractiveRenderManRender()
        s["r"]["in"].setInput(s["o"]["out"])

        # start a render, give it time to finish, and check the output

        s["r"]["state"].setValue(s["r"].State.Running)

        time.sleep(2)

        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c, IECore.Color3f(1, 0.5, 0.25))

        # adjust a shader parameter, wait, and check that it changed

        s["s"]["parameters"]["blackcolor"].setValue(IECore.Color3f(1, 1, 1))
        time.sleep(1)
        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c, IECore.Color3f(1))

        # turn off shader updates, do the same, and check that it hasn't changed

        s["r"]["updateAttributes"].setValue(False)
        s["s"]["parameters"]["blackcolor"].setValue(IECore.Color3f(0.5))
        time.sleep(1)
        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c, IECore.Color3f(1))

        # turn shader updates back on, and check that it updates

        s["r"]["updateAttributes"].setValue(True)
        time.sleep(1)
        c = self.__colorAtUV(
            IECore.ImageDisplayDriver.storedImage("myLovelyPlane"),
            IECore.V2f(0.5),
        )
        self.assertEqual(c, IECore.Color3f(0.5))
Esempio n. 12
0
    def testRender(self):

        s = Gaffer.ScriptNode()

        s["l"] = GafferRenderMan.RenderManLight()
        s["l"].loadShader("pointlight")
        s["l"]["parameters"]["lightcolor"].setValue(
            IECore.Color3f(1, 0.5, 0.25))
        s["l"]["transform"]["translate"]["z"].setValue(1)

        s["p"] = GafferScene.Plane()

        s["c"] = GafferScene.Camera()
        s["c"]["transform"]["translate"]["z"].setValue(1)

        s["g"] = GafferScene.Group()
        s["g"]["in"][0].setInput(s["l"]["out"])
        s["g"]["in"][1].setInput(s["p"]["out"])
        s["g"]["in"][2].setInput(s["c"]["out"])

        s["s"] = GafferRenderMan.RenderManShader()
        s["s"].loadShader("matte")
        s["a"] = GafferScene.ShaderAssignment()
        s["a"]["in"].setInput(s["g"]["out"])
        s["a"]["shader"].setInput(s["s"]["out"])

        s["d"] = GafferScene.Outputs()
        s["d"].addOutput(
            "beauty",
            IECore.Display(
                self.temporaryDirectory() + "/testRenderManLight.exr", "exr",
                "rgba", {"quantize": IECore.FloatVectorData([0, 0, 0, 0])}))
        s["d"]["in"].setInput(s["a"]["out"])

        s["o"] = GafferScene.StandardOptions()
        s["o"]["options"]["renderCamera"]["value"].setValue("/group/camera")
        s["o"]["options"]["renderCamera"]["enabled"].setValue(True)
        s["o"]["in"].setInput(s["d"]["out"])

        s["r"] = GafferRenderMan.RenderManRender()
        s["r"]["ribFileName"].setValue(self.temporaryDirectory() +
                                       "/testRenderManLight.rib")
        s["r"]["in"].setInput(s["o"]["out"])

        # must save the script for the procedural to load it
        # in the render process. if we were using a dispatcher,
        # that would have saved the script for us, but we're
        # calling execute() directly so it is our responsibility.
        s["fileName"].setValue(self.temporaryDirectory() +
                               "/testRenderManLight.gfr")
        s.save()

        s["r"].execute()

        imageReader = GafferImage.ImageReader()
        imageReader["fileName"].setValue(self.temporaryDirectory() +
                                         "/testRenderManLight.exr")

        imageSampler = GafferImage.ImageSampler()
        imageSampler["image"].setInput(imageReader["out"])
        imageSampler["pixel"].setValue(IECore.V2f(320, 240))

        self.assertEqual(imageSampler["color"]["r"].getValue(), 1)
        self.assertEqual(imageSampler["color"]["g"].getValue(), 0.5)
        self.assertEqual(imageSampler["color"]["b"].getValue(), 0.25)