diff options
Diffstat (limited to 'src/photon.h')
-rw-r--r-- | src/photon.h | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/photon.h b/src/photon.h index 11bcfc1..ad4c26c 100644 --- a/src/photon.h +++ b/src/photon.h @@ -20,7 +20,7 @@ struct Photon int last_hit_triangle; - curandState rng; + //curandState rng; }; struct State @@ -51,7 +51,7 @@ enum enum {BREAK, CONTINUE, PASS}; // return value from propagate_to_boundary -__device__ int fill_state(State &s, Photon &p) +__device__ int fill_state(State &s, Photon &p, curandState &rng) { p.last_hit_triangle = intersect_mesh(p.position, p.direction, s.distance_to_boundary, p.last_hit_triangle); @@ -102,20 +102,20 @@ __device__ int fill_state(State &s, Photon &p) } // fill_state -__device__ void rayleigh_scatter(Photon &p) +__device__ void rayleigh_scatter(Photon &p, curandState &rng) { float theta, y; while (true) { - y = curand_uniform(&p.rng); - theta = uniform(&p.rng, 0, 2*PI); + y = curand_uniform(&rng); + theta = uniform(&rng, 0, 2*PI); if (y < powf(cosf(theta),2)) break; } - float phi = uniform(&p.rng, 0, 2*PI); + float phi = uniform(&rng, 0, 2*PI); float3 b = cross(p.polarization, p.direction); float3 c = p.polarization; @@ -128,10 +128,10 @@ __device__ void rayleigh_scatter(Photon &p) } // scatter -__device__ int propagate_to_boundary(Photon &p, State &s) +__device__ int propagate_to_boundary(Photon &p, State &s, curandState &rng) { - float absorption_distance = -s.absorption_length*logf(curand_uniform(&p.rng)); - float scattering_distance = -s.scattering_length*logf(curand_uniform(&p.rng)); + float absorption_distance = -s.absorption_length*logf(curand_uniform(&rng)); + float scattering_distance = -s.scattering_length*logf(curand_uniform(&rng)); if (absorption_distance <= scattering_distance) { @@ -153,7 +153,7 @@ __device__ int propagate_to_boundary(Photon &p, State &s) p.time += scattering_distance/(SPEED_OF_LIGHT/s.refractive_index1); p.position += scattering_distance*p.direction; - rayleigh_scatter(p); + rayleigh_scatter(p, rng); p.history |= RAYLEIGH_SCATTER; @@ -170,7 +170,7 @@ __device__ int propagate_to_boundary(Photon &p, State &s) } // propagate_to_boundary -__device__ void propagate_at_boundary(Photon &p, State &s) +__device__ void propagate_at_boundary(Photon &p, State &s, curandState &rng) { float incident_angle = acosf(dot(s.surface_normal, -p.direction)); float refracted_angle = asinf(sinf(incident_angle)*s.refractive_index1/s.refractive_index2); @@ -182,11 +182,11 @@ __device__ void propagate_at_boundary(Photon &p, State &s) float normal_probability = normal_coefficient*normal_coefficient; float reflection_coefficient; - if (curand_uniform(&p.rng) < normal_probability) + if (curand_uniform(&rng) < normal_probability) { reflection_coefficient = -sinf(incident_angle-refracted_angle)/sinf(incident_angle+refracted_angle); - if ((curand_uniform(&p.rng) < reflection_coefficient*reflection_coefficient) || isnan(refracted_angle)) + if ((curand_uniform(&rng) < reflection_coefficient*reflection_coefficient) || isnan(refracted_angle)) { p.direction = rotate(s.surface_normal, incident_angle, incident_plane_normal); @@ -203,7 +203,7 @@ __device__ void propagate_at_boundary(Photon &p, State &s) { reflection_coefficient = tanf(incident_angle-refracted_angle)/tanf(incident_angle+refracted_angle); - if ((curand_uniform(&p.rng) < reflection_coefficient*reflection_coefficient) || isnan(refracted_angle)) + if ((curand_uniform(&rng) < reflection_coefficient*reflection_coefficient) || isnan(refracted_angle)) { p.direction = rotate(s.surface_normal, incident_angle, incident_plane_normal); @@ -220,7 +220,7 @@ __device__ void propagate_at_boundary(Photon &p, State &s) } // propagate_at_boundary -__device__ int propagate_at_surface(Photon &p, State &s) +__device__ int propagate_at_surface(Photon &p, State &s, curandState &rng) { Surface surface = surfaces[s.surface_index]; @@ -232,7 +232,7 @@ __device__ int propagate_at_surface(Photon &p, State &s) // since the surface properties are interpolated linearly, we are // guaranteed that they still sum to 1.0. - float uniform_sample = curand_uniform(&p.rng); + float uniform_sample = curand_uniform(&rng); if (uniform_sample < absorb) { @@ -247,13 +247,13 @@ __device__ int propagate_at_surface(Photon &p, State &s) else if (uniform_sample < absorb + detect + reflect_diffuse) { // diffusely reflect - p.direction = uniform_sphere(&p.rng); + p.direction = uniform_sphere(&rng); if (dot(p.direction, s.surface_normal) < 0.0f) p.direction = -p.direction; // randomize polarization? - p.polarization = cross(uniform_sphere(&p.rng), p.direction); + p.polarization = cross(uniform_sphere(&rng), p.direction); p.polarization /= norm(p.polarization); p.history |= REFLECT_DIFFUSE; |