22 if(
dot(ray.direction, n) > 0)
27 r.origin= p + 0.001f * nn;
28 r.direction= ray.direction - 2 *
dot(ray.direction, nn) * nn;
38 float cos_theta= -
dot(ray.direction, n);
45 cos_theta= -cos_theta;
49 float sin2_theta= i*i * (1.f - cos_theta*cos_theta);
52 t.origin= p - 0.001f * nn;
57 t.direction= i * (ray.direction + cos_theta * nn) - std::sqrt(1.f - sin2_theta) * nn;
61 bool fresnel_refract(
const Ray& ray,
const Point& p,
const Vector& n,
const float ir )
66 float cos_theta= -
dot(ray.direction, n);
75 float sin2_theta= i*i * (1.f - cos_theta*cos_theta);
76 return (sin2_theta < 1.f);
79 float fresnel(
const Ray& ray,
const Point& p,
const Vector& n,
const float ir )
84 float cos_theta= -
dot(ray.direction, n);
93 float sin2_theta= i*i * (1.f - cos_theta*cos_theta);
99 cos_theta= std::sqrt(1.f - sin2_theta);
102 float r0= (n1 - n2) / (n1 + n2);
105 float c= 1.f - cos_theta;
106 return r0 + (1.f - r0) * c*c*c*c*c;
representation d'un vecteur 3d.
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
representation d'un rayon.
representation d'un point 3d.