Skip to content

Commit 2de2ec2

Browse files
committed
added some extra code stuff
1 parent 4127639 commit 2de2ec2

File tree

3 files changed

+413
-0
lines changed

3 files changed

+413
-0
lines changed

Lecture3Lighting/Toon.py

+257
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
#!/usr/bin/env rmanpy3
2+
import prman, os
3+
import ProcessCommandLine as cl
4+
5+
# Main rendering routine
6+
def main(
7+
filename,
8+
shadingrate=10,
9+
pixelvar=0.1,
10+
fov=48.0,
11+
width=1024,
12+
height=720,
13+
integrator="PxrPathTracer",
14+
integratorParams={},
15+
):
16+
print("shading rate {} pivel variance {} using {} {}".format(shadingrate, pixelvar, integrator, integratorParams))
17+
ri = prman.Ri() # create an instance of the RenderMan interface
18+
19+
# this is the begining of the rib archive generation we can only
20+
# make RI calls after this function else we get a core dump
21+
ri.Begin(filename)
22+
ri.Option("searchpath", {"string archive": "./assets/:@"})
23+
24+
# now we add the display element using the usual elements
25+
# FILENAME DISPLAY Type Output format
26+
#ri.Display("rgb.exr", "it", "rgba")
27+
threshold = 0.009
28+
ri.DisplayChannel( "color Ci" ,{ "string source" : ["Ci"], "float relativepixelvariance" : [1], "float shadowthreshold" : [threshold]})
29+
ri.DisplayChannel( "float a" ,{"string source" : ["a"], "float shadowthreshold" :[threshold]})
30+
ri.DisplayChannel( "float z" ,{"string source" : ["z"], "float shadowthreshold" :[threshold]})
31+
ri.DisplayChannel( "color diffuse", {"string source" : ["color lpe:C(D[DS]*[LO])|[LO]"], "float shadowthreshold": [threshold]})
32+
ri.DisplayChannel( "color albedo", { "string source" : ["color lpe:nothruput;noinfinitecheck;noclamp;unoccluded;overwrite;C<.S'passthru'>*((U2L)|O)"], "float shadowthreshold" :[threshold]})
33+
ri.DisplayChannel( "point P", { "string source" : ["P"], "float shadowthreshold": [threshold]})
34+
ri.DisplayChannel( "normal Nn" ,{"string source" : ["Nn"], "float shadowthreshold" :[threshold]})
35+
ri.DisplayChannel( "float sampleCount" ,{"string source" : ["sampleCount"] ,"string filter" : ["sum"] ,"float[2] filterwidth" : [1 ,1], "float shadowthreshold" : [threshold]})
36+
ri.DisplayChannel( "color directSpecular",{ "string source" : ["color lpe:C<RS>[<L.>O]"], "float shadowthreshold" : [threshold]})
37+
ri.DisplayChannel( "color NPRtoonOut" ,{"string source" : ["NPRtoonOut"], "float shadowthreshold": [threshold]})
38+
ri.DisplayChannel( "color NPRhatchOut" ,{"string source" : ["NPRhatchOut"] ,"float shadowthreshold" : [threshold]})
39+
ri.DisplayChannel( "color NPRlineOut" ,{"string source" :["NPRlineOut"] ,"float shadowthreshold" : [threshold]})
40+
ri.DisplayChannel( "color NPRlineOutAlpha",{ "string source" : ["NPRlineOutAlpha"], "float shadowthreshold": [threshold]})
41+
ri.DisplayChannel( "color NPRoutline",{ "string source" :["NPRoutline"] ,"float shadowthreshold" : [threshold]})
42+
ri.DisplayChannel( "color NPRlineNZ",{ "string source": ["NPRlineNZ"], "float shadowthreshold" : [threshold]})
43+
ri.DisplayChannel( "color NPRsections" ,{"string source" : ["NPRsections"], "float shadowthreshold" :[threshold]})
44+
ri.DisplayChannel( "color NPRlineCamdist",{ "string source" :["NPRlineCamdist"] ,"float shadowthreshold" :[threshold]})
45+
ri.DisplayChannel( "color NPRlineAlbedo",{ "string source" : ["NPRlineAlbedo"], "float shadowthreshold" : [threshold]})
46+
ri.DisplayChannel( "color NPRlineWidth",{ "string source" : ["NPRlineWidth"], "float shadowthreshold" : [threshold]})
47+
ri.DisplayChannel( "color NPRmask",{ "string source" : ["NPRmask"] ,"float shadowthreshold" : [threshold]})
48+
ri.DisplayChannel( "color NPRcurvature",{ "string source" : ["NPRcurvature"], "float shadowthreshold" : [threshold]})
49+
ri.DisplayChannel( "color NPRalbedo",{ "string source" : ["NPRalbedo"], "float shadowthreshold" : [threshold]})
50+
ri.DisplayChannel( "color NPRtextureCoords",{ "string source" : ["NPRtextureCoords"], "float shadowthreshold" : [threshold]})
51+
ri.DisplayChannel( "color NPRPtriplanar",{ "string source" : ["NPRPtriplanar"], "float shadowthreshold" : [threshold]})
52+
ri.DisplayChannel( "color NPRNtriplanar" ,{"string source" : ["NPRNtriplanar"], "float shadowthreshold" : [threshold]})
53+
ri.DisplayChannel( "color NPRdistort" ,{"string source" : ["NPRdistort"], "float shadowthreshold" : [threshold]})
54+
#ri.Display( "toon.exr" "it", "Ci,a,z" ,{})
55+
ri.Display(
56+
"toon.exr",
57+
"openexr",
58+
"Ci,a,z,diffuse,albedo,P,Nn,sampleCount,directSpecular,NPRtoonOut,NPRhatchOut,NPRlineOut,NPRlineOutAlpha,NPRoutline,NPRlineNZ,NPRsections,NPRlineCamdist,NPRlineAlbedo,NPRlineWidth,NPRmask,NPRcurvature,NPRalbedo,NPRtextureCoords,NPRPtriplanar,NPRNtriplanar,NPRdistort",
59+
{
60+
61+
"string mode" : ["diffuse,albedo,P,Nn,sampleCount,directSpecular,NPRtoonOut,NPRhatchOut,NPRlineOut,NPRlineOutAlpha,NPRoutline,NPRlineNZ,NPRsections,NPRlineCamdist,NPRlineAlbedo,NPRlineWidth,NPRmask,NPRcurvature,NPRalbedo,NPRtextureCoords,NPRPtriplanar,NPRNtriplanar,NPRdistort"],
62+
"int asrgba": [1],
63+
"string exrpixeltype": ["half"],
64+
"string compression": ["zips"],
65+
"float compressionlevel": [45],
66+
},
67+
)
68+
69+
#ri.Display( "+_vp_null_dspy" ,"null" ,"diffuse,albedo,P,Nn,sampleCount,directSpecular,NPRtoonOut,NPRhatchOut,NPRlineOut,NPRlineOutAlpha,NPRoutline,NPRlineNZ,NPRsections,NPRlineCamdist,NPRlineAlbedo,NPRlineWidth,NPRmask,NPRcurvature,NPRalbedo,NPRtextureCoords,NPRPtriplanar,NPRNtriplanar,NPRdistort" "string mode" ["diffuse,albedo,P,Nn,sampleCount,directSpecular,NPRtoonOut,NPRhatchOut,NPRlineOut,NPRlineOutAlpha,NPRoutline,NPRlineNZ,NPRsections,NPRlineCamdist,NPRlineAlbedo,NPRlineWidth,NPRmask,NPRcurvature,NPRalbedo,NPRtextureCoords,NPRPtriplanar,NPRNtriplanar,NPRdistort"])
70+
71+
72+
73+
ri.DisplayFilter('PxrStylizedToon','ToonFilter',
74+
{
75+
'string visualizer' : ['toonDiffuseFinal'],
76+
'int colorRamp' : [4],
77+
#'float colorRamp_Knots' : [0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
78+
#'color colorRamp_Colors' : [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
79+
'string colorRamp_Interpolation' : ['catmull-rom'],
80+
'int Toon_Steps' : [4],
81+
'color backgroundColor' : [0,0,0],
82+
'string stepMode' : ['darks'],
83+
'color darks' : [0,0,0],
84+
'float albedoLift' : [0.0],
85+
'string Signal' : ['diffuse'],
86+
'string signal_aov_string' : ['diffuse'],
87+
'string whiteShader' : ['signalAovAverage'],
88+
'float Signal_Energy_Threshold_Min' : [0.0],
89+
'float Signal_Energy_Threshold_Max' : [1.0],
90+
'float Signal_Pre_Gain' : [1.0],
91+
'float Signal_Pre_Gamma' : [1.0],
92+
'int Spline_Ramp_Switch' : [0],
93+
'int ramp' : [4],
94+
#'float ramp_Knots' : [0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
95+
#'float ramp_Floats' : [0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
96+
'string ramp_Interpolation' : ['linear'],
97+
'int Toon_Mask_Switch' : [0],
98+
'int light_mask_switch' : [0],
99+
'string Note' : ['Color Spline Ramp'],
100+
})
101+
102+
ri.Format(width, height, 1)
103+
104+
# setup the raytrace / integrators
105+
ri.Hider("raytrace", {"int incremental": [1]})
106+
ri.ShadingRate(shadingrate)
107+
ri.PixelVariance(pixelvar)
108+
ri.Integrator(integrator, "integrator", integratorParams)
109+
ri.Option("statistics", {"filename": ["stats.txt"]})
110+
ri.Option("statistics", {"endofframe": [1]})
111+
112+
ri.Projection(ri.PERSPECTIVE, {ri.FOV: fov})
113+
114+
ri.Rotate(12, 1, 0, 0)
115+
ri.Translate(0, 0.75, 2.5)
116+
117+
# now we start our world
118+
ri.WorldBegin()
119+
120+
#######################################################################
121+
# Lighting :- Move the light just before the celling to show direction
122+
#######################################################################
123+
ri.TransformBegin()
124+
ri.AttributeBegin()
125+
ri.Declare("Light0", "string")
126+
ri.Translate(0, 0.6, 0)
127+
ri.Rotate(45, 0, 1, 0)
128+
ri.Rotate(90, 1, 0, 0)
129+
ri.Scale(0.5, 0.5, 0.5)
130+
ri.Light("PxrRectLight", "Light0", {"float intensity": 30})
131+
ri.AttributeEnd()
132+
ri.TransformEnd()
133+
#######################################################################
134+
# end lighting
135+
#######################################################################
136+
137+
ri.AttributeBegin()
138+
ri.Attribute("identifier", {"name": "cornell"})
139+
ri.ReadArchive("cornell.rib")
140+
ri.AttributeEnd()
141+
142+
ri.AttributeBegin()
143+
ri.Attribute("identifier", {"name": "buddha"})
144+
ri.TransformBegin()
145+
ri.Translate(-0.5, -1, 0)
146+
ri.Rotate(180, 0, 1, 0)
147+
ri.Scale(0.1, 0.1, 0.1)
148+
ri.Attribute("visibility", {"int transmission": [1]})
149+
ri.Attribute("trace", {"int maxdiffusedepth": [1], "int maxspeculardepth": [8]})
150+
ri.Bxdf(
151+
"PxrSurface",
152+
"greenglass",
153+
{
154+
"color refractionColor": [0, 0.9, 0],
155+
"float diffuseGain": 0,
156+
"color specularEdgeColor": [0.2, 1, 0.2],
157+
"float refractionGain": [1.0],
158+
"float reflectionGain": [1.0],
159+
"float glassRoughness": [0.01],
160+
"float glassIor": [1.5],
161+
"color extinction": [0.0, 0.2, 0.0],
162+
},
163+
)
164+
ri.ReadArchive("buddha.zip!buddha.rib")
165+
ri.TransformEnd()
166+
ri.AttributeEnd()
167+
168+
ri.AttributeBegin()
169+
ri.Attribute("identifier", {"name": "sphere"})
170+
ri.Pattern("PxrVariable", "du", {"string variable": "du", "string type": "float"})
171+
ri.Pattern("PxrVariable", "dv", {"string variable": "dv", "string type": "float"})
172+
ri.Pattern("starBall", "starBall", {"reference float du": ["du:resultR"], "reference float dv": ["dv:resultR"]})
173+
174+
ri.Bxdf("PxrDisney", "bxdf", {"reference color baseColor": ["starBall:Cout"]})
175+
ri.TransformBegin()
176+
ri.Translate(0.3, -0.7, 0.3)
177+
ri.Rotate(-30, 0, 1, 0)
178+
ri.Rotate(20, 1, 0, 0)
179+
ri.Sphere(0.3, -0.3, 0.3, 360)
180+
ri.TransformEnd()
181+
ri.AttributeEnd()
182+
183+
ri.AttributeBegin()
184+
ri.Attribute("identifier", {"name": "teapot"})
185+
ri.TransformBegin()
186+
ri.Translate(0, -1, -0.8)
187+
ri.Rotate(45, 0, 1, 0)
188+
ri.Rotate(-90, 1, 0, 0)
189+
ri.Scale(0.1, 0.1, 0.1)
190+
ri.Bxdf(
191+
"PxrSurface",
192+
"plastic",
193+
{
194+
"color diffuseColor": [0.04, 0.51, 0.1],
195+
"color clearcoatFaceColor": [0.5, 0.5, 0.5],
196+
"color clearcoatEdgeColor": [0.25, 0.25, 0.25],
197+
},
198+
)
199+
ri.Geometry("teapot")
200+
ri.TransformEnd()
201+
ri.AttributeEnd()
202+
203+
ri.AttributeBegin()
204+
ri.Bxdf(
205+
"PxrSurface",
206+
"metal",
207+
{
208+
"float diffuseGain": [0],
209+
"int specularFresnelMode": [1],
210+
"color specularEdgeColor": [1, 1, 1],
211+
"color specularIor": [4.3696842, 2.916713, 1.654698],
212+
"color specularExtinctionCoeff": [5.20643, 4.2313662, 3.7549689],
213+
"float specularRoughness": [0.1],
214+
"integer specularModelType": [1],
215+
},
216+
)
217+
218+
ri.Attribute("identifier", {"name": "ncca"})
219+
ri.TransformBegin()
220+
ri.Translate(0, 0.3, 0.8)
221+
ri.ReadArchive("ncca.rib")
222+
ri.TransformEnd()
223+
ri.AttributeEnd()
224+
225+
# end our world
226+
ri.WorldEnd()
227+
# and finally end the rib file
228+
ri.End()
229+
230+
231+
def checkAndCompileShader(shader):
232+
if (
233+
os.path.isfile(shader + ".oso") != True
234+
or os.stat(shader + ".osl").st_mtime - os.stat(shader + ".oso").st_mtime > 0
235+
):
236+
print("compiling shader %s" % (shader))
237+
try:
238+
subprocess.check_call(["oslc", shader + ".osl"])
239+
except subprocess.CalledProcessError:
240+
sys.exit("shader compilation failed")
241+
242+
243+
if __name__ == "__main__":
244+
shaderName = "starBall"
245+
checkAndCompileShader(shaderName)
246+
247+
cl.ProcessCommandLine("RectLight.rib")
248+
main(
249+
cl.filename,
250+
cl.args.shadingrate,
251+
cl.args.pixelvar,
252+
cl.args.fov,
253+
cl.args.width,
254+
cl.args.height,
255+
cl.integrator,
256+
cl.integratorParams,
257+
)

