Rendering学習日記

日々、3DCGの世界は進歩しています。勉強して理解したことをまとめていきます。RenderMan互換レンダラーやグローバル・イルミネーション。いろんなことに好奇心を持って、面白くなる。目指せShader書き!!
ありがとうございます。

PythonからRenderMan その13

ドーナツ作り。以前の記事を書き換えたものです。ありがとうございます。

#proc_torus2_pr.py
#set PYTHONPATH=C:\Python25;C:\Python\Scripts;%RMANTREE%\bin
import getpass
import time
# import the python renderman library
import prman

ri = prman.Ri() # create an instance of the RenderMan interface
ri.Option("rib", {"string asciistyle": "indented"})

filename = "proc_geom.rib"

ri.Begin(ri.RENDER)

def TorusWave(ri,nwaves,thetamax) :
if(nwaves < 1) :
print "need positive number of waves"
return
innerrad = 2.0/(8.0 * nwaves +2)
ri.Rotate(90.0,1.0,0.0,0.0)
ri.Sphere(innerrad,-innerrad,0,thetamax)
outerrad =0.0
for wave in range(1,nwaves) :
outerrad=outerrad+(innerrad*2)
ri.Torus(outerrad,innerrad,0.0,180.0,thetamax)
outerrad=outerrad+(innerrad*2)
ri.Torus(outerrad,innerrad,180.0,360.0,thetamax)


#ArchiveRecord is used to add elements to the rib stream in this case comments
# note the function is overloaded so we can concatinate output
ri.ArchiveRecord(ri.COMMENT, 'File ' +filename)
ri.ArchiveRecord(ri.COMMENT, "Created by " + getpass.getuser())
ri.ArchiveRecord(ri.COMMENT, "Creation Date: " +time.ctime(time.time()))

# now we add the display element using the usual elements
# FILENAME DISPLAY Type Output format
ri.Display("proc_torus2.png", "file", "rgb")
ri.Format(512, 384, -1.0)
ri.Projection(ri.PERSPECTIVE,{ri.FOV:30})

# now we start our world
colours ={
"red":[1,0,0],
"white":[1,1,1],
"green":[0,1,0],
"blue":[0,0,1],
"black":[0,0,0],
"yellow":[1,1,0]
}

# start our world
ri.WorldBegin()
ri.LightSource("distantlight", {ri.HANDLEID: "1","to":[0,0,1]})
ri.LightSource("ambientlight", {ri.HANDLEID: "2", "intensity":[0.4]})

ri.Translate(0,0,9) #move the global view position
ri.Surface("plastic")

ri.TransformBegin()
ri.Rotate(40,1,0,0)
ri.Color(colours["red"])
ri.Attribute ("identifier",{"name": "Wave1"})
TorusWave(ri,8,360.0)
ri.TransformEnd()

ri.TransformBegin()
ri.Rotate(55,1,0,0)
ri.Color(colours["green"])
ri.Translate(2.2,0,0)
ri.Attribute( "identifier",{ "name" :"Wave2"})
TorusWave(ri,8,360.0)
ri.TransformEnd()

ri.TransformBegin()
ri.Rotate(35,1,0,0)
ri.Color(colours["blue"])
ri.Translate(-2.2,0,0)
ri.Attribute("identifier",{ "name" : "Wave3"})
TorusWave(ri,8,360.0)
ri.TransformEnd()
#end our world

ri.WorldEnd()
ri.End()
  • -
  • -

PythonからRenderManシーン記述

レイトレーシングを使わないで、それらしく見せる反射トリックですね。
レンダリングは速いです。
過去のPixarのC言語によるシーン記述をPythonで書き換えてみました。
まだまだ課題がありますが、チャレンジですね。ありがとうございます。
generate_scn.jpg
#generate_scn_pr.py
#Modified from a C program that generates a scene, May,1990, Pixar
#set PYTHONPATH=C:\Python25;C:\Python\Scripts;%RMANTREE%\bin
# import the python renderman library
import prman

ri = prman.Ri() # create an instance of the RenderMan interface
ri.Option("rib", {"string asciistyle": "indented"})

filename = "generate_scn.rib"

"""
* Set RenderMan options for medium quality/speed tradeoff.
"""

REFLECTION=0


