Q106:Linux系统下安装编译PBRT-V3

来源:互联网 发布:纯html源码 编辑:程序博客网 时间:2024/05/17 02:40

106.0 引入

本人之前尝试过在windows系统中编译pbrt-v3,但是出现了很多错误。pbrt-v3的源代码中部分Linux的函数没有用宏包好,而是直接使用,所以在windows环境下就报错了。而且,报错的这些函数和pbrt的“图形”核心并无关系,所以本人不想深入研究这些函数。所以,决定转到Linux系统。所以,也就有了前面安装Linux系统的博文:
Q105:PC双系统:Windows 7下硬盘安装Ubuntu 16.04
http://blog.csdn.net/libing_zeng/article/details/72273281

(另外,原版电子书相关博文:Physically Based Rendering, Third Edition 第三版电子书 )

所以,这篇文章记录的是在新安装的Linux系统中安装编译PBRT-V3

106.1 相关步骤

打开Linux终端。

1.安装git;

sudo apt-get install gitsudo apt-get install git-core

2.下载pbrt-v3源代码;

git clone --recursive https://github.com/mmp/pbrt-v3/

3.安装cmake;

sudo apt-get install cmake

4.安装zlib(zlib1g-dev);

sudo apt-get install zlib1g-dev

5.安装bison;

sudo apt-get install bison

6.安装flex;

sudo apt-get install flex

7.在代码文件夹(pbrt-v3)中新建一个文件夹”build”,定位到build文件夹中;

cd ~/pbrt-v3/build

8.cmake ../;

(结束时,会在build文件夹中产生一个makefile文件)

9.make -j4;

(根据前面产生的makefile文件进行编译,编译完成后在build文件夹会产生pbrt、pbrt_test等可执行文件)

10.链接可执行文件;

