def testAutomaticInstancing( self ) : m = MeshPrimitive.createPlane( Box2f( V2f( -1 ), V2f( 1 ) ) ) r = IECoreRI.Renderer( "test/IECoreRI/output/instancing.rib" ) with WorldBlock( r ) : # check auto instancing is on by default, and turn it off: self.assertEqual( r.getAttribute("ri:automaticInstancing"), BoolData(True)) r.setAttribute("ri:automaticInstancing", BoolData(False)) m.render( r ) m.render( r ) rib = "".join( open( "test/IECoreRI/output/instancing.rib" ).readlines() ) self.assertEqual( rib.count( "ObjectBegin" ), 0 ) self.assertEqual( rib.count( "PointsGeneralPolygons" ), 2 ) r = IECoreRI.Renderer( "test/IECoreRI/output/instancing.rib" ) with WorldBlock( r ) : r.setAttribute( "ri:automaticInstancing", True ) m.render( r ) m.render( r ) rib = "".join( open( "test/IECoreRI/output/instancing.rib" ).readlines() ) self.assertEqual( rib.count( "ObjectBegin" ), 1 ) self.assertEqual( rib.count( "PointsGeneralPolygons" ), 1 ) self.assertEqual( rib.count( "ObjectInstance" ), 2 )
def testInstancingAcrossProcedurals(self): class InstanceInheritingProcedural(Renderer.Procedural): def __init__(self, root=True): Renderer.Procedural.__init__(self) self.__root = root def bound(self): return Box3f(V3f(-1), V3f(1)) def render(self, renderer): if self.__root: renderer.instanceBegin("myLovelySphere", {}) renderer.sphere(1, -1, 1, 360, {}) renderer.instanceEnd() renderer.procedural(InstanceInheritingProcedural(False)) else: renderer.instance("myLovelySphere") def hash(self): h = MurmurHash() return h # test writing a rib r = IECoreRI.Renderer("test/IECoreRI/output/instancing.rib") with WorldBlock(r): # disable auto instancing, as we're testing explicit instancing: r.setAttribute("ri:automaticInstancing", BoolData(False)) r.procedural(InstanceInheritingProcedural()) rib = "".join(open("test/IECoreRI/output/instancing.rib").readlines()) self.failUnless("ObjectInstance \"myLovelySphere\"" in rib) # test doing an actual render r = IECoreRI.Renderer("") r.display( "test", "ieDisplay", "rgba", { "driverType": StringData("ImageDisplayDriver"), "handle": StringData("myLovelySphere"), "quantize": FloatVectorData([0, 0, 0, 0]), }) with WorldBlock(r): # disable auto instancing, as we're testing explicit instancing: r.setAttribute("ri:automaticInstancing", BoolData(False)) r.concatTransform(M44f.createTranslated(V3f(0, 0, -10))) r.procedural(InstanceInheritingProcedural()) image = IECoreImage.ImageDisplayDriver.removeStoredImage( "myLovelySphere") dimensions = image.dataWindow.size() + V2i(1) index = dimensions.x * int(dimensions.y * 0.5) + int( dimensions.x * 0.5) self.failUnless(image["R"][index] > 0.95)
def testMesh( self ) : """Check that anticlockwise winding order is considered front facing by default.""" # render a single sided plane that shouldn't be backface culled r = IECoreRI.Renderer( "" ) r.display( "test/IECoreRI/output/testOrientation.tif", "tiff", "rgba", {} ) r.worldBegin() r.setAttribute( "doubleSided", IECore.BoolData( False ) ) r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) ) self.makePlane().render( r ) r.worldEnd() # check that something appears in the output image i = IECore.Reader.create( "test/IECoreRI/output/testOrientation.tif" ).read() dimensions = i.dataWindow.size() + IECore.V2i( 1 ) index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) self.assertEqual( i["A"][index], 1 ) del r # render a plane that should be backface culled r = IECoreRI.Renderer( "" ) r.display( "test/IECoreRI/output/testOrientation.tif", "tiff", "rgba", {} ) r.worldBegin() r.setAttribute( "doubleSided", IECore.BoolData( False ) ) r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) ) r.concatTransform( IECore.M44f.createRotated( IECore.V3f( 0, math.pi, 0 ) ) ) self.makePlane().render( r ) r.worldEnd() # check that nothing appears in the output image i = IECore.Reader.create( "test/IECoreRI/output/testOrientation.tif" ).read() dimensions = i.dataWindow.size() + IECore.V2i( 1 ) index = dimensions.x * int(dimensions.y * 0.5) + int(dimensions.x * 0.5) self.assertEqual( i["A"][index], 0 )
def test( self ) : self.assertEqual( os.system( "shaderdl -o test/IECoreRI/shaders/tex.sdl test/IECoreRI/shaders/tex.sl" ), 0 ) r = IECoreRI.Renderer( "" ) r.display( "test/IECoreRI/output/testTextureOrientation1.tif", "tiff", "rgba", {} ) r.worldBegin() r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) ) r.shader( "surface", "st", {} ) IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) ).render( r ) r.worldEnd() del r r = IECoreRI.Renderer( "" ) r.display( "test/IECoreRI/output/testTextureOrientation2.tif", "tiff", "rgba", {} ) r.setOption( "ri:searchpath:texture", IECore.StringData( "@:." ) ) r.worldBegin() r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) ) r.shader( "surface", "test/IECoreRI/shaders/tex", {} ) IECore.MeshPrimitive.createPlane( IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) ).render( r ) r.worldEnd() ie = IECore.ImageReader.create( "test/IECoreRI/data/textureOrientationImages/expected.tif" ).read() i1 = IECore.ImageReader.create( "test/IECoreRI/output/testTextureOrientation1.tif" ).read() i2 = IECore.ImageReader.create( "test/IECoreRI/output/testTextureOrientation2.tif" ).read() testOp = IECore.ImageDiffOp() self.assert_( not testOp( imageA=ie, imageB=i1, maxError=0.003 ).value ) self.assert_( not testOp( imageA=ie, imageB=i2, maxError=0.003 ).value )
def testInstancingAcrossProcedurals( self ) : class InstanceInheritingProcedural( Renderer.Procedural ) : def __init__( self, root = True ) : Renderer.Procedural.__init__( self ) self.__root = root def bound( self ) : return Box3f( V3f( -1 ), V3f( 1 ) ) def render( self, renderer ) : if self.__root : renderer.instanceBegin( "myLovelySphere", {} ) renderer.sphere( 1, -1, 1, 360, {} ) renderer.instanceEnd() renderer.procedural( InstanceInheritingProcedural( False ) ) else : renderer.instance( "myLovelySphere" ) def hash( self ) : h = MurmurHash() return h # test writing a rib r = IECoreRI.Renderer( "test/IECoreRI/output/instancing.rib" ) with WorldBlock( r ) : r.procedural( InstanceInheritingProcedural() ) rib = "".join( open( "test/IECoreRI/output/instancing.rib" ).readlines() ) self.failUnless( "ObjectInstance \"myLovelySphere\"" in rib ) # test doing an actual render r = IECoreRI.Renderer( "" ) r.display( "test", "ie", "rgba", { "driverType" : StringData( "ImageDisplayDriver" ), "handle" : StringData( "myLovelySphere" ), "quantize" : FloatVectorData( [ 0, 0, 0, 0 ] ), } ) with WorldBlock( r ) : r.concatTransform( M44f.createTranslated( V3f( 0, 0, -10 ) ) ) r.procedural( InstanceInheritingProcedural() ) image = ImageDisplayDriver.removeStoredImage( "myLovelySphere" ) e = ImagePrimitiveEvaluator( image ) r = e.createResult() e.pointAtUV( V2f( 0.5 ), r ) self.failUnless( r.floatPrimVar( image["R"] ) > 0.95 )
def test( self ) : r = IECoreRI.Renderer( self.outputFileName ) r.worldBegin() a = IECore.AttributeState() a.attributes["ri:subsurface"] = IECore.CompoundData( { "visibility" : IECore.StringData( "test" ), "meanfreepath" : IECore.Color3fData( IECore.Color3f( 1 ) ), "reflectance" : IECore.Color3fData( IECore.Color3f( 0 ) ), "refractionindex" : IECore.FloatData( 1.3 ), "scale" : IECore.FloatData( 0.1 ), "shadingrate" : IECore.FloatData( 10 ), } ) a.render( r ) r.worldEnd() l = "".join( file( self.outputFileName ).readlines() ) p1 = l.find( 'Attribute "visibility" "string subsurface" [ "test" ]' ) p2 = l.find( 'Attribute "subsurface"' ) self.assertNotEqual( p1, -1 ) self.assertNotEqual( p2, -1 ) self.assert_( p2 > p1 ) for a in ( '"color meanfreepath" [ 1 1 1 ]', '"color reflectance" [ 0 0 0 ]', '"float refractionindex" [ 1.3 ]', '"float scale" [ 0.1 ]', '"float shadingrate" [ 10 ]' ) : p3 = l.find( a ) self.assert_( p3 > p2 )
def testFlippingTransforms(self): """Check that flipping transforms are automatically compensated for.""" outputFileName = os.path.dirname( __file__) + "/output/testOrientation.tif" # render a single sided plane that shouldn't be backface culled, even though # the negative transform has reversed the winding order r = IECoreRI.Renderer("") r.display(outputFileName, "tiff", "rgba", {}) r.camera("main", {"resolution": IECore.V2iData(IECore.V2i(256))}) r.worldBegin() self.assertEqual(r.getAttribute("rightHandedOrientation"), IECore.BoolData(True)) r.setAttribute("doubleSided", IECore.BoolData(False)) r.concatTransform(IECore.M44f.createTranslated(IECore.V3f(0, 0, -5))) r.concatTransform(IECore.M44f.createScaled(IECore.V3f(-1, 1, 1))) self.assertEqual(r.getAttribute("rightHandedOrientation"), IECore.BoolData(False)) self.makePlane().render(r) r.worldEnd() # check that something appears in the output image i = IECore.Reader.create(outputFileName).read() e = IECore.PrimitiveEvaluator.create(i) result = e.createResult() a = e.A() e.pointAtUV(IECore.V2f(0.5, 0.5), result) self.assertEqual(result.floatPrimVar(a), 1)
def testAutomaticInstancingWithThreadedProcedurals( self ) : class PlaneProcedural( Renderer.Procedural ) : def __init__( self ) : Renderer.Procedural.__init__( self ) def bound( self ) : return Box3f( V3f( -10, -10, -0.01 ), V3f( 10, 10, 0.01 ) ) def render( self, renderer ) : MeshPrimitive.createPlane( Box2f( V2f( -10 ), V2f( 10 ) ) ).render( renderer ) def hash( self ) : h = MurmurHash() return h initThreads() r = IECoreRI.Renderer( "" ) with WorldBlock( r ) : r.setAttribute( "ri:automaticInstancing", True ) r.concatTransform( M44f.createTranslated( V3f( 0, 0, -20 ) ) ) for i in range( 0, 1000 ) : r.procedural( PlaneProcedural() )
def testAutomaticInstancingWithTransformMotionBlur( self ) : m = MeshPrimitive.createPlane( Box2f( V2f( -1 ), V2f( 1 ) ) ) r = IECoreRI.Renderer( "test/IECoreRI/output/instancing.rib" ) with WorldBlock( r ) : r.setAttribute( "ri:automaticInstancing", True ) with TransformBlock( r ): with MotionBlock( r, [ 0, 1 ] ) : r.setTransform( M44f.createTranslated( V3f( 0,0,0 ) ) ) r.setTransform( M44f.createTranslated( V3f( 1,0,0 ) ) ) m.render( r ) with TransformBlock( r ): with MotionBlock( r, [ 0, 1 ] ) : r.setTransform( M44f.createTranslated( V3f( 0,0,0 ) ) ) r.setTransform( M44f.createTranslated( V3f( 1,0,0 ) ) ) m.render( r ) rib = "".join( open( "test/IECoreRI/output/instancing.rib" ).readlines() ) self.assertEqual( rib.count( "ObjectBegin" ), 1 ) self.assertEqual( rib.count( "PointsGeneralPolygons" ), 1 ) self.assertEqual( rib.count( "ObjectInstance" ), 2 )
def testMotionBlurCameraRender(self): r = IECoreRI.Renderer("") r.display("test/IECoreRI/output/testCamera.tif", "tiff", "rgba", {}) with IECore.TransformBlock(r): with IECore.MotionBlock(r, [0, 1]): r.concatTransform( IECore.M44f.createTranslated(IECore.V3f(-0.2, 0, 1))) r.concatTransform( IECore.M44f.createTranslated(IECore.V3f(0.2, 0, 1))) r.camera("main", {"shutter": IECore.V2f(0, 1)}) with IECore.WorldBlock(r): IECore.MeshPrimitive.createPlane( IECore.Box2f(IECore.V2f(-0.1), IECore.V2f(0.1))).render(r) # check that something appears in the output image i = IECore.Reader.create("test/IECoreRI/output/testCamera.tif").read() dimensions = i.dataWindow.size() + IECore.V2i(1) index = dimensions.x * int(dimensions.y * 0.5) + int( dimensions.x * 0.5) self.assertTrue(i["A"][index] > 0) # something should be there self.assertTrue(i["A"][index] < 1) # but it should be blurry
def testImmediateGeometryOnly(self): r = IECoreRI.Renderer( "test/IECoreRI/output/testParameterisedProcedural.rib") r.worldBegin() t = TeapotProcedural() t.render(r, inAttributeBlock=False, withState=False, withGeometry=True, immediateGeometry=True) r.worldEnd() self.checkContents( "test/IECoreRI/output/testParameterisedProcedural.rib", [ "Geometry \"teapot\"", ], [ "AttributeBegin", "Attribute \"visibility\" \"int diffuse\" [ 1 ]", "AttributeEnd", ], ) self.assertEqual(t.renderStateCalled, False) self.assertEqual(t.boundCalled, False) self.assertEqual(t.renderCalled, True)
def testAttributes( self ) : tests = [ # format is : name value expectedRib getAttributeShouldWork ( "ri:shadingRate", FloatData( 2 ), "ShadingRate 2", True ), ( "ri:matte", BoolData( 0 ), "Matte 0", True ), ( "ri:matte", BoolData( 1 ), "Matte 1", True ), ( "user:whatever", StringData( "whatever" ), "Attribute \"user\" \"string whatever\" [ \"whatever\" ]", True ), ( "color", Color3fData( Color3f( 1, 2, 3 ) ), "Color [ 1 2 3 ]", False ), ( "opacity", Color3fData( Color3f( 0, 1, 0 ) ), "Opacity [ 0 1 0 ]", False ), ( "doubleSided", BoolData( False ), "Sides 1", False ), ( "ri:geometricApproximation:motionFactor", FloatData( 1 ), "GeometricApproximation \"motionfactor\" 1", False ), ( "ri:geometricApproximation:focusFactor", FloatData( 1 ), "GeometricApproximation \"focusfactor\" 1", False ), ( "ri:cull:hidden", IntData( 0 ), "Attribute \"cull\" \"int hidden\" [ 0 ]", False ), ( "name", StringData( "oioi" ), "Attribute \"identifier\" \"string name\" [ \"oioi\" ]", True ), ( "ri:trace:bias", FloatData( 2 ), "Attribute \"trace\" \"float bias\" [ 2 ]", True ), ( "user:myString", StringData( "wellHello" ), "Attribute \"user\" \"string myString\" [ \"wellHello\" ]", True ), ( "ri:automaticInstancing", BoolData( True ), "Attribute \"user\" \"int cortexAutomaticInstancing\" [ 1 ]", True ), ] for t in tests : r = IECoreRI.Renderer( "test/IECoreRI/output/testAttributes.rib" ) with WorldBlock( r ) : r.setAttribute( t[0], t[1] ) if t[3] : self.assertEqual( r.getAttribute( t[0] ), t[1] ) l = "".join( file( "test/IECoreRI/output/testAttributes.rib" ).readlines() ) l = " ".join( l.split() ) self.assert_( t[2] in l )
def testMotionBlurCameraRender(self): r = IECoreRI.Renderer("") r.display("test/IECoreRI/output/testCamera.tif", "tiff", "rgba", {}) with IECore.TransformBlock(r): with IECore.MotionBlock(r, [0, 1]): r.concatTransform( IECore.M44f.createTranslated(IECore.V3f(-0.2, 0, 1))) r.concatTransform( IECore.M44f.createTranslated(IECore.V3f(0.2, 0, 1))) r.camera("main", {"shutter": IECore.V2f(0, 1)}) with IECore.WorldBlock(r): IECore.MeshPrimitive.createPlane( IECore.Box2f(IECore.V2f(-0.1), IECore.V2f(0.1))).render(r) # check that something appears in the output image i = IECore.Reader.create("test/IECoreRI/output/testCamera.tif").read() e = IECore.PrimitiveEvaluator.create(i) result = e.createResult() e.pointAtUV(IECore.V2f(0.5, 0.5), result) self.assertTrue( result.floatPrimVar(e.A()) > 0) # something should be there self.assertTrue( result.floatPrimVar(e.A()) < 1) # but it should be blurry
def test(self): r = IECoreRI.Renderer("test/IECoreRI/output/test.rib") r.setOption("ri:searchpath:shader", StringData(os.environ["SHADER_PATH"])) r.setOption("ri:render:bucketorder", StringData("zigzag")) r.setOption("user:magicNumber", IntData(42)) r.setOption("ri:pixelSamples", V2iData(V2i(8, 8))) r.worldBegin() r.transformBegin() r.attributeBegin() self.loadShader("plastic").render(r) Reader.create("test/IECoreRI/data/sphere.cob").read().render(r) r.attributeEnd() r.transformEnd() r.worldEnd() l = "".join(file("test/IECoreRI/output/test.rib").readlines()).replace( "\n", "") self.failUnless( 'Option "render" "string bucketorder" [ "zigzag" ]' in l) self.failUnless('Option "user" "int magicNumber"' in l) self.failUnless('PixelSamples 8 8' in l)
def testSubDivs(self): r = IECoreRI.Renderer("test/IECoreRI/output/subdiv.rib") r.display("test", "idisplay", "rgba", {}) r.worldBegin() t = M44f() t.translate(V3f(0, 0, 10)) r.concatTransform(t) m = ObjectReader("test/IECoreRI/data/openSubDivCube.cob").read() m.render(r) r.worldEnd() l = "".join( file("test/IECoreRI/output/subdiv.rib").readlines()).replace( "\n", "") self.failUnless('SubdivisionMesh "catmull-clark" [ 4 4 4 4 4 ]' in l) self.failUnless('[ "interpolateboundary" ] [ 0 0 ] [ ] [ ]' in l) self.failUnless('vertex point P' in l) self.failUnless('facevarying float s' in l) self.failUnless('facevarying float t' in l)
def testGetTransform(self): r = IECoreRI.Renderer("test/IECoreRI/output/transform.rib") r.worldBegin() self.assertEqual(r.getTransform(), M44f()) self.assertEqual(r.getTransform("world"), M44f()) self.assertEqual(r.getTransform("object"), M44f()) r.transformBegin() t = M44f.createTranslated(V3f(1, 2, 3)) * M44f.createScaled( V3f(2, 1, 0)) * M44f.createRotated(V3f(20, 0, 90)) r.concatTransform(t) self.assert_(r.getTransform("object").equalWithAbsError(t, 0.000001)) self.assert_(r.getTransform().equalWithAbsError(t, 0.000001)) r.coordinateSystem("coordSys") self.assert_(r.getTransform("coordSys").equalWithAbsError(t, 0.000001)) r.transformEnd() self.assertEqual(r.getTransform(), M44f()) self.assertEqual(r.getTransform("world"), M44f()) self.assertEqual(r.getTransform("object"), M44f()) self.assert_(r.getTransform("coordSys").equalWithAbsError(t, 0.000001)) r.worldEnd()
def performTest( self, curvesPrimitive, testImage ) : r = IECoreRI.Renderer( "" ) r.camera( "main", { "projection" : IECore.StringData( "orthographic" ), "resolution" : IECore.V2iData( IECore.V2i( 256 ) ), "clippingPlanes" : IECore.V2fData( IECore.V2f( 1, 1000 ) ), "screenWindow" : IECore.Box2fData( IECore.Box2f( IECore.V2f( 0 ), IECore.V2f( 1 ) ) ), "shutter" : IECore.V2fData( IECore.V2f( 0, 1 ) ), } ) r.display( self.outputFileName, "tiff", "rgba", {} ) r.setOption( "ri:pixelSamples", IECore.V2iData( IECore.V2i( 10 ) ) ) r.worldBegin() r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) ) curvesPrimitive.render( r ) r.worldEnd() imageCreated = IECore.Reader.create( self.outputFileName ).read() expectedImage = IECore.Reader.create( testImage ).read() self.assertEqual( IECore.ImageDiffOp()( imageA=imageCreated, imageB=expectedImage, maxError=0.01 ), IECore.BoolData( False ) )
def testParameters( self ) : r = IECoreRI.Renderer( "test/IECoreRI/output/testCamera.rib" ) r.camera( "main", { "resolution" : IECore.V2iData( IECore.V2i( 1024, 200 ) ), "screenWindow" : IECore.Box2fData( IECore.Box2f( IECore.V2f( -1 ), IECore.V2f( 1 ) ) ), "cropWindow" : IECore.Box2fData( IECore.Box2f( IECore.V2f( 0.1, 0.1 ), IECore.V2f( 0.9, 0.9 ) ) ), "clippingPlanes" : IECore.V2fData( IECore.V2f( 1, 1000 ) ), "projection" : IECore.StringData( "perspective" ), "projection:fov" : IECore.FloatData( 45 ), "shutter" : IECore.V2fData( IECore.V2f( 0, 0.1 ) ), } ) r.worldBegin() r.worldEnd() l = "".join( file( "test/IECoreRI/output/testCamera.rib" ).readlines() ) l = " ".join( l.split() ) self.assert_( "Format 1024 200 1 " in l ) self.assert_( "ScreenWindow -1 1 -1 1" in l ) self.assert_( "CropWindow 0.1 0.9 0.1 0.9" in l ) self.assert_( ("Clipping 1 1000" in l) or ("Clipping 1 1e3" in l) ) self.assert_( "Projection \"perspective\" \"float fov\" [ 45 ]" in l ) self.assert_( "Shutter 0 0.1" in l )
def testOSLShader( self ) : r = IECoreRI.Renderer( "test/IECoreRI/output/test.rib" ) with WorldBlock( r ) : r.shader( "osl:surface", "test", { "intParam" : 1, "floatParam" : 2.5, "stringParam" : "sp", "vectorParam" : V3f( 1, 2, 3 ), "colorParam" : Color3f( 4, 5, 6 ), } ) del r rib = "".join( file( "test/IECoreRI/output/test.rib" ).readlines() ) self.assertEqual( len( self.nsiNodes( rib ) ), 1 ) self.assertTrue( '"shaderfilename" "string" 1 "test"' in rib ) self.assertTrue( '"stringParam" "string" 1 "sp"' in rib ) self.assertTrue( '"intParam" "int" 1 1' in rib ) self.assertTrue( '"floatParam" "float" 1 2.5' in rib ) self.assertTrue( '"vectorParam" "vector" 1 [ 1 2 3 ]' in rib ) self.assertTrue( '"colorParam" "color" 1 [ 4 5 6 ]' in rib ) self.assertTrue( 'Attribute "nsi" "string oslsurface"' in rib )
def testInstancingWithThreadedProcedurals(self): class InstanceMakingProcedural(Renderer.Procedural): def __init__(self, instanceName): Renderer.Procedural.__init__(self) self.__instanceName = instanceName def bound(self): return Box3f(V3f(-10), V3f(10)) def render(self, renderer): renderer.instanceBegin(self.__instanceName, {}) renderer.sphere(1, -1, 1, 360, {}) renderer.instanceEnd() renderer.instance(self.__instanceName) def hash(self): h = MurmurHash() return h initThreads() r = IECoreRI.Renderer("") with WorldBlock(r): r.concatTransform(M44f.createTranslated(V3f(0, 0, -20))) for i in range(0, 100): r.procedural(InstanceMakingProcedural("instance%d" % i))
def testNullShaderParameters( self ) : self.assertEqual( os.system( "shaderdl -o test/IECoreRI/shaders/types.sdl test/IECoreRI/shaders/types.sl" ), 0 ) r = IECoreRI.Renderer( "test/IECoreRI/output/test.rib" ) with WorldBlock( r ) : r.shader( "surface", "test/IECoreRI/shaders/types", { "f3" : None } )
def testDynamicLoadProcedural( self ) : r = IECoreRI.Renderer( "test/IECoreRI/output/test.rib" ) with WorldBlock( r ) : r.procedural( r.ExternalProcedural( "test.so", Box3f( V3f( 1, 2, 3 ), V3f( 4, 5, 6 ) ), { "ri:data" : "blah blah blah", "colorParm" : Color3f( 1, 2, 3 ), "stringParm" : "test", "floatParm" : 1.5, "intParm" : 2, } ) ) rib = "".join( file( "test/IECoreRI/output/test.rib" ).readlines() ) self.assertTrue( "Procedural \"DynamicLoad\"" in rib ) self.assertTrue( "test.so" in rib ) self.assertTrue( "\"blah blah blah" in rib ) self.assertTrue( "--colorParm 1 2 3" in rib ) self.assertTrue( "--stringParm test" in rib ) self.assertTrue( "--floatParm 1.5" in rib ) self.assertTrue( "--intParm 2" in rib ) self.assertTrue( "[ 1 4 2 5 3 6 ]" in rib )
def testFloat3PrimitiveVariables( self ) : self.assertEqual( os.system( "shaderdl -o test/IECoreRI/shaders/types.sdl test/IECoreRI/shaders/types.sl" ), 0 ) r = IECoreRI.Renderer( "test/IECoreRI/output/test.rib" ) with WorldBlock( r ) : r.shader( "surface", "test/IECoreRI/shaders/types", { "f3" : V3fData( V3f( 4, 5, 6 ) ) } ) r.mesh( IntVectorData( [ 4, 4 ] ), IntVectorData( [ 0, 1, 2, 3, 3, 2, 4, 5 ] ), "linear", { "P" : PrimitiveVariable( PrimitiveVariable.Interpolation.Vertex, V3fVectorData( [ V3f( 0, 0, 0 ), V3f( 0, 1, 0 ), V3f( 1, 1, 0 ), V3f( 1, 0, 0 ), V3f( 2, 1, 0 ), V3f( 2, 0, 0 ) ] ) ), "f3" : PrimitiveVariable( PrimitiveVariable.Interpolation.Uniform, V3fVectorData( [ V3f( 0 ), V3f( 1 ) ] ), ) } ) l = "".join( file( "test/IECoreRI/output/test.rib" ).readlines() ).replace( "\n", "" ) self.failUnless( "\"uniform float[3] f3\" [ 0 0 0 1 1 1 ]" in l )
def testSubDivTags( self ) : r = IECoreRI.Renderer( "test/IECoreRI/output/subdiv.rib" ) r.display( "test", "idisplay", "rgba", {} ) r.worldBegin() t = M44f() t.translate( V3f( 0, 0, 10 ) ) r.concatTransform( t ) m = ObjectReader( "test/IECoreRI/data/openSubDivCube.cob" ).read() m["tags"] = PrimitiveVariable( PrimitiveVariable.Interpolation.Constant, CompoundData( { "names" : StringVectorData( [ "interpolateboundary", "facevaryinginterpolateboundary" ] ), "nArgs" : IntVectorData( [ 1, 0, 1, 0 ] ), "floats" : FloatVectorData( [] ), "integers" : IntVectorData( [ 1, 0 ] ), } ) ) m.render( r ) r.worldEnd() l = "".join( file( "test/IECoreRI/output/subdiv.rib" ).readlines() ).replace( "\n", "" ) self.failUnless( 'SubdivisionMesh "catmull-clark" [ 4 4 4 4 4 ]' in l ) self.failUnless( '[ "interpolateboundary" "facevaryinginterpolateboundary" ] [ 1 0 1 0 ] [ 1 0 ] [ ]' in l ) self.failUnless( 'vertex point P' in l ) self.failUnless( 'facevarying float[3] st' in l )
def testRenderDirectToImagePrimitive(self): r = IECoreRI.Renderer("") # write one image direct to memory r.display( "test", "ie", "rgba", { "driverType": IECore.StringData("ImageDisplayDriver"), "handle": IECore.StringData("myLovelySphere"), "quantize": IECore.FloatVectorData([0, 0, 0, 0]), }) # write another to disk the usual way r.display("+test/IECoreRI/output/sphere.tif", "tiff", "rgba", { "quantize": IECore.FloatVectorData([0, 0, 0, 0]), }) with IECore.WorldBlock(r): r.concatTransform( IECore.M44f.createTranslated(IECore.V3f(0, 0, -5))) r.sphere(1, -1, 1, 360, {}) # check that they're the same i = IECore.ImageDisplayDriver.removeStoredImage("myLovelySphere") i2 = IECore.TIFFImageReader("test/IECoreRI/output/sphere.tif").read() i.blindData().clear() i2.blindData().clear() self.failIf(IECore.ImageDiffOp()(imageA=i, imageB=i2, maxError=0.001).value)
def testMultipleCameraRIB( self ) : r = IECoreRI.Renderer( "test/IECoreRI/output/testCamera.rib" ) with IECore.TransformBlock( r ) : r.setTransform( IECore.M44f.createTranslated( IECore.V3f( 1, 2, 3 ) ) ) r.camera( "first", { "projection" : IECore.StringData( "perspective" ), "projection:fov" : IECore.FloatData( 45 ), } ) with IECore.TransformBlock( r ) : r.setTransform( IECore.M44f.createTranslated( IECore.V3f( 3, 4, 5 ) ) ) r.camera( "second", { "projection" : IECore.StringData( "perspective" ), "projection:fov" : IECore.FloatData( 50 ), } ) with IECore.WorldBlock( r ) : pass l = "".join( file( "test/IECoreRI/output/testCamera.rib" ).readlines() ) l = " ".join( l.split() ) self.assertTrue( "Projection \"perspective\" \"float fov\" [ 45 ]" in l ) self.assertTrue( "Camera \"first\"" in l ) self.assertTrue( "Projection \"perspective\" \"float fov\" [ 50 ]" in l ) self.assertTrue( "Camera \"second\"" in l ) self.assertEqual( l.count( "Camera" ), 2 )
def testTwoOSLShaders( self ) : r = IECoreRI.Renderer( "test/IECoreRI/output/test.rib" ) with WorldBlock( r ) : r.shader( "osl:surface", "test", { "intParam" : 1, } ) with AttributeBlock( r ) : r.shader( "osl:surface", "test", { "intParam" : 2, } ) del r rib = "".join( file( "test/IECoreRI/output/test.rib" ).readlines() ) nodes = self.nsiNodes( rib ) self.assertEqual( len( nodes ), 2 ) # Handles should be unique self.assertEqual( len( set( x[0] for x in nodes ) ), 2 ) # Both node types should be shader self.assertEqual( set( x[1] for x in nodes ), { "shader" } )
def testEditShader( self ) : # start an editable render with one light colour r = IECoreRI.Renderer( "" ) r.setOption( "editable", True ) r.display( "test", "ie", "rgba", { "driverType" : IECore.StringData( "ImageDisplayDriver" ), "handle" : IECore.StringData( "myLovelySphere" ), "quantize" : IECore.FloatVectorData( [ 0, 0, 0, 0 ] ), } ) with IECore.WorldBlock( r ) : r.light( "pointlight", "myLovelyLight", {} ) with IECore.AttributeBlock( r ) : r.setAttribute( "name", "/sphere" ) r.concatTransform( IECore.M44f.createTranslated( IECore.V3f( 0, 0, -5 ) ) ) r.shader( "surface", "matte", { "Kd" : 1 } ) r.sphere( 1, -1, 1, 360, {} ) # give it a bit of time to finish time.sleep( 1 ) # record the colour produced by the first render i = IECore.ImageDisplayDriver.storedImage( "myLovelySphere" ) e = IECore.ImagePrimitiveEvaluator( i ) er = e.createResult() e.pointAtUV( IECore.V2f( 0.5 ), er ) initialColor = IECore.Color3f( er.floatPrimVar( i["R"] ), er.floatPrimVar( i["G"] ), er.floatPrimVar( i["B"] ) ) # make an edit to the shader and wait for it to take hold with IECore.EditBlock( r, "attribute", { "scopename" : "/sphere" } ) : r.shader( "surface", "matte", { "Kd" : 0.5 } ) time.sleep( 1 ) # check the ratio of the two colours is as expected. i = IECore.ImageDisplayDriver.storedImage( "myLovelySphere" ) e = IECore.ImagePrimitiveEvaluator( i ) er = e.createResult() e.pointAtUV( IECore.V2f( 0.5 ), er ) newColor = IECore.Color3f( er.floatPrimVar( i["R"] ), er.floatPrimVar( i["G"] ), er.floatPrimVar( i["B"] ) ) self.assertEqual( newColor / initialColor, IECore.Color3f( .5 ) )
def test( self ) : r = IECoreRI.Renderer( "test/IECoreRI/output/testDoubleSided.rib" ) self.assertEqual( r.getAttribute( "doubleSided" ), IECore.BoolData( True ) ) r.setAttribute( "doubleSided", IECore.BoolData( False ) ) self.assertEqual( r.getAttribute( "doubleSided" ), IECore.BoolData( False ) ) del r l = "".join( file( "test/IECoreRI/output/testDoubleSided.rib" ).readlines() ) self.assert_( "Sides 1" in l ) r = IECoreRI.Renderer( "test/IECoreRI/output/testDoubleSided.rib" ) r.setAttribute( "doubleSided", IECore.BoolData( True ) ) del r l = "".join( file( "test/IECoreRI/output/testDoubleSided.rib" ).readlines() ) self.assert_( "Sides 2" in l )
def test( self ) : r1 = IECoreRI.Renderer( "test/IECoreRI/output/contextOne.rib" ) r2 = IECoreRI.Renderer( "test/IECoreRI/output/contextTwo.rib" ) self.assertEqual( r1.getAttribute( "doubleSided" ), IECore.BoolData( True ) ) self.assertEqual( r2.getAttribute( "doubleSided" ), IECore.BoolData( True ) ) r1.setAttribute( "doubleSided", IECore.BoolData( False ) ) self.assertEqual( r1.getAttribute( "doubleSided" ), IECore.BoolData( False ) ) self.assertEqual( r2.getAttribute( "doubleSided" ), IECore.BoolData( True ) ) r1.setAttribute( "doubleSided", IECore.BoolData( True ) ) self.assertEqual( r1.getAttribute( "doubleSided" ), IECore.BoolData( True ) ) self.assertEqual( r2.getAttribute( "doubleSided" ), IECore.BoolData( True ) ) r2.setAttribute( "doubleSided", IECore.BoolData( False ) ) self.assertEqual( r1.getAttribute( "doubleSided" ), IECore.BoolData( True ) ) self.assertEqual( r2.getAttribute( "doubleSided" ), IECore.BoolData( False ) )