本文整理汇总了C++中Intersection::object方法的典型用法代码示例。如果您正苦于以下问题:C++ Intersection::object方法的具体用法?C++ Intersection::object怎么用?C++ Intersection::object使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intersection
的用法示例。
在下文中一共展示了Intersection::object方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shade
Color Scene::shade(Intersection isect, Ray r, int level) {
if (!isect.hits()) {
return bgColor;
}
real eps;
if (r.in()) {
eps = 0.00001;
} else {
eps = -0.00001;
}
Texture *txt = isect.object()->getTexture();
Point isectPt = r.pointOn(isect.t());
Color curColor(0.0,0.0,0.0);
Color specular(0,0,0);
Color diffuse(0,0,0);
Color shadowAmt(1,1,1);
for (LightList::iterator lt_iter = lights.begin();
lt_iter != lights.end();
++lt_iter) {
Vector specL((*lt_iter)->location()-isectPt);
Vector specV(cam.getLocation()-isectPt);
Vector specHj((specL+specV)*(1.0/((specL+specV).length())));
Ray shade_ray = (*lt_iter)->getRayTo(r.pointOn(isect.t()+ eps));
++shadow_rays_cast;
Intersection tempI = rtrace(shade_ray, true, isect.object());
if (tempI.hits()) {
if (level>0) {
shadowAmt -= shade(tempI, shade_ray, level-1);
} else {
shadowAmt = Color(0.0,0.0,0.0);
}
}
specular += (*lt_iter)->intensity()*std::pow(specHj.dot(isect.normal()), txt->n());
diffuse += (*lt_iter)->intensity()*shade_ray.getDir().dot(isect.normal());
}
shadowAmt *= 1.0/real(lights.size());
Color reflective(0.0,0.0,0.0,0.0);
if ((level>0)
&& (txt->kr().intensity()>0.01)) {
++reflective_rays_cast;
Ray tempRay(r.pointOn(isect.t()+eps),
r.getDir()
- 2.0
* (r.getDir().dot(isect.normal()))
* isect.normal());
reflective = shade(rtrace(tempRay), tempRay, level-1);
}
Color refractive(0.0,0.0,0.0);
if ((level>0)
&& (txt->kt().intensity()>0.01)) {
real eta;
if (r.in()) {
eta = 1.0/txt->ior();
} else {
eta = txt->ior();
}
real ci;
if (r.in()) {
ci = (r.getDir().dot(-1.0*isect.normal()));
} else {
ci = (r.getDir().dot(isect.normal()));
}
real costt = 1.0 - (eta*eta) * (1.0-ci*ci);
if (costt<0.0) {
refractive = Color(0,0,0);
} else {
++refractive_rays_cast;
Ray tempRay(r.pointOn(isect.t()+eps),
((eta*ci-std::sqrt(costt))*((r.in()?-1.0:1.0)*isect.normal())
- (eta*r.getDir())),
!r.in());
refractive = shade(rtrace(tempRay, isect.object()), tempRay, level-1);
}
}
curColor +=
txt->ka()
+ (txt->kd()*diffuse
+ txt->ks()*specular
+ txt->kr()*reflective
+ txt->kt()*refractive)
* shadowAmt;
return curColor.clamp();
}