Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RBComb Ray Tracer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pascal Engeler
RBComb Ray Tracer
Commits
288071d7
Commit
288071d7
authored
3 years ago
by
Pascal Engeler
Browse files
Options
Downloads
Patches
Plain Diff
phase flips fixed (in amplitude), removed extinction
parent
7adae652
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dielectric.cpp
+13
-10
13 additions, 10 deletions
src/dielectric.cpp
with
13 additions
and
10 deletions
src/dielectric.cpp
+
13
−
10
View file @
288071d7
...
@@ -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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment