返回信息流这个代码地来源在上传的文件里,伪代码如下:
rgb lsou; // intensity of light source
rgb back; // background intensity
rgb ambi; // ambient light intensity
Vector L // vector pointing to light source
Vector N // surface normal
Object objects [n] //list of n objects in scene
float Ks [n] // specular reflectivity factor for each object
float Kr [n] // refractivity index for each object
float Kd [n] // diffuse reflectivity factor for each object
Ray r;
void raytrace() {
for (each pixel P of projection viewport in raster order) {
r = ray emanating from viewer through P
int depth = 1; // depth of ray tree consisting of multiple paths
the pixel color at P = intensity(r, depth)
}
}
rgb intensity (Ray r, int depth) {
Ray flec, frac;
rgb spec, refr, dull, intensity;
if (depth >= 5) intensity = back;
else {
find the closest intersection of r with all objects in scene
if (no intersection) {
intensity =back;
} else {
Take closest intersection which is object[j]
compute normal N at the intersection point
if (Ks[j] >0) { // non-zero specular reflectivity
compute reflection ray flec;
refl = Ks[j]*intensity(flec, depth+1);
} else refl =0;
if (Kr[j]>0) { // non-zero refractivity
compute refraction ray frac;
refr = Kr[j]*intensity(frac, depth+1);
} else refr =0;
check for shadow;
if (shadow) direct = Kd[j]*ambi
else direct = Phong illumination computation;
intensity = direct + refl +refr;
} }
return intensity; }
附件(1.2MB) raytracing.ppt
这是一条镜像帖。来源:北邮人论坛 / cpp / #40595同步于 2010/6/20
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
哪位大哥帮我一下,把这个伪代码改成能运行的代码,毕设急求
select603
2010/6/20镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
orz……光线追踪……bd……
有个HTML5 + javascript 的简单实现……
http://www.cnblogs.com/miloyip/archive/2010/03/29/1698953.html
【 在 Vampire 的大作中提到: 】
: orz……光线追踪……bd……
: 有个HTML5 + javascript 的简单实现……
: http://www.cnblogs.com/miloyip/archive/2010/03/29/1698953.html
: ...................
非常感谢