对于PBRT-V3场景文件.pbrt格式,小编自己根据自己的理解总结如下:
1,“#”后面的内容为注释
举例1:
#sphere.pbrt
#first we set up the eye
2,每一行的第一个词为“关键字”,在api.cpp中对应着处理函数。
举例2:
#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
在api.cpp中:
关键字“LookAt”对应的处理函数是pbrtLookAt();
关键字“Camera”对应的处理函数是pbrtCamera();
关键字“Film”对应的处理函数是pbrtFilm();
关键字“Integrator”对应的处理函数是pbrtIntegrator();
关键字“WorldBegin”对应的处理函数是pbrtWorldBegin();
关键字“AttributeBegin”对应的处理函数是pbrtAttributeBegin();
关键字“CoordSysTransform”对应的处理函数是pbrtCoordSysTransform();
关键字“LightSource”对应的处理函数是pbrtLightSource();
关键字“AttributeEnd”对应的处理函数是pbrtAttributeEnd();
关键字还有:Translate,Rotate,Scale,Material,Shape等等。
3,AttributeBegin和AttributeEnd是成对顺序出现,最临近的一对包含的内容可是为一个block。
举例3:
AttributeBegin
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
AttributeEnd
如上有三对AttributeBegin/AttributeEnd,刚好也有三组仿射变换Translate/Rotate。
第二组Translate/Rotate只作用于第二对AttributeBegin/AttributeEnd包住的sphere;
第三组Translate/Rotate只作用于第三对AttributeBegin/AttributeEnd包住的cone;
由于第一对AttributeBegin/AttributeEnd包住的是sphere和cone,所以,第一组Translate/Rotate对sphere和cone都起作用。
4,对关键字后参数的解析
4.1 关键字后直接跟参数值,直接解析,处理函数形参中顺序对应这些参数。
举例4:
LookAt 1 1 10 0 0 -1 0 1 0 #ex ey ez lx ly lz ux uy uz
处理函数原型:
void pbrtLookAt(Float ex, Float ey, Float ez, Float lx, Float ly, Float lz, Float ux, Float uy, Float uz);
举例5:
Translate 0 -1 0
Rotate 35 0 1 0
处理函数原型:
void pbrtTranslate(Float dx, Float dy, Float dz);
void pbrtRotate(Float angle, Float ax, Float ay, Float az);
4.2 关键字后跟:类型+属性,其中“属性”的格式是:“属性类型 属性名称”[该名称属性对应的值]
“属性”的格式类似于:
float num = 3.0;
即:类型+变量+赋值
举例6:
Film "image" "string filename" ["sphere.exr"]
"integer xresolution" [200] "integer yresolution" [200]
解析:
关键字是Film;
这个Film的类型是image;
这个image类型的Film有三个属性:
属性一:有个string类型的属性叫做filename,这个filename的值是“sphere.exr”
属性二:有个integer类型的属性叫做xresolution,这个xresolution的值为200
属性三:有个integer类型的属性叫做yresolution,这个yresolution的值为200
处理函数原型:
void pbrtFilm(const std::string &type, const ParamSet ¶ms);
举例7:
LightSource "distant"
"point from" [0 0 0] "point to" [0 0 1]
"color L" [3 3 3]
解析:
关键字是LightSource;
这个LightSource的类型是distant;
这个distant类型的LightSource有三个属性:
属性一:有个point类型的属性叫做from,这个fr