I am trying to implement a path tracer, but I have some problem. The class Spectrum
is color. I implemented a mirror material like this:
Spectrum MirrorBSDF::f(const Vector3D& wo, const Vector3D& wi)
{
return reflectance * (1.0 / abs_cos_theta(wo));
}
The reflectance is a Spectrum variable. And now I want to add a material "Glass" that can reflect and refract. It meets the Fresnel theorem. Can someone teach me how to implement this? The function f
is used like this:
Spectrum light_L = light->sample_L(hit_p, &dir_to_light, &dist_to_light, &pdf);
// convert direction into coordinate space of the surface, where surface normal is [0 0 1]
Vector3D w_in = w2o * dir_to_light;
double cos_theta = std::max(0.0, w_in[2]);
Spectrum f = isect.bsdf->f(w_out, w_in);
// TODO: Construct a shadow ray and compute whether the intersected surface is
// in shadow and accumulate reflected radiance
Ray shadow_ray(hit_p + EPS_D * dir_to_light, dir_to_light,
dist_to_light - (EPS_D * dir_to_light).norm(), 0);
if (!bvh->intersect(shadow_ray))
{
L_out += (f * light_L * (cos_theta * scale / pdf));
}