Ejemplo n.º 1
0
bool PhongMetalMaterial::specularDirection(const ONB& uvw, const Vector3D& v_in, const Vector3D& p, const Vector2D& uv,
        Vector2D& seed, ColorRGB& color, Vector3D& v_out)
{
    float phi = 2* PI* seed.getX();
    //the phong exponent is stored in the red value for the texture at that point
    float exponent = phong_exp->value(uv, p).getRed();
    float cosTheta = pow(1-seed.getY(), 1.0/(exponent+1));
    float sinTheta = sqrt(1-cosTheta*cosTheta);
    float x = cos(phi) * sinTheta;
    float y = sin(phi) * sinTheta;
    float z = cosTheta;


    ONB basis;
    Vector3D w = v_in - 2*dotProduct(v_in, uvw.w())*uvw.w();
    basis.initFromW(w);

    //color = R->value(uv, p);
    ColorRGB r = R->value(uv, p);
    float c = 1 - (dotProduct(v_in, uvw.w()));
    color = r + (ColorRGB(1, 1, 1) + (-r))*(c*c*c*c*c);
    v_out = x*basis.u() + y*basis.v() + z*basis.w();

    if(exponent <10000) seed.scramble();
    return (dotProduct(v_out, uvw.w()) >0 );

}
Ejemplo n.º 2
0
bool DSphere::randomPoint(const Vector3 &viewpoint, const Vector2 &seed, float time, Vector3 &light_point, Vector3 &N, float &pdf, Color &radiance) const {
    float d = (viewpoint - getCenter(0)).magnitude();
    if (d < radius) {return false;}
    float r = radius;
    //internal angle of cone surrounding light seen from viewpoint
    float sin_alpha_max = r / d;
    float cos_alpha_max = sqrt(1 - sin_alpha_max * sin_alpha_max);
    float q = 1.0 / (2*M_PI*(1 - cos_alpha_max));
    float cos_alpha = 1 + seed.x() * (cos_alpha_max - 1);
    float sin_alpha = sqrt(1 - cos_alpha * cos_alpha);
    float phi = 2*M_PI*seed.y();
    float cos_phi = cos(phi);
    float sin_phi = sin(phi);
    Vector3 k_i(cos_phi * sin_alpha, sin_phi * sin_alpha, cos_alpha);
    //construct local coordinate system UVW where viewpoint at origin and sphere at (0,0,d) in UVW
    ONB UVW;
    UVW.initFromW(getCenter(0) - viewpoint);
    Ray to_light(viewpoint, k_i.x() * UVW.u() + k_i.y() * UVW.v() + k_i.z() * UVW.w());
    
    IntersectRecord rec;
    if (this -> intersect(to_light, 0.00001, FLT_MAX, time, rec)) {
        light_point = rec.intersection;
        float cos_theta_prime = -dot(rec.uvw.w(), to_light.direction());
        pdf = q * cos_theta_prime / (light_point - viewpoint).squaredMagnitude();
        N = rec.uvw.w();
        radiance = mptr -> emittedRadiance(rec.uvw, -to_light.direction(), light_point, rec.uv);
        return true;
    }
    return false;
}
Ejemplo n.º 3
0
bool PhongMetalMaterial::specularDirection(const ONB& uvw, const Vector3& v_in, const Vector3& p, const Vector2& uv, Vector2& seed, Color& color, Vector3& v_out) {
    float phi = 2 * M_PI * seed.x();
    float exponent = phong_exp -> value(uv, p).getRed();
    float cosTheta = pow(1 - seed.y(), 1.0 / (exponent + 1));
    float sinTheta = sqrt(1 - cosTheta*cosTheta);
    float x = cos(phi) * sinTheta;
    float y = sin(phi) * sinTheta;
    float z = cosTheta;
    
    ONB basis;
    Vector3 w = v_in - 2*dot(v_in, uvw.w()) * uvw.w();
    basis.initFromW(w);
    
    color = tex -> value(uv, p);
    v_out = x*basis.u() + y*basis.v() + z*basis.w();
    
    if (exponent < 10000) {/*seed.scramble();*/}
    return dot(v_out, uvw.w()) > 0;
}