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

phase flips fixed (in amplitude), removed extinction

parent 7adae652
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include <cassert> #include <cassert>
dielectric::dielectric(double index_of_refraction_inside, double index_of_refraction_outside, double extinction_inside) 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), extinction_inside(extinction_inside){ : ir_inside(index_of_refraction_inside), ir_outside(index_of_refraction_outside){
} }
...@@ -23,22 +23,17 @@ bool dielectric::scatter( ...@@ -23,22 +23,17 @@ 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;
} }
...@@ -57,17 +52,23 @@ bool dielectric::scatter( ...@@ -57,17 +52,23 @@ bool dielectric::scatter(
double sin_theta_refracted = refraction_ratio * sin_theta; double sin_theta_refracted = refraction_ratio * sin_theta;
double cos_theta_refracted = std::sqrt(1. - sin_theta_refracted * sin_theta_refracted); double cos_theta_refracted = std::sqrt(1. - sin_theta_refracted * sin_theta_refracted);
fraction_reflected = reflectance(cos_theta, cos_theta_refracted, ir_in, ir_out); fraction_reflected = reflectance(cos_theta, cos_theta_refracted, ir_in, ir_out);
fraction_refracted = 1. - fraction_reflected; //fraction_refracted = 1. - fraction_reflected;
fraction_refracted = transmittance(cos_theta, cos_theta_refracted, ir_in, ir_out);
} }
else{ else{
fraction_reflected = 1.; fraction_reflected = 1.;
fraction_refracted = 0.; fraction_refracted = 0.;
} }
int phase_flips = r_in.get_phaseflips(); int phase_flips = r_in.get_phaseflips();
/*
//Explicit handling of phase flips
r_reflected = ir_out > ir_in ? r_reflected = ir_out > ir_in ?
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_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_at(rec.t), optical_path_to_p, ir_in, extinct_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_at(rec.t), optical_path_to_p, ir_out, extinct_out, phase_flips, bounces_left - 1); */
//Phase flips are absorbed by the reflection amplitude
r_reflected = ray(rec.p, dir_reflected, fraction_reflected * r_in.get_amplitude_at(rec.t), optical_path_to_p, ir_in, 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, phase_flips, bounces_left - 1);
#ifndef NDEBUG #ifndef NDEBUG
//if(fraction_reflected > 1.){ //if(fraction_reflected > 1.){
...@@ -97,11 +98,13 @@ double dielectric::reflectance(double cos_theta_in, double cos_theta_out, double ...@@ -97,11 +98,13 @@ double dielectric::reflectance(double cos_theta_in, double cos_theta_out, double
//new amplitude reflectance coefficients //new amplitude reflectance coefficients
double rs = ( ir_in * cos_theta_in - ir_out * cos_theta_out ) / ( ir_in * cos_theta_in + ir_out * cos_theta_out ); double rs = ( ir_in * cos_theta_in - ir_out * cos_theta_out ) / ( ir_in * cos_theta_in + ir_out * cos_theta_out );
double rp = ( ir_out * cos_theta_in - ir_in * cos_theta_out ) / ( ir_out * cos_theta_in + ir_in * cos_theta_out ); double rp = ( ir_out * cos_theta_in - ir_in * cos_theta_out ) / ( ir_out * cos_theta_in + ir_in * cos_theta_out );
return 0.5 * (rs + rp); //return 0.5 * (rs + rp);
return rs;
} }
double dielectric::transmittance(double cos_theta_in, double cos_theta_out, double ir_in, double ir_out) const{ double dielectric::transmittance(double cos_theta_in, double cos_theta_out, double ir_in, double ir_out) const{
double ts = 2 * ir_in * cos_theta_in / ( ir_in * cos_theta_in + ir_out * cos_theta_out ); double ts = 2 * ir_in * cos_theta_in / ( ir_in * cos_theta_in + ir_out * cos_theta_out );
double tp = 2 * ir_in * cos_theta_in / ( ir_out * cos_theta_in + ir_in * cos_theta_out ); double tp = 2 * ir_in * cos_theta_in / ( ir_out * cos_theta_in + ir_in * cos_theta_out );
return 0.5 * (ts + tp); //return 0.5 * (ts + tp);
return ts;
} }
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