这篇文章的内容主要分两部分:1,用Blender建立模型;2,用PBRT渲染
一、用Blender建立模型
咱在这里要建立的模型是“马克杯”。完全参考:
台湾大神的blender教程全集
中的“马克杯”部分。
小编看视频做的笔记截图:
将模型数据导出,截图如下:
导出的有如下两个文件:
二、用PBRT渲染
参考:http://pbrt.org/users-guide.html
会用到工具obj2pbrt,这个工具是之前在编译PBRT时一起生成的。
Q106:Linux系统下安装编译PBRT-V3 中的
10.链接可执行文件;
(以便系统能够找到这些可执行文件)
ln -s ~/pbrt-v3/build/* /usr/bin/
已经将obj2pbrt安装在系统中,此时只需执行:
obj2pbrt ~/pbrt/cup/cup3/cup3.obj ~/pbrt/cup/cup3/cup3_geo.pbrt
即将从Blender中导出的.obj文件转换成了.pbrt文件。
根据http://pbrt.org/users-guide.html
中的建议,
First, you may find it useful to run
$ pbrt –toply scene.pbrt > newscene.pbrt
This will convert triangle meshes into more compact binary PLY files, giving you a much smaller pbrt scene file to edit.
所以执行:
pbrt --toply ~/pbrt/cup/cup3/cup3_geo.pbrt > ~/pbrt/cup/cup3/cup3/cup3-geo_new.pbrt
执行完这条指令,会在当前目录下生成cup-geo_new.pbrt文件,同时在~/目录下生成mesh_00001.ply文件。
将mesh_00001.ply文件剪切到当前目录中。
接下来,只需要设置场景脚本文件啦。这里,咱用两种方式来进行渲染:方式一、sppm;方式二、bdtp
(sppm、bdtp是PBRT-V3中提供的积分器)
方式一、sppm
脚本文件(命名为cup3_glass_sppm_blue.pbrt)如下:
#sharp.pbrt -- a simple pbrt input file that displays a cone, sphere
# and refletive plane
#Richard P. Sharp - CIS782 Fall 2004
#first we set up the eye
LookAt 1 5 10 0 0 -3 0 1 0 #ex ey ez lx ly lz ux uy uz
#the camera
Camera "perspective" "float fov" [30]
#this is the filter used for antialiasing
PixelFilter "mitchell" "float xwidth" [2] "float ywidth" [2]
#name the file
Film "image" "string filename" ["cup.exr"]
"integer xresolution" [400] "integer yresolution" [400]
Integrator "sppm" "float radius" .075
"integer numiterations" [10] "integer photonsperiteration" [5000000]
#begin describing scene
WorldBegin
#light source
AttributeBegin
CoordSysTransform "camera"
LightSource "distant"
"point from" [0 0 0] "point to" [0 0 1]
"color L" [3 3 3]
AttributeEnd
#transform the world
AttributeBegin
Translate 0 -1 0
Rotate 35 0 1 0
#define an orangish sphere
AttributeBegin
Scale 1.5 1.5 1.5
Translate 1.5 1 -1.5
Rotate -135 0 1 0
Material "glass"
"float index" [ 1.2500000000 ]
Shape "plymesh" "string filename" "mesh_00001.ply"
AttributeEnd
#define a reflective ground plane
AttributeBegin
Scale 20 20 20
Material "matte" "color Kd" [0.1 1 1]
#this is a triangle mesh, the first set of points define four xyz
#coordinates, the second set defines the mesh by indexing into
#those points
Shape "trianglemesh" "point P" [ -1 0 -1 1 0 -1 1 0 1 -1 0 1 ]
"integer indices" [ 0 1 2 2 3 0 ]
AttributeEnd
AttributeEnd
WorldEnd
渲染该文件:
pbrt ~/pbrt/cup/cup3/cup3_glass_sppm_blue.pbrt
生成图形:
方式二、bdtp
脚本文件(命名为cup3_glass_bdtp_blue.pbrt)如下:
#sharp.pbrt -- a simple pbrt input file that displays a cone, sphere
# and refletive plane
#Richard P. Sharp - CIS782 Fall 2004
#first we set up the eye
LookAt 1 5 10 0 0 -3 0 1 0 #ex ey ez lx ly lz ux uy uz
#the camera
Camera "perspective" "float fov" [30]
#this is the filter used for antialiasing
PixelFilter "mitchell" "float xwidth" [2] "float ywidth" [2]
#name the file
Film "image" "string filename" ["cup3_glass_bdpt_blue.exr"]
"integer xresolution" [400] "integer yresolution" [400]
Sampler "sobol" "integer pixelsamples" 512
Integrator "bdpt" "integer maxdepth" 20
#begin describing scene
WorldBegin
LightSource "spot"
"point from" [ 0 5 5 ]
"point to" [ 1.5 1 -1.5 ]
"rgb I" [ 139.8113403320 118.6366500854 105.3887557983 ]
AttributeBegin
LightSource "infinite"
"rgb L" [ 0.1000000015 0.1000000015 0.1000000015 ]
AttributeEnd
#transform the world
AttributeBegin
Translate 0 -1 0
Rotate 35 0 1 0
#define an orangish sphere
AttributeBegin
Scale 1.5 1.5 1.5
Translate 1.5 1 -1.5
Rotate -135 0 1 0
Material "glass"
"float index" [ 1.2500000000 ]
Shape "plymesh" "string filename" "mesh_00001.ply"
AttributeEnd
#define a reflective ground plane
AttributeBegin
Scale 20 20 20
Material "matte" "color Kd" [0.1 1 1]
#this is a triangle mesh, the first set of points define four xyz
#coordinates, the second set defines the mesh by indexing into
#those points
Shape "trianglemesh" "point P" [ -1 0 -1 1 0 -1 1 0 1 -1 0 1 ]
"integer indices" [ 0 1 2 2 3 0 ]
AttributeEnd
AttributeEnd
WorldEnd
渲染该文件:
pbrt ~/pbrt/cup/cup3/cup3_glass_bdtp_blue.pbrt
生成图形: