diff options
-rw-r--r-- | src/photon.h | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/photon.h b/src/photon.h index da866bc..69ecd34 100644 --- a/src/photon.h +++ b/src/photon.h @@ -16,39 +16,28 @@ struct Photon float wavelength; float time; - //bool alive; - //unsigned int last_process; unsigned int history; int last_hit_triangle; - //int photon_state; - curandState rng; }; struct State { float3 surface_normal; - //Material material1, material2; - //Surface surface; float refractive_index1, refractive_index2; float absorption_length; float scattering_length; - //float absorption_distance; - //float scattering_distance; int surface_index; - //int last_hit_triangle; float distance_to_boundary; }; enum { - //DEBUG = -2, - //INIT = -1, NO_HIT = 0x1 << 0, BULK_ABSORB = 0x1 << 1, SURFACE_DETECT = 0x1 << 2, @@ -191,27 +180,38 @@ __device__ void propagate_at_boundary(Photon &p, State &s) { reflection_coefficient = -sinf(incident_angle-refracted_angle)/sinf(incident_angle+refracted_angle); + if ((curand_uniform(&p.rng) < reflection_coefficient*reflection_coefficient) || isnan(refracted_angle)) + { + p.direction = rotate(s.surface_normal, incident_angle, incident_plane_normal); + + p.history |= REFLECT_SPECULAR; + } + else + { + p.direction = rotate(s.surface_normal, PI-refracted_angle, incident_plane_normal); + } + p.polarization = incident_plane_normal; } // photon polarization normal to plane of incidence else { reflection_coefficient = tanf(incident_angle-refracted_angle)/tanf(incident_angle+refracted_angle); + if ((curand_uniform(&p.rng) < reflection_coefficient*reflection_coefficient) || isnan(refracted_angle)) + { + p.direction = rotate(s.surface_normal, incident_angle, incident_plane_normal); + + p.history |= REFLECT_SPECULAR; + } + else + { + p.direction = rotate(s.surface_normal, PI-refracted_angle, incident_plane_normal); + } + p.polarization = cross(incident_plane_normal, p.direction); p.polarization /= norm(p.polarization); } // photon polarization parallel to plane of incidence - if ((curand_uniform(&p.rng) < reflection_coefficient*reflection_coefficient) || isnan(refracted_angle)) - { - p.direction = rotate(s.surface_normal, incident_angle, incident_plane_normal); - - p.history |= REFLECT_SPECULAR; - } - else - { - p.direction = rotate(s.surface_normal, PI-refracted_angle, incident_plane_normal); - } - } // propagate_at_boundary __device__ int propagate_at_surface(Photon &p, State &s) |