本文整理汇总了C++中HitInfo::normal方法的典型用法代码示例。如果您正苦于以下问题:C++ HitInfo::normal方法的具体用法?C++ HitInfo::normal怎么用?C++ HitInfo::normal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HitInfo
的用法示例。
在下文中一共展示了HitInfo::normal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: traceSinglePhoton
void PhotonTracer::traceSinglePhoton(IPhotonMap& photonMap, int photonCount) const {
float randomVector[RANDOM_DIMENSION];
randomSet_->nextf(randomVector);
Spectrum power;
ray3f ray(light_->samplePhoton(
power,
vec2f(
Lcg::global().nextf(),
Lcg::global().nextf()),
vec2f(
randomAt(randomVector, 0),
randomAt(randomVector, 1))));
power /= static_cast<float>(photonCount); // split power
HitInfo hit = HitInfo::createUninitialized();
float currentRefractiveIndex = 1;
int bounceCount = 0;
while( scene_->raytrace(ray, hit) ) {
if(bounceCount > 0) {
Photon photon(
hit.position(),
hit.normal(),
power);
photonMap.add(photon);
}
Material const& material = hit.material();
if(material.getType() == Material::MATERIAL_DIFFUSE) {
float u = Lcg::global().nextf();
// Russian roulette.
if(u <= material.getReflectance().average()) {
power *= material.getReflectance()
/ material.getReflectance().average();
ray = ray3f(
hit.position(),
Hemisphere::cosineWeightedDirection(
hit.normal(),
randomAt(randomVector, 2+2*bounceCount),
randomAt(randomVector, 3+2*bounceCount)));
} else {
break;
}
} else if(material.getType() == Material::MATERIAL_SPECULAR) {
float u = Lcg::global().nextf();
// Russian roulette.
if(u <= material.getReflectance().average()) {
power *= material.getReflectance()
/ material.getReflectance().average();
ray = ray3f(
hit.position(),
Hemisphere::mirrorReflection(
hit.normal(),
ray.getDirection()));
} else {
break;
}
} else if(material.getType() == Material::MATERIAL_DIELECTRIC) {
float fresnel = Hemisphere::fresnelCoefficient(
hit.normal(), ray.getDirection(),
currentRefractiveIndex,
material.getRefractiveIndex());
float u = Lcg::global().nextf();
if(u < 1 - fresnel) {
// refraction
vec3f excitantDirection;
if( Hemisphere::computeRefraction(
hit.normal(), ray.getDirection(),
currentRefractiveIndex,
material.getRefractiveIndex(),
excitantDirection) ) {
ray = ray3f(
hit.position(),
excitantDirection);
currentRefractiveIndex = material.getRefractiveIndex();
} else {
// total internal reflection
ray = ray3f(
hit.position(),
Hemisphere::mirrorReflection(
hit.normal(),
ray.getDirection()));
//.........这里部分代码省略.........