PythonBindings/bindings

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
"exec" "/Applications/Pixar/RenderManProServer-25.2/bin/rmanpy3" "$0"
3+
4+
import code
5+
import sys
6+
import os
7+
import time
8+
9+
# Find pythonbindings directory and append python path
10+
RMANTREE = os.getenv("RMANTREE")
11+
assert os.path.isdir(RMANTREE), "RMANTREE is invalid"
12+
PYTHONBINDINGS = os.path.abspath(os.path.join(RMANTREE, "bin", "pythonbindings"))
13+
if PYTHONBINDINGS not in sys.path:
14+
sys.path.append(PYTHONBINDINGS)
15+
16+
# Now import rman modules
17+
import rman
18+
# Grab an instance of the rman ctl module (bit like ri in the old API)
19+
rictl = rman.RiCtl.Get()
20+
rictl.PRManBegin(sys.argv)
21+
22+
# Acquire scene graph interface and check version
23+
sgmngr = rman.scenegraph.Get()
24+
if sgmngr.GetVersion() != 3:
25+
print("wrong version of API")
26+
sys.exit()
27+
28+
29+
# Create the scene
30+
config = rman.Types.RtParamList()
31+
renderConfig = rman.Types.RtParamList()
32+
statsSession = rman.Stats.AddSession("stats")
33+
scene = sgmngr.CreateScene(config, renderConfig, statsSession)
34+
35+
# import pydoc
36+
# file = open("rmanhelp.txt","w")
37+
# modules=[rman.Ctx,
38+
# rman.Dspy,
39+
# rman.EventCallbacks,
40+
# rman.RiCtl,
41+
# rman.SGManager,
42+
# rman.Stats,
43+
# rman.Tokens,
44+
# rman.Types,
45+
# rman.pxrcore,
46+
# rman.scenegraph,
47+
# ]
48+
49+
# for module in modules :
50+
# strhelp = pydoc.render_doc(module, "Help on %s\n",renderer=pydoc.plaintext)
51+
# print("**************************************************")
52+
# print(strhelp)
53+
# print("**************************************************")
54+
55+
56+
code.interact(local=locals())
57+
58+
59+
60+
61+

0 commit comments

Comments
 (0)