本文整理汇总了C++中Sampler::GetDouble方法的典型用法代码示例。如果您正苦于以下问题:C++ Sampler::GetDouble方法的具体用法?C++ Sampler::GetDouble怎么用?C++ Sampler::GetDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sampler
的用法示例。
在下文中一共展示了Sampler::GetDouble方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
Color DiffuseReflection::f(const Vector & normal, const Vector & wo, Vector * wi, double * pdf, Sampler &sampler)
{
Vector n = Vector::Dot(normal,wo) >= 0 ? normal : -normal;
/*
Vector tangent, bitangent;
if (std::fabs(n.x) > 0.9)
{
tangent = Vector(0, 1, 0);
}
else
{
tangent = Vector(1, 0, 0);
}
tangent -= n*Vector::Dot(n, tangent);
tangent = tangent.Normalize();
bitangent = Vector::Cross(n, tangent).Normalize();*/
/*
* Frisvad J R. Building an orthonormal basis from a 3D unit vector without normalization[J].
* Journal of Graphics Tools, 2012, 16(3): 151-159.
*/
Vector tangent, bitangent;
if (n.z < -0.9999999)
{
tangent = Vector(0, -1, 0);
bitangent = Vector(-1, 0, 0);
}
else
{
const double a = 1.0 / (1.0 + n.z);
const double b = -n.x*n.y*a;
tangent = Vector(1.0 - n.x*n.x*a, b, -n.x);
bitangent = Vector(b, 1.0 - n.y*n.y*a, -n.y);
}
/*
* cosine sample vector around normal
*/
const double u1 = sampler.GetDouble();
const double u2 = sampler.GetDouble();
const double r = std::sqrt(u1);
const double theta = 2 * M_PI * u2;
*wi = tangent*(r*std::cos(theta)) + bitangent*(r*std::sin(theta)) + n*std::sqrt(std::fmax(0, 1 - u1));
/* if return color/PI , then pdf=1.0/PI.
* we simplify this by returning color and setting pdf=1.0
*/
*pdf = 1.0;
return m_color;
}