Example Usage

This is an example of the usage of my research and development version of rigo, my pure go implementation of Pixar’s RenderMan Interface.

> go get gitlab.com/mae.earth/rigo
Raw go file

package main

import (
	"gitlab.com/mae.earth/rigo/ri"
	"gitlab.com/mae.earth/rigo"
)		


func main() {

	ctx := rigo.New()

	ctx.Begin("test.rib")	

	ctx.ArchiveRecord(ri.STRUCTURE,ri.RIB)

	resolution := ctx.Declare("resolution","constant float[2]")
	ctx.Declare("baseColor","color")
	
	/* inline rib archive */
	archive1 := ctx.ArchiveBegin("lighting")
		ctx.AttributeBegin()
			ctx.ArchiveRecord(ri.COMMENT,"this is our lights")
			ctx.Translate(5,5,5)
		 	ctx.Light("PxrEnvDayLight","light1") 
			ctx.Geometry("envsphere",resolution,[2]float64{1024,1024})
		ctx.AttributeEnd()
		ctx.AttributeBegin()
			ctx.Translate(-5,5,-5)
			ctx.Light("PxrEnvDayLight","light2")
			ctx.Geometry("envsphere",resolution,[2]float64{1024,1024})
		ctx.AttributeEnd()
	ctx.ArchiveEnd()


	ctx.Display("2_spheres.exr","openexr","rgba")
	ctx.Format(640,480,1.0)

	ctx.Projection("perspective","float fov",30.0)
	ctx.Hider("raytrace","int maxsamples",64,"int minsamples",16,"int incremental",100,"float[4] aperture",[4]float64{0,0,0,0})
	ctx.Integrator("PxrPathTracer","production")

	ctx.Shutter(0,1)
			
	ctx.System("date; echo starting job ^{Option:user:jobid}")

	ctx.WorldBegin()
				
	object := ctx.ObjectBegin()
			ctx.Sphere(1,-1,1,360)
		ctx.ObjectEnd()

		ctx.ReadArchive("test2.rib",nil)
		ctx.Translate(0,0,10)
		ctx.ReadArchive(archive1,nil)
		ctx.Illuminate("light1",true)
		ctx.Illuminate("light2",true)
		ctx.AttributeBegin()
			ctx.MotionBegin(0.0,0.5,1.0)
				ctx.Translate(1,0,0)
				ctx.Translate(0,0,0)
				ctx.Translate(-1,0,0)
			ctx.MotionEnd()
			ctx.Bxdf("PxrDisney","surface","baseColor",[]float64{1,0,0})
			ctx.ObjectInstance(object)
		ctx.AttributeEnd()
		ctx.AttributeBegin()
			ctx.Bxdf("PxrDisney","surface_2","color baseColor",[]float64{0,1,0})
			ctx.Sphere(1,-1,1,360)		
		ctx.AttributeEnd()	
	ctx.WorldEnd()	

	ctx.System("date; echo rendered job ^{Option:user:jobid}")

	for {
		if ctx.RicGetProgress() == 100 {
			break
		}
	}

	ctx.End()

	
	ctx = rigo.New()

	ctx.Begin("test2.rib")
		ctx.ArchiveRecord("structure","RenderMan RIB")
		ctx.ReadArchive(archive1,nil)
	ctx.End()
	
	ctx = rigo.New()

	ctx.Begin("driver.rib")
		ctx.ArchiveRecord("structure","RenderMan RIB")
			
		ctx.Option("ribparse","string varsubst","^") 
		ctx.Option("user","string jobid","2_spheres")
	ctx.End()

}

Running this go program will generate three rib files; driver.rib, test.rib and test2.rib. We can concat driver.rib and test.rib togeather to get a rib file that can be rendered.

> cat driver.rib test.rib > out.rib

##RenderMan RIB
Option "ribparse" "string varsubst" ["^"]
Option "user" "string jobid" ["2_spheres"]
##RenderMan RIB
Declare "resolution" "constant float[2]" 
Declare "baseColor" "color" 
ArchiveBegin "lighting" 
	AttributeBegin
# this is our lights
		Translate 5 5 5 
		Light "PxrEnvDayLight" "light1" 
		Geometry "envsphere" "constant float[2] resolution" [1024 1024]
	AttributeEnd
	AttributeBegin
		Translate -5 5 -5 
		Light "PxrEnvDayLight" "light2" 
		Geometry "envsphere" "constant float[2] resolution" [1024 1024]
	AttributeEnd
ArchiveEnd
Display "test.exr" "openexr" "rgba" 
Format 640 480 1 
Projection "perspective" "float fov" [30]
Hider "raytrace" "int maxsamples" [64] "int minsamples" [16] "int incremental" [100] "float[4] aperture" [0 0 0 0]
Integrator "PxrPathTracer" "production" 
Shutter 0 1 
System "date; echo starting job ^{Option:user:jobid}" 
WorldBegin
	ObjectBegin "object#1" 
		Sphere 1 -1 1 360 
	ObjectEnd
	ReadArchive "test2.rib" 
	Translate 0 0 10 
	ReadArchive "lighting" 
	Illuminate "light1" 1 
	Illuminate "light2" 1 
	AttributeBegin
		MotionBegin [0 .5 1] 
			Translate 1 0 0 
			Translate 0 0 0 
			Translate -1 0 0 
		MotionEnd
		Bxdf "PxrDisney" "surface" "baseColor" [1 0 0]
		ObjectInstance "object#1" 
	AttributeEnd
	AttributeBegin
		Bxdf "PxrDisney" "surface_2" "color baseColor" [0 1 0]
		Sphere 1 -1 1 360 
	AttributeEnd
WorldEnd
System "date; echo rendered job ^{Option:user:jobid}" 

Now we can render our image.

> render -d it -progress -maxsamples 512 out.rib

r/2_spheres.png