Rendering学習日記

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

「実践CGへの誘い」例題をPythonで・・その11

「実践CGへの誘い」p.67
Listing 4.3
wavemain.jpg
#list43.py
#/* Copyrighted Pixar 1989 */
#/* From the RenderMan Companion p. 67 */
#/* Listing 4.3 Using RiTorus to create a wavelike pattern */

import cgkit.cri
from cgkit.cgtypes import *

# Load the RenderMan API.
# Replace the library name with whatever renderer you want to use.
ri = cgkit.cri.loadRI("3delight")
cgkit.cri.importRINames(ri, globals())

def TorusWave(nwaves, thetamax):
if nwaves < 1:
print "Need a positive number of waves\n"

#/* Divide the net radius 1.0 among the waves and the hemisphere */
innerrad = 2 / (8.0*nwaves + 2)
RiRotate(90.0, 1.0, 0.0, 0.0)
#/* Create the downward-opening hemisphere */
RiSphere(innerrad, -innerrad, 0.0, thetamax, RI_NULL)

outerrad = 0
for wave in range(1,nwaves+1):
#* Each iteration creates a downward-opening half-torus
#* and a larger upward-opening half-torus.
outerrad = outerrad + (innerrad * 2)
RiTorus(outerrad, innerrad, 0.0, 180.0, thetamax, RI_NULL)
outerrad = outerrad + (innerrad * 2)
RiTorus(outerrad, innerrad, 180.0, 360.0, thetamax, RI_NULL)

def Go():
TorusWave(4, 250.0)


RiBegin (RI_NULL) #/* Start Renderer */
RiDisplay("wavemain.tif", RI_FILE, "rgb", RI_NULL)
RiFormat( 512, 372, -1.0)
RiProjection ("perspective", RI_NULL)

RiWorldBegin ()
RiLightSource("ambientlight","intensity",0.4)
RiLightSource ("distantlight", RI_NULL)
RiAttributeBegin()
RiTranslate (-0.1, 0.0, 1.1)
RiRotate (50.0, -1.0, 1.0, 0.0)
RiColor((0.42,0.97,0.45))
RiSurface ("plastic", Kd=1.0)
Go()
RiAttributeEnd()
RiWorldEnd()
RiEnd()


wavemain2.jpg
RiProjection ("perspective", "fov", 45)
と書き換えてみた。
  • -
  • -

Depth of field

Essential RenderManから、loop.cをPythonで試してみる。
Depth of field、PixelSamples、ShadingRateを調整しています。
ありがとうございます。
loop.jpg
#/* loop.py - Create a line of Spheres */
# Essential RenderMan p.113
import cgkit.cri
from cgkit.cgtypes import *

# Load the RenderMan API.
# Replace the library name with whatever renderer you want to use.
ri = cgkit.cri.loadRI("3delight")
cgkit.cri.importRINames(ri, globals())

RiBegin(RI_NULL)
RiDisplay ("loop.tif",RI_FILE, RI_RGB)
RiFormat(320, 240,1)
RiPixelSamples( 8, 8)
RiShadingRate(0.25)
RiProjection (RI_PERSPECTIVE)
RiDepthOfField(2.8,0.100,2)
RiTranslate(0,0,0.25)
RiRotate(-10,0,1,0)
RiWorldBegin()
RiLightSource("ambientlight","intensity",0.2)
RiLightSource("distantlight", "from",[-1,1,-1])
RiTranslate(0.3,0,0)
for i in range(12):
RiSurface ("plastic")
RiColor((1.0,0.05,0.05))
RiSphere(0.25,-0.25,0.25,360,RI_NULL)
RiTranslate(-0.2,0,0.5)

RiWorldEnd()
RiEnd()

RiLightSource("distantlight", "from",[-4,1,-1])
ディスタントライトの方向を変更してみた。

#RiDepthOfField(2.8,0.1,2)
とコメントアウトすると、くっきりになる。
cgkitと3Delightを使用しました。
  • -
  • -

pythonでパーティクル

Essential RenderManから、point.cをPythonで試してみる。
パーティクルも面白くなりそうです。
記述に関しては、cgkitのritest.pyが参考になります。
ありがとうございます。レンダリングは3Delightです。
以前書いた記事、CAPIでパーティクル
point.jpg
#point.py - Create a simple Particle System
import random, math
import cgkit.cri
from cgkit.cgtypes import *


# Load the RenderMan API.
# Replace the library name with whatever renderer you want to use.
ri = cgkit.cri.loadRI("3delight")
cgkit.cri.importRINames(ri, globals())


COUNT = 1000

def jitter(scale):
val=random.random()*1000
return (val/500-1)*scale

position=[]
red=[1,0,0]
fov=30

#/*Generate Particle Postions*/
for i in range(COUNT):
x=math.sin(i*0.5)*50+jitter(2)
y=math.cos(i*0.1)*50+jitter(2)
z=math.cos(i*0.5)*100+jitter(2)
position.append(vec3(x, y, z))


RiBegin(RI_NULL)
RiDisplay ("point.tif","file","rgb",RI_NULL)
RiFormat(512, 384, -1.0)
RiPixelSamples( 4, 4)
RiShadingRate(0.5)
RiProjection ("perspective","fov",fov,RI_NULL)
RiWorldBegin()
RiTranslate(0,0,300)
RiColor(red)
RiPoints("P",position,RI_NULL)
RiWorldEnd()
RiEnd()
  • -
  • -
<< 5/14 >>