没有合适的资源?快使用搜索试试~ 我知道了~
参数曲线、曲面的三维造形与渲染1
需积分: 0 0 下载量 8 浏览量
2022-08-03
14:41:43
上传
评论
收藏 162KB PDF 举报
温馨提示
试读
12页
模型简介本模型使用基于光子映射的真实感图形绘制方法,对于由矩形、球形、点光源、面积光源构成的场景进行真实感图形绘制,主要有以下几个方面的特点:1. 实现了 PM
资源详情
资源评论
资源推荐
参数曲线、曲面的三维造形与渲染
计 62 胡致远
2016011260
2018 年 7 月 1 日
1 模型简介
本模型使用基于光子映射的真实感图形绘制方法,对于由矩形、球形、
点光源、面积光源构成的场景进行真实感图形绘制,主要有以下几个方面的
特点:
1. 实现了 PM 算法,能够表现出 caustics 的效果
2. 实现了针对矩形面片,球形及任意次 Bezier 曲线旋转体的求交操作
3. 使用了 OpenMP 进行并行运算,对渲染过程进行加速
4. 实现了针对面积光源的软阴影效果
5. 使用了纹理贴图,美化设计
与 Bezier 曲线相关的理论推导将在第三部分给出。
2 对应代码段
1. PM 算法,包括光子投射,光子图的组织,平衡以及颜色查询。
1 Photonmap * Photontracer :: Start ()
2 {
3 int maxphotons = 0;
4 float maxpower = 0.0;
5 Light* tmp = scene ->GetLightHead ();
6 while(tmp)
7 {
8 maxphotons += tmp -> GetMaxPhotons ();
1
9 maxpower += tmp -> GetColor().Power();
10 tmp = tmp ->GetNext();
11 }
12 Photonmap* photonmap = new Photonmap(maxphotons * MAX_PHOTON_DEP , scene);
13 float photonpower = float ( maxpower) / maxphotons ;
14 tmp = scene -> GetLightHead ();
15 while(tmp)
16 {
17 #pragma parallel omp for
18 for(int i = 0; i < tmp ->GetMaxPhotons (); i++)
19 {
20 Photon photon = tmp ->EmitPhoton ();
21 photon.color *= photonpower;
22 PhotonTrace ( photon , 1, photonmap , false );
23 }
24 tmp = tmp ->GetNext();
25 }
26 photonmap -> Balance ();
27 return photonmap;
28 }
这是光子投射的主函数,负责将各个光源中的光子依次投出,并生成
一幅光子图。对于每一个光源,在投射光子时采用并行投射的方法以
提高效率。
1 void Photontracer :: PhotonTrace ( Photon photon , int dep , Photonmap* photonmap , bool
refracted )
2 {
3 if( photon.color. IsBlack () ) return;
4 if( dep > MAX_PHOTON_DEP ) return;
5 Intsct * intsct = scene -> GetNearstObj(photon.pos , photon.dir);
6 if(! intsct )return ;
7 photon .pos = intsct ->P;
8 Material * mat = intsct -> GetObj()-> GetMaterial();
9 if(mat ->cdiff > EPS)
10 photonmap -> Store(photon );
11
12 double boardsize = mat -> cabso + mat ->crefl + mat ->crefc;
13 double end = ran () * boardsize;
14 if( end < mat -> crefl ) Reflect(intsct , photon , dep , photonmap
, refracted);
15 else if(end < mat ->crefl + mat -> crefc) Refract (intsct , photon , dep , photonmap
, refracted);
16
17 if( intsct) delete intsct ;
18 }
光子投射算法,负责跟踪光子并在必要时将其存储。
2
1 void Photontracer :: Reflect ( Intsct* intsct , Photon photon , int dep , Photonmap*
photonmap , bool refracted )
2 {
3 Object * obj = intsct -> GetObj();
4 photon .dir = ReflDir(intsct ->I, intsct ->N);
5 Color basecolor = obj ->GetColor(intsct ->P) * obj -> GetMaterial () ->crefl ;
6 float power = photon.color.Power();
7 photon . color = photon.color * basecolor;
8 PhotonTrace(photon , dep + 1, photonmap , refracted);
9 }
10
11 void Photontracer :: Refract ( Intsct* intsct , Photon photon , int dep , Photonmap*
photonmap , bool refracted )
12 {
13 Object * obj = intsct -> GetObj();
14 double n = obj ->GetMaterial()->N;
15 bool valid;
16 n = refracted ? 1.0 / n : n;
17 photon .dir = RefrDir(intsct ->I, intsct ->N, n, valid);
18 if(! valid)return;
19 Color basecolor = obj ->GetMaterial ()->incolor * obj -> GetMaterial () ->crefc ;
20 if( refracted)
21 basecolor = basecolor * (obj ->GetMaterial ()->absorb * -intsct ->dep).Exp ()
;
22 float power = photon.color.Power();
23 photon . color = photon.color * basecolor;
24 PhotonTrace(photon , dep + 1, photonmap , refracted);
25 }
处理光子的反射和折射。
1 void Photonmap:: Balance ()
2 {
3 std:: cout << "Stored␣Photons␣=␣" << photons.size() << std ::endl ;
4 Photon ** p = new Photon*[photons.size () ];
5 for(int i = 0; i < photons.size (); i++)
6 p[i] = & photons[i];
7 head = SegBalance(p, 0, photons . size());
8 }
9 KDT* Photonmap :: SegBalance(Photon ** p, int l, int r)
10 {
11 if(l >= r)return NULL ;
12 int mid = (l + r) / 2;
13 KDT* node = new KDT();
14 int axis = 1;
15 if( Box_max.y - Box_min.y > Box_max.x - Box_min.x && Box_max .y - Box_min .y >
Box_max.z - Box_min .z) axis = 2;
16 if( Box_max.z - Box_min.z > Box_max.x - Box_min.x && Box_max .z - Box_min .z >
Box_max.y - Box_min .y) axis = 3;
17 Axis = axis;
18 std:: nth_element(p + l, p + mid , p + r, cmp );
19
3
剩余11页未读,继续阅读
基鑫阁
- 粉丝: 61
- 资源: 358
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0