Skip to content
Snippets Groups Projects
Commit d0250989 authored by Pascal Engeler's avatar Pascal Engeler
Browse files

added extinction coefficient, removed wrong assertions

parent 8caafb54
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#include <cmath> #include <cmath>
#include <cassert> #include <cassert>
dielectric::dielectric(double index_of_refraction_inside, double index_of_refraction_outside) dielectric::dielectric(double index_of_refraction_inside, double index_of_refraction_outside, double extinction_inside)
: ir_inside(index_of_refraction_inside), ir_outside(index_of_refraction_outside){ : ir_inside(index_of_refraction_inside), ir_outside(index_of_refraction_outside), extinction_inside(extinction_inside){
} }
...@@ -23,17 +23,22 @@ bool dielectric::scatter( ...@@ -23,17 +23,22 @@ bool dielectric::scatter(
vec3 unit_direction = unit_vector(r_in.direction()); vec3 unit_direction = unit_vector(r_in.direction());
double refraction_ratio; double refraction_ratio;
double ir_in, ir_out; double ir_in, ir_out;
double extinct_in, extinct_out;
vec3 relevant_normal; vec3 relevant_normal;
if(rec.inbound){ if(rec.inbound){
refraction_ratio = ir_outside / ir_inside; refraction_ratio = ir_outside / ir_inside;
ir_in = ir_outside; ir_in = ir_outside;
ir_out = ir_inside; ir_out = ir_inside;
extinct_in = 0.;
extinct_out = extinction_inside;
relevant_normal = rec.normal; relevant_normal = rec.normal;
} }
else{ else{
refraction_ratio = ir_inside / ir_outside; refraction_ratio = ir_inside / ir_outside;
ir_in = ir_inside; ir_in = ir_inside;
ir_out = ir_outside; ir_out = ir_outside;
extinct_in = extinction_inside.;
extinct_out = 0.;
relevant_normal = -rec.normal; relevant_normal = -rec.normal;
} }
...@@ -60,9 +65,9 @@ bool dielectric::scatter( ...@@ -60,9 +65,9 @@ bool dielectric::scatter(
} }
int phase_flips = r_in.get_phaseflips(); int phase_flips = r_in.get_phaseflips();
r_reflected = ir_out > ir_in ? r_reflected = ir_out > ir_in ?
ray(rec.p, dir_reflected, fraction_reflected * r_in.get_amplitude(), optical_path_to_p, ir_in, phase_flips + 1, bounces_left - 1) : ray(rec.p, dir_reflected, fraction_reflected * r_in.get_amplitude_at(rec.t), optical_path_to_p, ir_in, extinct_in, phase_flips + 1, bounces_left - 1) :
ray(rec.p, dir_reflected, fraction_reflected * r_in.get_amplitude(), optical_path_to_p, ir_in, phase_flips, bounces_left - 1); ray(rec.p, dir_reflected, fraction_reflected * r_in.get_amplitude_at(rec.t), optical_path_to_p, ir_in, extinct_in, phase_flips, bounces_left - 1);
r_refracted = ray(rec.p, dir_refracted, fraction_refracted * r_in.get_amplitude(), optical_path_to_p, ir_out, phase_flips, bounces_left - 1); r_refracted = ray(rec.p, dir_refracted, fraction_refracted * r_in.get_amplitude_at(rec.t), optical_path_to_p, ir_out, extinct_out, phase_flips, bounces_left - 1);
#ifndef NDEBUG #ifndef NDEBUG
//if(fraction_reflected > 1.){ //if(fraction_reflected > 1.){
...@@ -74,9 +79,9 @@ bool dielectric::scatter( ...@@ -74,9 +79,9 @@ bool dielectric::scatter(
std::cerr << "refracted ray: origin: " << r_refracted.origin() << ", direction: " << r_refracted.direction() << std::endl; std::cerr << "refracted ray: origin: " << r_refracted.origin() << ", direction: " << r_refracted.direction() << std::endl;
//} //}
#endif #endif
assert(fraction_reflected >= 0. && fraction_refracted >= 0.); //assert(fraction_reflected >= 0. && fraction_refracted >= 0.);
assert(fraction_reflected <= 1. && fraction_refracted <= 1.); //assert(fraction_reflected <= 1. && fraction_refracted <= 1.);
assert(std::fabs(fraction_refracted + fraction_reflected - 1.) < 0.00000001); //assert(std::fabs(fraction_refracted + fraction_reflected - 1.) < 0.00000001);
assert(r_reflected.origin().x() == rec.p.x() && r_reflected.origin().y() == rec.p.y() && r_reflected.origin().z() == rec.p.z()); assert(r_reflected.origin().x() == rec.p.x() && r_reflected.origin().y() == rec.p.y() && r_reflected.origin().z() == rec.p.z());
assert(r_refracted.origin().x() == rec.p.x() && r_refracted.origin().y() == rec.p.y() && r_refracted.origin().z() == rec.p.z()); assert(r_refracted.origin().x() == rec.p.x() && r_refracted.origin().y() == rec.p.y() && r_refracted.origin().z() == rec.p.z());
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
class dielectric: public material{ class dielectric: public material{
public: public:
dielectric(double index_of_refraction_inside, double index_of_refraction_outside); dielectric(double index_of_refraction_inside, double index_of_refraction_outside, double extinction_inside = 0.);
virtual bool scatter( virtual bool scatter(
const ray& r_in, const hit_record& rec, const ray& r_in, const hit_record& rec,
...@@ -19,6 +19,7 @@ private: ...@@ -19,6 +19,7 @@ private:
double ir_inside; //index of refraction inside material double ir_inside; //index of refraction inside material
double ir_outside; //index of refraction outside material double ir_outside; //index of refraction outside material
double extinction_inside; //exponential extinction coefficient inside material
}; };
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment