小编在这里想通过渲染一个简单的场景(比如,一个球),来看看:
从“系统读入场景描述文件”到“系统输出图形”的过程中,系统具体是怎么跑的。(内容适合有一定ray tracing基础的童鞋)
〇、准备
直接参考:
1,PBRT-V3官方代码(book版)
2,PBRT-V3原著章节“1.3 pbrt: System Overview”
另外,小编之前零零碎碎写了一些小总结:
Q106:Linux系统下安装编译PBRT-V3
Q107:Linux系统下GDB对PBRT-V3进行debug
Q108:浅析PBRT-V3的代码结构
Q110:PBRT-V3十大基类对应的继承关系
对了,首先参考“Q107”将debug版本的pbrt编译出来。
小编的调试环境是:Ubuntu+GDB
这一章节,用到的场景描述文件sphere.pbrt内容如下:
#first we set up the eye
LookAt 1 1 10 0 0 -1 0 1 0 #ex ey ez lx ly lz ux uy uz
#the camera
Camera "perspective" "float fov" [30]
#name the file
Film "image" "string filename" ["sphere.exr"]
"integer xresolution" [200] "integer yresolution" [200]
Integrator "whitted"
#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 a sphere
AttributeBegin
Translate 1 .75 -1.5
Rotate -90 1 0 0
Scale 2 2 2
Material "matte" "color Kd" [0.1 0.9 0.1]
Shape "sphere" "float radius" [.75]
AttributeEnd
AttributeEnd
WorldEnd
涉及的“十大基类”中的Camera、Film、Integrator、Light、Material、Shape。
对应输出的图形是:
接下来,咱用pbrt的debug版本渲染(调试)上面提到的这个场景。
一、main()
对的,系统是从main()开始跑的。
main()在这个位置:
/home/libingzeng/CG/pbrt-v3/src/main/pbrt.cpp:74:int main(int argc, char *argv[])
书上提供的main()文学编码形式截图如下:
main()函数里主要干的就是这么四件事。
接下来,咱先在这四个位置设置断点看看。
(