func Test_SimpleExample(t *testing.T) { Convey("Simple Example", t, func() { pipe := DefaultFilePipe() /* use a custom unique generator with a prefix for the light handles */ lights := NewPrefixLightUniqueGenerator("light_") mgr := NewHandleManager(nil, lights, nil) ctx := NewContext(pipe, mgr, &Configuration{PrettyPrint: true}) ri := RI(ctx) ri.Begin("output/exampleSimple.rib") ri.Display("sphere.tif", "file", "rgb") ri.Format(320, 240, 1) ri.Projection(PERSPECTIVE, RtToken("fov"), RtFloat(30)) ri.Translate(0, 0, 6) ri.WorldBegin() ri.LightSource("ambientlight", RtToken("intensity"), RtFloat(0.5)) ri.LightSource("distantlight", RtToken("intensity"), RtFloat(1.2), RtToken("from"), RtIntArray{0, 0, -6}, RtToken("to"), RtIntArray{0, 0, 0}) ri.Color(RtColor{1, 0, 0}) ri.Sphere(1, -1, 1, 360) ri.WorldEnd() So(ri.End(), ShouldBeNil) /* output gathered stats */ p := pipe.GetByName(PipeToStats{}.Name()) So(p, ShouldNotBeNil) s, ok := p.(*PipeToStats) So(s, ShouldNotBeNil) So(ok, ShouldBeTrue) p = pipe.GetByName(PipeTimer{}.Name()) So(p, ShouldNotBeNil) t, ok := p.(*PipeTimer) So(t, ShouldNotBeNil) So(ok, ShouldBeTrue) fmt.Printf("%s%s", s, t) }) Convey("Simple Example Flattened", t, func() { pipe := DefaultFilePipe() ctx := NewContext(pipe, nil, &Configuration{PrettyPrint: false}) ri := RI(ctx) ri.Begin("output/exampleSimpleFlattened.rib") f, err := os.Open("output/exampleSimple.rib") So(err, ShouldBeNil) defer f.Close() So(ri.ParseRIB(f), ShouldBeNil) ri.End() }) }
/* go test -bench=. */ func Benchmark_SimpleExampleNumberHandlers(b *testing.B) { for i := 0; i < b.N; i++ { ri, _ := DefaultPipeline(nil) ri.Begin("simple.rib") ri.Display("sphere.tif", "file", "rgb") ri.Format(320, 240, 1) ri.Projection(PERSPECTIVE, RtToken("fov"), RtFloat(30)) ri.Translate(0, 0, 6) ri.WorldBegin() ri.LightSource("ambientlight", RtToken("intensity"), RtFloat(0.5)) ri.LightSource("distantlight", RtToken("intensity"), RtFloat(1.2), RtToken("from"), RtIntArray{0, 0, -6}, RtToken("to"), RtIntArray{0, 0, 0}) ri.Color(RtColor{1, 0, 0}) ri.Sphere(1, -1, 1, 360) ri.WorldEnd() ri.End() } }
func main() { ri, _ := rigo.DefaultPipeline(&rigo.Configuration{PrettyPrint: true}) ri.Begin("./scene.rib") ri.ArchiveRecord("structure", "Scene regressions/001") ri.ArchiveRecord("structure", "Regression 001") ri.Display("./scene.tif", "file", "rgb") ri.Format(300, 300, 1) ri.Translate(0, 0, 6) ri.WorldBegin() ri.Color(RtColor{1, 0, 0}) ri.Sphere(1, -1, 1, 360) ri.WorldEnd() if err := ri.End(); err != nil { fmt.Fprintf(os.Stderr, "End() error -- %v\n", err) os.Exit(1) } }
func Test_HandleCallbacks(t *testing.T) { lighthandle := func(name RtName, light RtLightHandle) { fmt.Printf("LightHandle -- %s %s\n", name, light) } Convey("Handle callbacks pipelining", t, func() { pipe := NewPipe() callback := new(PipeHookHandleCallback) callback.LightHandler = lighthandle pipe.Append(callback) mgr := NewHandleManager(nil, NewPrefixLightUniqueGenerator("light_"), nil) ri := RI(NewContext(pipe, mgr, nil)) So(ri.Begin("output/filters-simple.rib"), ShouldBeNil) ri.Display("sphere.tif", "file", "rgb") ri.Format(320, 240, 1) ri.Projection(PERSPECTIVE, RtToken("fov"), RtFloat(30)) ri.Translate(0, 0, 6) ri.WorldBegin() ambient, _ := ri.LightSource("ambientlight", RtToken("intensity"), RtFloat(0.5)) So(ambient, ShouldNotBeNil) ri.LightSource("distantlight", RtToken("intensity"), RtFloat(1.2), RtToken("from"), RtIntArray{0, 0, -6}, RtToken("to"), RtIntArray{0, 0, 0}) ri.Illuminate(ambient, false) ri.Color(RtColor{1, 0, 0}) ri.Sphere(1, -1, 1, 360) ri.WorldEnd() So(ri.End(), ShouldBeNil) }) }
func Benchmark_SimpleExampleUniqueHandlers(b *testing.B) { for i := 0; i < b.N; i++ { pipe := NullPipe() mgr := NewHandleManager(nil, NewLightUniqueGenerator(), nil) ctx := NewContext(pipe, mgr, nil) ri := RI(ctx) ri.Begin("simple.rib") ri.Display("sphere.tif", "file", "rgb") ri.Format(320, 240, 1) ri.Projection(PERSPECTIVE, RtToken("fov"), RtFloat(30)) ri.Translate(0, 0, 6) ri.WorldBegin() ri.LightSource("ambientlight", RtToken("intensity"), RtFloat(0.5)) ri.LightSource("distantlight", RtToken("intensity"), RtFloat(1.2), RtToken("from"), RtIntArray{0, 0, -6}, RtToken("to"), RtIntArray{0, 0, 0}) ri.Color(RtColor{1, 0, 0}) ri.Sphere(1, -1, 1, 360) ri.WorldEnd() ri.End() } }
func Test_RISExamples(t *testing.T) { Convey("RIS Examples", t, func() { Convey("PxrConstant -- bxdf shader", func() { cuser, err := user.Current() So(err, ShouldBeNil) pipe := DefaultFilePipe() So(pipe, ShouldNotBeNil) ctx := NewContext(pipe, nil, &Configuration{PrettyPrint: true}) ri := RI(ctx) ri.Begin("output/risBxdfPxrConstant.rib") ri.ArchiveRecord("structure", "Scene Bxdf Constant") ri.ArchiveRecord("structure", "Creator %s", Author) ri.ArchiveRecord("structure", "CreationDate %s", time.Now()) ri.ArchiveRecord("structure", "For %s", cuser.Username) ri.ArchiveRecord("structure", "Frames 1") ri.Display("risbxdf_sphere.tif", "file", "rgb") ri.Format(320, 240, 1) ri.PixelFilter(GaussianFilter, 4, 4) ri.Imager("background", RtToken("color color"), RtColor{.6, .6, .6}, RtToken("float alpha"), RtFloat(1)) ri.Projection(PERSPECTIVE, RtToken("fov"), RtFloat(30)) ri.Translate(0, 0, 6) ri.WorldBegin() ri.Color(RtColor{1, 0, 0}) /* wrap the context with the RIS interface */ ris := RIS(ctx) /* first we setup a pattern RIS */ pattern, err := ris.Pattern("PxrHSL", "-") So(err, ShouldBeNil) So(pattern, ShouldNotBeNil) So(pattern.Name(), ShouldEqual, "PxrHSL") w := pattern.Widget("inputRGB") So(w, ShouldNotBeNil) So(w.SetValue(RtColor{0, 0, 0.3}), ShouldBeNil) ri.Pattern(pattern.Name(), pattern.Handle(), RtToken("inputRGB"), RtColor{0, 0, 0.3}) /* load the PxrConstant bxdf shader, $RMANTREE/lib/RIS/bxdf/Args/PxrConstant.args is parsed * for the constant shader. */ constant, err := ris.Bxdf("PxrConstant", "-") So(err, ShouldBeNil) So(constant, ShouldNotBeNil) /* we want to manipulate the emit color of the shader so we * ask the shader for the widget interface */ w = constant.Widget("emitColor") So(w, ShouldNotBeNil) /* set the color via the widget; SetValue(Rter) */ So(w.SetValue(RtColor{0.3, 0.2, 0.1}), ShouldBeNil) /* we know it's a color so we can convert directly to the * RtColorWidget concrete type */ cw, ok := w.(*RtColorWidget) So(ok, ShouldBeTrue) So(cw, ShouldNotBeNil) /* we can directly set the color via our RtColorWidget : * overriding our previous SetValue */ So(cw.Set(RtColor{0.1, 0.2, 0.3}), ShouldBeNil) /* As the widget (w & cw) is linked to the shader (constant), we can override * what we set with the widget directly at the shader */ So(constant.SetValue(RtToken("emitColor"), RtColor{0.45, 0.45, 0.45}), ShouldBeNil) /* The widget should be in sync with what we set at the shader */ So(cw.Value().Equal(RtColor{0.45, 0.45, 0.45}), ShouldBeTrue) /* Here we over the shader again by including the emitColor inline; the constant.Handle() * includes the handle created for the shader */ ri.Bxdf("PxrConstant", constant.Handle(), RtToken("color emitColor"), RtColor{1, 0.25, 0.25}) /* now instead we can reference the pattern we set earlier and replace the emitColor with a reference */ refid := pattern.ReferenceOutput("resultRGB") So(refid, ShouldEqual, fmt.Sprintf("%s:resultRGB", string(pattern.Handle()))) So(constant.SetReferencedValue("emitColor", refid), ShouldBeNil) /* this is another way of writing our shader : using the emitColor that we actually set above */ ri.Bxdf(constant.Name(), constant.Handle()) ri.Sphere(1, -1, 1, 360) ri.WorldEnd() So(ri.End(), ShouldBeNil) /* gather and print the statistics and time the * pipe took */ p := pipe.GetByName(PipeToStats{}.Name()) So(p, ShouldNotBeNil) s, ok := p.(*PipeToStats) So(s, ShouldNotBeNil) So(ok, ShouldBeTrue) p = pipe.GetByName(PipeTimer{}.Name()) So(p, ShouldNotBeNil) t, ok := p.(*PipeTimer) So(t, ShouldNotBeNil) So(ok, ShouldBeTrue) fmt.Printf("%s%s", s, t) }) }) }
func Test_ExampleD14(t *testing.T) { Convey("Example D1.4", t, func() { sgroup := RtToken("shadinggroup") frames := 2 cuser, err := user.Current() So(err, ShouldBeNil) ri, pipe := DefaultPipeline(&Configuration{PrettyPrint: true}) ri.Begin("output/exampleD14.rib") ri.ArchiveRecord("structure", "Scene Bouncing Ball") ri.ArchiveRecord("structure", "Creator %s", Author) ri.ArchiveRecord("structure", "CreationDate %s", time.Now()) ri.ArchiveRecord("structure", "For %s", cuser.Username) ri.ArchiveRecord("structure", "Frames %d", frames) ri.ArchiveRecord("structure", "Shaders PIXARmarble, PIXARwood, MyUserShader") ri.ArchiveRecord("structure", "CapabilitiesNeeded ShadingLanguage Displacements") ri.Declare("d", "uniform point") ri.Declare("squish", "uniform float") ri.Option("limits", RtToken("bucketsize"), RtIntArray{6, 6}) ri.Option("limits", RtToken("gridsize"), RtIntArray{18}) ri.Format(1024, 768, 1) ri.Projection(PERSPECTIVE) ri.Clipping(10, 1000.0) ri.FrameBegin(1) ri.ArchiveRecord("structure", "Shaders PIXARmarble, PIXARwood") ri.ArchiveRecord("structure", "CameraOrientation %.1f %.1f %.1f %.1f %.1f %.1f", 10., 10., 10., 0., 0., 0.) ri.Transform(RtMatrix{.707107, -.408248, 0.57735, 0, 0, .816497, -.57735, 0, -.707107, -.408248, -.57735, 0, 0, 0, 17.3205, 1}) ri.WorldBegin() ri.AttributeBegin() ri.Attribute("identifier", RtToken("name"), RtString("myball")) ri.Displacement("MyUserShader", RtToken("squish"), RtInt(5)) ri.AttributeBegin() ri.Attribute("identifier", sgroup, RtStringArray{"tophalf"}) ri.Surface("plastic") ri.Sphere(.5, -.5, 0, 360) ri.AttributeEnd() ri.AttributeBegin() ri.Attribute("identifier", sgroup, RtStringArray{"bothalf"}) ri.Surface("PIXARmarble") ri.Sphere(.5, 0, .5, 360) ri.AttributeEnd() ri.AttributeEnd() ri.AttributeBegin() ri.Attribute("identifier", RtToken("name"), RtStringArray{"floor"}) ri.Surface("PIXARwood", RtToken("roughness"), RtFloatArray{.3}, RtToken("d"), RtIntArray{1}) ri.Comment("geometry for floor") ri.Polygon(4, RtToken("P"), RtFloatArray{-100, 0, -100, -100, 0, 100, 100, 0, 100, 10, 0, -100}) ri.AttributeEnd() ri.WorldEnd() ri.FrameEnd() ri.FrameBegin(2) ri.ArchiveRecord("structure", "Shaders PIXARwood, PIXARmarbles") ri.ArchiveRecord("structure", "CameraOrientation %.1f %.1f %.1f %.1f %.1f %.1f", 10., 20., 10., 0., 0., 0.) ri.Transform(RtMatrix{.707107, -.57735, -.408248, 0, 0, .57735, -.815447, 0, -.707107, -.57735, -.408248, 0, 0, 0, 24.4949, 1}) ri.WorldBegin() ri.AttributeBegin() ri.Attribute("identifier", RtToken("name"), RtStringArray{"myball"}) ri.AttributeBegin() ri.Attribute("identifier", sgroup, RtStringArray{"tophalf"}) ri.Surface("PIXARmarble") ri.ShadingRate(.1) ri.Sphere(.5, 0, .5, 360) ri.AttributeEnd() ri.AttributeBegin() ri.Attribute("identifier", sgroup, RtStringArray{"bothalf"}) ri.Surface("plastic") ri.Sphere(.5, -.5, 0, 360) ri.AttributeEnd() ri.AttributeEnd() ri.AttributeBegin() ri.Attribute("identifier", RtToken("name"), RtStringArray{"floor"}) ri.Surface("PIXARwood", RtToken("roughness"), RtFloatArray{.3}, RtToken("d"), RtIntArray{1}) ri.Comment("geometry for floor") ri.Polygon(4, RtToken("P"), RtFloatArray{-100, 0, -100, -100, 0, 100, 100, 0, 100, 10, 0, -100}) ri.AttributeEnd() ri.WorldEnd() ri.FrameEnd() So(ri.End(), ShouldBeNil) /* output gathered stats */ p := pipe.GetByName(PipeToStats{}.Name()) So(p, ShouldNotBeNil) s, ok := p.(*PipeToStats) So(s, ShouldNotBeNil) So(ok, ShouldBeTrue) p = pipe.GetByName(PipeTimer{}.Name()) So(p, ShouldNotBeNil) t, ok := p.(*PipeTimer) So(t, ShouldNotBeNil) So(ok, ShouldBeTrue) fmt.Printf("%s%s", s, t) }) }