示例#1
0
bool Cube::sampleDirection(PathSampleGenerator &sampler, const PositionSample &point, DirectionSample &sample) const
{
    Vec3f d = SampleWarp::cosineHemisphere(sampler.next2D());
    sample.d = TangentFrame(point.Ng).toGlobal(d);
    sample.weight = Vec3f(1.0f);
    sample.pdf = SampleWarp::cosineHemispherePdf(d);

    return true;
}
示例#2
0
void Primitive::setupTangentFrame(const IntersectionTemporary &data,
        const IntersectionInfo &info, TangentFrame &dst) const
{
    const Texture *bump = info.bsdf ? info.bsdf->bump().get() : nullptr;

    if ((!bump || bump->isConstant()) && !info.bsdf->lobes().isAnisotropic()) {
        dst = TangentFrame(info.Ns);
        return;
    }
    Vec3f T, B, N(info.Ns);
    if (!tangentSpace(data, info, T, B)) {
        dst = TangentFrame(info.Ns);
        return;
    }
    if (bump && !bump->isConstant()) {
        Vec2f dudv;
        bump->derivatives(info.uv, dudv);

        T += info.Ns*(dudv.x() - info.Ns.dot(T));
        B += info.Ns*(dudv.y() - info.Ns.dot(B));
        N = T.cross(B);
        if (N == 0.0f) {
            dst = TangentFrame(info.Ns);
            return;
        }
        if (N.dot(info.Ns) < 0.0f)
            N = -N;
        N.normalize();
    }
    T = (T - N.dot(T)*N);
    if (T == 0.0f) {
        dst = TangentFrame(info.Ns);
        return;
    }
    T.normalize();
    B = N.cross(T);

    dst = TangentFrame(N, T, B);
}
示例#3
0
void Quad::prepareForRender()
{
    _base = _transform*Vec3f(0.0f);
    _edge0 = _transform.transformVector(Vec3f(1.0f, 0.0f, 0.0f));
    _edge1 = _transform.transformVector(Vec3f(0.0f, 0.0f, 1.0f));
    _base -= _edge0*0.5f;
    _base -= _edge1*0.5f;

    Vec3f n = _edge1.cross(_edge0);
    _area = n.length();
    _invArea = 1.0f/_area;
    n /= _area;

    _frame = TangentFrame(n, _edge0.normalized(), _edge1.normalized());

    _invUvSq = 1.0f/Vec2f(_edge0.lengthSq(), _edge1.lengthSq());

    Primitive::prepareForRender();
}
bool HenyeyGreensteinPhaseFunction::sample(PathSampleGenerator &sampler, const Vec3f &wi, PhaseSample &sample) const
{
    Vec2f xi = sampler.next2D(MediumPhaseSample);
    if (_g == 0.0f) {
        sample.w = SampleWarp::uniformSphere(xi);
        sample.weight = Vec3f(1.0f);
        sample.pdf = SampleWarp::uniformSpherePdf();
    } else {
        float phi = xi.x()*TWO_PI;
        float cosTheta = (1.0f + _g*_g - sqr((1.0f - _g*_g)/(1.0f + _g*(xi.y()*2.0f - 1.0f))))/(2.0f*_g);
        float sinTheta = std::sqrt(max(1.0f - cosTheta*cosTheta, 0.0f));
        sample.w = TangentFrame(wi).toGlobal(Vec3f(
            std::cos(phi)*sinTheta,
            std::sin(phi)*sinTheta,
            cosTheta
        ));
        sample.weight = Vec3f(1.0f);
        sample.pdf = henyeyGreenstein(cosTheta);
    }
    return true;
}