(以便系统能够找到这些可执行文件)
ln -s ~/pbrt-v3/build/* /usr/bin/

11.找一个场景脚本文件

先来个简单的场景文件。内容如下:

#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 eyeLookAt 1 1 10   0 0 -1  0 1 0 #ex ey ez lx ly lz ux uy uz#the cameraCamera "perspective" "float fov" [30]#this is the filter used for antialiasingPixelFilter "mitchell" "float xwidth" [2] "float ywidth" [2]#name the fileFilm "image" "string filename" ["sharp.exr"]     "integer xresolution" [400] "integer yresolution" [400]#begin describing sceneWorldBegin#light sourceAttributeBegin  CoordSysTransform "camera"  LightSource "distant"               "point from" [0 0 0] "point to"   [0 0 1]              "color L"    [3 3 3]AttributeEnd#transform the worldAttributeBegin  Translate 0 -1 0  Rotate 35 0 1 0  #define a sphere  AttributeBegin    Translate -1 .75 -1.5    Rotate -90 1 0 0    Material "matte" "color Kd" [0.1 0.9 0.1]    Shape "sphere" "float radius" [.75]   AttributeEnd  #define a cone  AttributeBegin    Translate 0 0 2.5    Rotate -90 1 0 0    #this describes the material properties    Material "matte" "color Kd" [0.9 0.1 0.1]    #this is the shape    Shape "cone" "float radius" [.75] "float height" [2]  AttributeEnd  #define a reflective ground plane  AttributeBegin    Scale 20 20 20    Material "uber" "color Kd" [0.1 0.1 0.9] "color Kr" [0.9 0.9 0.9] "color Ks" [0.1 0.1 0.1] "float roughness" [0.9] "float index" [1.34]    #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 for the triangle mesh including two triangles    Shape "trianglemesh" "point P" [ -1 0 -1  1 0 -1  1 0 1  -1 0 1 ]      "integer indices" [ 0 1 2 2 3 0 ]  AttributeEndAttributeEndWorldEnd

要做的事情是:在~/pbrt/目录下新建文件,将上方“代码”粘贴保存为.pbrt格式,文件随便命名(比如:sharp.pbrt)

12.运行可执行文件;

pbrt ~/pbrt/sharp.pbrt

(执行完成后,结果图形文件保存在~/下,名为sharp.exr)

这里写图片描述

13.安装KolourPaint;

(双击之前生成的“sharp.exr”文件,系统默认是没有软件可以打开该文件的。但是,会提示安装KolourPaint。后续一直选择“继续”就可以啦,等待安装完成。赞一个Ubuntu安装软件的便利性。)

安装KolourPaint前,双击“sharp.exr”时是这样,贴图如下:
这里写图片描述

安装KolourPaint后,双击“sharp.exr”时是这样,贴图如下:
这里写图片描述

14.将“sharp.exr”转成“sharp.png”;

(在安装完KolourPaint之后,双击“sharp.exr”,则会在KolourPaint中打开sharp.exr,然后点击“文件”–“另存为”,选择png格式,保存。)

最后,贴出png格式的sharp图形:

这里写图片描述

到这里为止,Linux系统下安装编译PBRT-V3算是完成。

后文提供一些测试图形及其测试的方法。

106.2 补充官网图形

15.下载“pbrt-v3-scenes”场景脚本文件;

(不知道到哪去找实例场景脚本,下载官网提供的。pbrt-v3-scenes包好的场景文件很多,整个文件夹估计有好几个G,完整下载需要一段时间。下载结果会保存在~/中。执行下方指令前,得先安装git)
git clone git://git.pbrt.org/pbrt-v3-scenes

16.1 pbrt ~/pbrt/killeroos/killeroos-simple.pbrt

这里写图片描述

这里写图片描述

16.2 pbrt ~/pbrt/killeroos/killeroos-moving.pbrt

这里写图片描述

这里写图片描述

16.3 pbrt ~/pbrt/cloud/cloud.pbrt

这里写图片描述

这里写图片描述

106.3 补充其他PLY相关图形

http://www.cc.gatech.edu/projects/large_models/
这里可以找到一些PLY文件。
记得在学习《Ray Tracing from the Ground Up》时,windows环境下并不能直接使用这里的PLY文件,而需要将文件中的“换行符”转换到windows环境中的格式才可以使用。参考:
Unix/Mac系统下的文件在Windows里打开的话,所有文字会变成一行——怎么将Unix/Mac系统下的文件转换到Windows系统下

但是,PBRT貌似可以通用解析windows、unix/mac环境下的PLY文件。这个确实比《Ray Tracing from the Ground Up》官网提供的代码考虑得周全一些。

在这里,咱测试一下dragon.ply。文件下载路径:
http://www.cc.gatech.edu/projects/large_models/dragon.html
将该文件下载、解压到~/pbrt/dragon/路径下。

使用的.pbrt是基于前面的sharp.pbrt。只是将其中的球和锥体换成dragon。重命名为dragon.pbrt,保存在~/pbrt/dragon/路径下。
dragon.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 eyeLookAt 1 1 10   0 0 -1  0 1 0 #ex ey ez lx ly lz ux uy uz#the cameraCamera "perspective" "float fov" [30]#this is the filter used for antialiasingPixelFilter "mitchell" "float xwidth" [2] "float ywidth" [2]#name the fileFilm "image" "string filename" ["sharp.exr"]     "integer xresolution" [400] "integer yresolution" [400]#begin describing sceneWorldBegin#light sourceAttributeBegin  CoordSysTransform "camera"  LightSource "distant"               "point from" [0 0 0] "point to"   [0 0 1]              "color L"    [3 3 3]AttributeEnd#transform the worldAttributeBegin  Translate 0 -1 0  Rotate 35 0 1 0AttributeBegin  Scale 15 15 15  Material "matte" "color Kd" [0.1 0.9 0.1]  Shape "plymesh" "string filename" "dragon.ply"AttributeEnd  #define a reflective ground plane  AttributeBegin    Scale 20 20 20    Material "uber" "color Kd" [0.1 0.1 0.9] "color Kr" [0.9 0.9 0.9] "color Ks" [0.1 0.1 0.1] "float roughness" [0.9] "float index" [1.34]    #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 ]  AttributeEndAttributeEndWorldEnd

这个文件和sharp.pbrt不同之处在于:

AttributeBegin  Scale 15 15 15  Material "matte" "color Kd" [0.1 0.9 0.1]  Shape "plymesh" "string filename" "dragon.ply"AttributeEnd

PBRT-V3较之前版本的新增功能之一:直接支持PLY文件。
参考:http://www.pbrt.org/users-guide.html

接下来,运行如下指令:

pbrt ~/pbrt/dragon/dragon.pbrt 

得到:
这里写图片描述

这里写图片描述
从这个图形来看,上方的绿色的dragon距离下方“镜面”的地面貌似有点远哈。
将dragon向下平移0.8个单位。即在“Scale 15 15 15”配置指令前添加:“Translate 0 -0.8 0”。即:

AttributeBegin  Translate 0 -0.8 0  Scale 15 15 15  Material "matte" "color Kd" [0.1 0.9 0.1]  Shape "plymesh" "string filename" "dragon.ply"AttributeEnd

得到的图形如下:
这里写图片描述

若给dragon换种材质,配置文件对应部分改成:

    Material "subsurface"        "float eta" [1.5]       "string name" ["Skin1"]       "float scale" [20]

得到这个图形:
这里写图片描述
这个图形貌似噪音太多了,在dragon.pbrt的开头添加如下配置:

Integrator "path" "integer maxdepth" [5]Sampler "halton" "integer pixelsamples" [500]

(将integrator换成path,另外将单像素采样次数设置为500)
得到如下图形:
这里写图片描述

原创粉丝点击