def SetupOptions():
global REFLECTION
ASPECT_RATIO=1.33333
TEXTURE_ROWS=256
IMAGE_ROWS=300
gsz = 32
bktsz = [12, 12]
splits = 5

#ri.Option("limits", {"gridsize": gsz,"eyesplits",:splits,"bucketsize": bktsz})
ri.ShadingRate(2.)
ri.PixelSamples(2., 2.)
ri.PixelFilter(ri.BoxFilter, 1., 1.)

if REFLECTION:
ri.Display("refl.tif","file", "rgb")
ri.Format(TEXTURE_ROWS, TEXTURE_ROWS, ASPECT_RATIO);
else:
ri.Display("generate_scn.tif","file", "rgb")
ri.Format(512, 384, -1.0)


"""
/*
* Set RenderMan camera parameters.
*/
"""

def SetupCamera():
global REFLECTION
m = [
.970143, -0.004705, -.24249, 0,
0, .999812, -0.0193992, 0,
.242536, 0.01882, .96996, 0,
-7.27607, -1.96434, 53.406, 1
]

fov = 25.0

ri.Projection(ri.PERSPECTIVE,{ri.FOV:fov})
ri.Transform(m)

if REFLECTION:
#/* Transform z=0 plane to coincide with reflection plane. */
ri.Translate(0., 0., -0.05)

#/* Reflect camera through the reflection plane z=0. */
ri.Scale(1., 1., -1.)
#/* Transform reflection plane back to z=0. */
ri.Translate(0., 0., 0.05);


"""
* The model consists of three "walls" of a room (actually two
* walls and the floor) with a mirror on one of the walls.
* When rendering the REFLECTION image, the mirror
* and the wall it is hanging on are both removed so that
* the camera can see into the room from the other side of
* the wall.
"""

def SetupModel():
global REFLECTION
c = [[ 0.5, 0.4, 0.1], [ 0.3, 0.5, 0.5],[ 1, 1, 1], [ 0.4, 0.2, 0.7]]

if REFLECTION:
NWALLS=2 #/* Just do two walls. */
walls = [ [0, 0, -100, 0, 0, 0, 100, 0, -100, 100, 0, 0],[0, 100, -100, 0, 100, 0, 0, 0, -100, 0, 0, 0]]
else:
#ri.MakeTexture( "refl.tif", "refl.tex", "periodic", "periodic", "gaussian", 1, 1)
NWALLS=3 #/* Do three walls and mirror. */
walls = [ [0, 0, -100, 0, 0, 0, 100, 0, -100, 100, 0, 0],[ 0, 100, -100, 0, 100, 0, 0, 0, -100, 0, 0, 0],[ 0, 100, 0, 100, 100, 0, 0, 0, 0 , 100, 0, 0]]
mirror = [ 5, 10.5, -.05, 10, 10.5, -.05,5, 0.5, -.05, 10, 0.5, -.05]

ri.AttributeBegin()
ri.Color(c[2])
ri.Surface("texmap",{'string texname':"refl.tex"})
#ri.Surface("shinymetal",{'string texturename':"refl.tex"})
ri.Patch("bilinear",{'P': mirror})
ri.AttributeEnd()


ri.Color(c[0])
for i in range(NWALLS):
ri.Patch("bilinear",{'P': walls[i]})
ri.Color(c[1])

#/* Put a teapot in the room. */
ri.Color(c[3])
ri.TransformBegin()
ri.Translate(5., 1., -2.)
ri.Rotate(90., 0., 1., 0.)
ri.Rotate(-90., 1., 0., 0.)
ri.Geometry("teapot")
ri.TransformEnd()


ri.Begin(ri.RENDER)

SetupCamera()

SetupOptions()

# start our world
ri.WorldBegin()
ri.LightSource("distantlight", {ri.HANDLEID: "1","to":[0,0,1]})
ri.LightSource("ambientlight", {ri.HANDLEID: "2", "intensity":[0.4]})

SetupModel()

ri.WorldEnd()
ri.End()



テクスチャについては、
MakeTexture "refl.tif" "refl.tex" "periodic" "periodic" "gaussian" 1 1
を記述したRIBを使ってtexファイルを出力しました。
Wrong state to call RiMakeTexture.なので、調べます。ありがとうございます。
  • -
  • -
<< 4/4