def testShaders(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.Displays() s["d"].addDisplay( "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(1) 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"]["updateShaders"].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"]["updateShaders"].setValue(True) time.sleep(1) c = self.__colorAtUV( IECore.ImageDisplayDriver.storedImage("myLovelyPlane"), IECore.V2f(0.5), ) self.assertEqual(c, IECore.Color3f(0.5))
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.Displays() s["d"].addDisplay( "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(1) 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))
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 )
def testMoveCoordinateSystem( self ) : shader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coordSysDot.sl" ) s = Gaffer.ScriptNode() s["plane"] = GafferScene.Plane() s["shader"] = GafferRenderMan.RenderManShader() s["shader"].loadShader( shader ) s["shader"]["parameters"]["coordSys"].setValue( "/group/coordinateSystem" ) s["shaderAssignment"] = GafferScene.ShaderAssignment() s["shaderAssignment"]["in"].setInput( s["plane"]["out"] ) s["shaderAssignment"]["shader"].setInput( s["shader"]["out"] ) s["camera"] = GafferScene.Camera() s["camera"]["transform"]["translate"]["z"].setValue( 1 ) s["coordSys"] = GafferScene.CoordinateSystem() s["g"] = GafferScene.Group() s["g"]["in"].setInput( s["shaderAssignment"]["out"] ) s["g"]["in1"].setInput( s["camera"]["out"] ) s["g"]["in2"].setInput( s["coordSys"]["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["g"]["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.assertAlmostEqual( c[1], 1, delta = 0.001 ) # move the coordinate system, and check the output s["coordSys"]["transform"]["translate"]["x"].setValue( 0.1 ) time.sleep( 2 ) c = self.__colorAtUV( IECore.ImageDisplayDriver.storedImage( "myLovelyPlane" ), IECore.V2f( 0.6, 0.5 ), ) self.assertAlmostEqual( c[0], 1 ) c = self.__colorAtUV( IECore.ImageDisplayDriver.storedImage( "myLovelyPlane" ), IECore.V2f( 0.6, 0.7 ), ) self.assertAlmostEqual( c[0], 0 ) # scale the coordinate system to cover everything, and check again s["coordSys"]["transform"]["scale"].setValue( IECore.V3f( 100 ) ) time.sleep( 2 ) for p in [ IECore.V2f( 0.5 ), IECore.V2f( 0.1 ), IECore.V2f( 0.9 ), ] : c = self.__colorAtUV( IECore.ImageDisplayDriver.storedImage( "myLovelyPlane" ), p, ) self.assertAlmostEqual( c[0], 1, delta = 0.001 )
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"]["match"] ) 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] )
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 ) )
import GafferUI import GafferRenderMan import IECore import os scriptFile = script['fileName'].getValue() scriptPath = os.path.dirname(scriptFile) os.environ[ 'DL_SHADERS_PATH'] = os.environ['DL_SHADERS_PATH'] + ':' + scriptPath shaderNode = GafferRenderMan.RenderManShader('ShaderNode') script.addChild(shaderNode) shaderNode.shaderLoader().searchPath = IECore.SearchPath( os.environ['DL_SHADERS_PATH'], ":") shaderPath = 'annotationsExample' shaderNode.loadShader(shaderPath) scriptWindow = GafferUI.ScriptWindow.acquire(script) scriptNode = script layout = eval( "GafferUI.CompoundEditor( scriptNode, children = {'tabs': (GafferUI.NodeEditor( scriptNode ),), 'currentTab': 0} )" ) #simple single NodeEditor layout scriptWindow.setLayout(layout) scriptWindow._Widget__qtWidget.resize(500, 700) script.selection().clear() #make sure the Shader node is active script.selection().add(shaderNode) #make sure the Shader node is active
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() i = IECore.EXRImageReader(self.temporaryDirectory() + "/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)
def testSplineParameters( self ) : shader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/splineParameters.sl" ) n = GafferRenderMan.RenderManShader() n.loadShader( shader ) self.assertEqual( n["parameters"].keys(), [ "floatSpline", "colorSpline", "colorSpline2" ] ) self.assertTrue( isinstance( n["parameters"]["floatSpline"], Gaffer.SplineffPlug ) ) self.assertTrue( isinstance( n["parameters"]["colorSpline"], Gaffer.SplinefColor3fPlug ) ) self.assertEqual( n["parameters"]["floatSpline"].defaultValue(), IECore.Splineff( IECore.CubicBasisf.catmullRom(), [ ( 0, 0 ), ( 0, 0 ), ( 1, 1 ), ( 1, 1 ), ] ) ) self.assertEqual( n["parameters"]["colorSpline"].defaultValue(), IECore.SplinefColor3f( IECore.CubicBasisf.catmullRom(), [ ( 0, IECore.Color3f( 0 ) ), ( 0, IECore.Color3f( 0 ) ), ( 1, IECore.Color3f( 1 ) ), ( 1, IECore.Color3f( 1 ) ), ] ) ) floatValue = IECore.Splineff( IECore.CubicBasisf.catmullRom(), [ ( 0, 0 ), ( 0, 0 ), ( 1, 2 ), ( 1, 2 ), ] ) colorValue = IECore.SplinefColor3f( IECore.CubicBasisf.catmullRom(), [ ( 0, IECore.Color3f( 0 ) ), ( 0, IECore.Color3f( 0 ) ), ( 1, IECore.Color3f( .5 ) ), ( 1, IECore.Color3f( .5 ) ), ] ) n["parameters"]["floatSpline"].setValue( floatValue ) n["parameters"]["colorSpline"].setValue( colorValue ) s = n.state()[0] self.assertEqual( s.parameters["floatSpline"].value, floatValue ) self.assertEqual( s.parameters["colorSpline"].value, colorValue )
def testDisablingCoshaderArrayInputs( self ) : shader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coshaderArrayParameters.sl" ) n = GafferRenderMan.RenderManShader() n.loadShader( shader ) coshader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coshader.sl" ) coshaderNode1 = GafferRenderMan.RenderManShader() coshaderNode1.loadShader( coshader ) coshaderNode2 = GafferRenderMan.RenderManShader() coshaderNode2.loadShader( coshader ) n["parameters"]["fixedShaderArray"][0].setInput( coshaderNode1["out"] ) n["parameters"]["fixedShaderArray"][2].setInput( coshaderNode2["out"] ) state = n.state() h1 = n.stateHash() self.assertEqual( state[2].parameters["fixedShaderArray"], IECore.StringVectorData( [ state[0].parameters["__handle"].value, "", state[1].parameters["__handle"].value, "" ] ) ) coshaderNode1["enabled"].setValue( False ) state = n.state() self.assertEqual( state[1].parameters["fixedShaderArray"], IECore.StringVectorData( [ "", "", state[0].parameters["__handle"].value, "" ] ) ) h2 = n.stateHash() self.assertNotEqual( h2, h1 ) coshaderNode2["enabled"].setValue( False ) state = n.state() self.assertEqual( state[0].parameters["fixedShaderArray"], IECore.StringVectorData( [ "", "", "", "" ] ) ) self.assertNotEqual( n.stateHash(), h1 ) self.assertNotEqual( n.stateHash(), h2 )
def testSerialDisabledShaders( self ) : # C ----> D1 ----> D2 ----> S shader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coshaderParameter.sl" ) S = GafferRenderMan.RenderManShader() S.loadShader( shader ) passThroughCoshader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coshaderWithPassThrough.sl" ) D1 = GafferRenderMan.RenderManShader() D1.loadShader( passThroughCoshader ) D2 = GafferRenderMan.RenderManShader() D2.loadShader( passThroughCoshader ) coshader = self.compileShader( os.path.dirname( __file__ ) + "/shaders/coshader.sl" ) C = GafferRenderMan.RenderManShader() C.loadShader( coshader ) S["parameters"]["coshaderParameter"].setInput( D2["out"] ) D2["parameters"]["aColorIWillTint"].setInput( D1["out"] ) D1["parameters"]["aColorIWillTint"].setInput( C["out"] ) h1 = S.stateHash() s = S.state() self.assertEqual( len( s ), 4 ) self.assertEqual( s[0].name, coshader ) self.assertEqual( s[1].name, passThroughCoshader ) self.assertEqual( s[2].name, passThroughCoshader ) self.assertEqual( s[3].name, shader ) self.assertEqual( s[3].parameters["coshaderParameter"], s[2].parameters["__handle"] ) self.assertEqual( s[2].parameters["aColorIWillTint"], s[1].parameters["__handle"] ) self.assertEqual( s[1].parameters["aColorIWillTint"], s[0].parameters["__handle"] ) D2["enabled"].setValue( False ) h2 = S.stateHash() self.assertNotEqual( h1, h2 ) s = S.state() self.assertEqual( len( s ), 3 ) self.assertEqual( s[0].name, coshader ) self.assertEqual( s[1].name, passThroughCoshader ) self.assertEqual( s[2].name, shader ) self.assertEqual( s[2].parameters["coshaderParameter"], s[1].parameters["__handle"] ) self.assertEqual( s[1].parameters["aColorIWillTint"], s[0].parameters["__handle"] ) D1["enabled"].setValue( False ) h3 = S.stateHash() self.assertNotEqual( h3, h2 ) self.assertNotEqual( h3, h1 ) s = S.state() self.assertEqual( len( s ), 2 ) self.assertEqual( s[0].name, coshader ) self.assertEqual( s[1].name, shader ) self.assertEqual( s[1].parameters["coshaderParameter"], s[0].parameters["__handle"] )