More timing functions
This commit is contained in:
parent
6331a2bf79
commit
321c677da2
12 changed files with 184 additions and 129 deletions
20
material.hpp
20
material.hpp
|
|
@ -37,9 +37,9 @@ struct lambertian : material {
|
|||
struct metal : material {
|
||||
/* Attributes */
|
||||
color albedo;
|
||||
double fuzz;
|
||||
float fuzz;
|
||||
// Constructor
|
||||
metal(const color& c, double f)
|
||||
metal(const color& c, float f)
|
||||
{
|
||||
albedo = c;
|
||||
fuzz = f;
|
||||
|
|
@ -57,17 +57,17 @@ struct metal : material {
|
|||
struct dielectric : material
|
||||
{
|
||||
/* Attributes */
|
||||
double ri; // refraction index
|
||||
float ri; // refraction index
|
||||
|
||||
// Constructor
|
||||
dielectric(double refraction_index) { ri = refraction_index; }
|
||||
dielectric(float refraction_index) { ri = refraction_index; }
|
||||
|
||||
/* Methods */
|
||||
|
||||
// Schlick's approximation of reflectance
|
||||
static double reflectance(double cosine, double ref_idx)
|
||||
static float reflectance(float cosine, float ref_idx)
|
||||
{
|
||||
double r0 = (1-ref_idx) / (1+ref_idx);
|
||||
float r0 = (1-ref_idx) / (1+ref_idx);
|
||||
r0 = r0*r0;
|
||||
return r0 + (1-r0)*pow((1 - cosine), 5);
|
||||
}
|
||||
|
|
@ -77,17 +77,17 @@ struct dielectric : material
|
|||
virtual bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override
|
||||
{
|
||||
attenuation = color(1,1,1);
|
||||
double refraction_ratio = rec.front_face ? (1.0/ri) : ri;
|
||||
float refraction_ratio = rec.front_face ? (1.0/ri) : ri;
|
||||
|
||||
vec3 unit_direction = normalize(r_in.direction);
|
||||
|
||||
double cos_theta = fmin(dot(-unit_direction, rec.normal), 1);
|
||||
double sin_theta = sqrt(1.0 - cos_theta*cos_theta);
|
||||
float cos_theta = fmin(dot(-unit_direction, rec.normal), 1);
|
||||
float sin_theta = sqrt(1.0 - cos_theta*cos_theta);
|
||||
|
||||
bool cannot_refract = refraction_ratio * sin_theta > 1.0;
|
||||
vec3 direction;
|
||||
|
||||
if (cannot_refract || reflectance(cos_theta, refraction_ratio) > random_double())
|
||||
if (cannot_refract || reflectance(cos_theta, refraction_ratio) > random_float())
|
||||
direction = reflect(unit_direction, rec.normal);
|
||||
else
|
||||
direction = refract(unit_direction, rec.normal, refraction_ratio);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue