Esempio n. 1
0
func Test_SimpleExampleWithConditionals(t *testing.T) {

	Convey("Simple Example with Conditionals", 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/exampleConditionals.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.Option("user", RtToken("string renderpass"), RtString("red"))
		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.IfBegin("$user:renderpass == 'red'")
		ri.Color(RtColor{1, 0, 0})
		ri.ElseIf("$user:renderpass == 'blue'")
		ri.Color(RtColor{0, 0, 1})
		ri.Else()
		ri.Color(RtColor{0, 1, 0})
		ri.IfEnd()

		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)
	})
}
Esempio n. 2
0
/* 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()
	}
}
Esempio n. 3
0
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)
	}
}
Esempio n. 4
0
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)

	})
}
Esempio n. 5
0
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()
	}
}
Esempio n. 6
0
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)
		})
	})
}