diff options
| author | Andy Mastbaum <mastbaum@hep.upenn.edu> | 2012-04-26 18:00:29 -0400 |
|---|---|---|
| committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:39 -0700 |
| commit | 70bcf95d6bed3001256e5034b47c111f762d82c8 (patch) | |
| tree | 635252e0ccf14571d7118bc9b95cd0ec77aa9471 /chroma/cuda | |
| parent | c5882fe78ca2a4c08784a03c589c4af2a12604e8 (diff) | |
| download | chroma-70bcf95d6bed3001256e5034b47c111f762d82c8.tar.gz chroma-70bcf95d6bed3001256e5034b47c111f762d82c8.tar.bz2 chroma-70bcf95d6bed3001256e5034b47c111f762d82c8.zip | |
fixes and tweaks for surface models
All surface models including ``SURFACE_COMPLEX`` and ``SURFACE_WLS`` are now working. Note that the WLS won't work right in hybrid rendering mode since that mode relies on matching up incoming and outgoing photon wavelengths in a lookup table.
Diffstat (limited to 'chroma/cuda')
| -rw-r--r-- | chroma/cuda/geometry_types.h | 3 | ||||
| -rw-r--r-- | chroma/cuda/hybrid_render.cu | 3 | ||||
| -rw-r--r-- | chroma/cuda/photon.h | 6 | ||||
| -rw-r--r-- | chroma/cuda/random.h | 20 |
4 files changed, 26 insertions, 6 deletions
diff --git a/chroma/cuda/geometry_types.h b/chroma/cuda/geometry_types.h index ab54dfa..f82f372 100644 --- a/chroma/cuda/geometry_types.h +++ b/chroma/cuda/geometry_types.h @@ -30,13 +30,10 @@ struct Surface float *reflect_specular; float *eta; float *k; - - float *reemission_wavelength; float *reemission_cdf; unsigned int model; unsigned int n; - unsigned int reemission_n; unsigned int transmissive; float step; float wavelength0; diff --git a/chroma/cuda/hybrid_render.cu b/chroma/cuda/hybrid_render.cu index 29edefa..2c64d0e 100644 --- a/chroma/cuda/hybrid_render.cu +++ b/chroma/cuda/hybrid_render.cu @@ -44,6 +44,9 @@ to_diffuse(Photon &p, State &s, Geometry *g, curandState &rng, int max_steps) if (p.history & REFLECT_DIFFUSE) break; + if (p.history & SURFACE_REEMIT) + break; + if (command == BREAK) break; diff --git a/chroma/cuda/photon.h b/chroma/cuda/photon.h index 68ea92c..09430e9 100644 --- a/chroma/cuda/photon.h +++ b/chroma/cuda/photon.h @@ -493,7 +493,7 @@ propagate_complex(Photon &p, State &s, curandState &rng, Surface* surface, bool return BREAK; } else if (uniform_sample < absorb + reflect) { - return propagate_at_specular_reflector(p, s); + return propagate_at_diffuse_reflector(p, s, rng); } else { // transmit @@ -515,7 +515,7 @@ propagate_at_wls(Photon &p, State &s, curandState &rng, Surface *surface, bool u float uniform_sample = curand_uniform(&rng); if (use_weights && p.weight > WEIGHT_LOWER_THRESHOLD && absorb < (1.0f - WEIGHT_LOWER_THRESHOLD)) { - // Prevent absorption and reweight accordingly + // Prevent absorption and reweight accordingly float survive = 1.0f - absorb; absorb = 0.0f; p.weight *= survive; @@ -528,7 +528,7 @@ propagate_at_wls(Photon &p, State &s, curandState &rng, Surface *surface, bool u float uniform_sample_reemit = curand_uniform(&rng); if (uniform_sample_reemit < reemit) { p.history |= SURFACE_REEMIT; - p.wavelength = sample_cdf(&rng, surface->reemission_n, surface->reemission_wavelength, surface->reemission_cdf); + p.wavelength = sample_cdf(&rng, surface->n, surface->wavelength0, surface->step, surface->reemission_cdf); return propagate_at_diffuse_reflector(p, s, rng); // reemit isotropically (eh?) } diff --git a/chroma/cuda/random.h b/chroma/cuda/random.h index e9d2e75..ee528ea 100644 --- a/chroma/cuda/random.h +++ b/chroma/cuda/random.h @@ -44,6 +44,26 @@ sample_cdf(curandState *rng, int ncdf, float *cdf_x, float *cdf_y) return cdf_x[lower] * frac + cdf_x[upper] * (1.0f - frac); } +// Sample from a uniformly-sampled CDF +__device__ float +sample_cdf(curandState *rng, int ncdf, float x0, float delta, float *cdf_y) +{ + float u = curand_uniform(rng); + + int lower = 0; + int upper = ncdf - 1; + while(lower < upper-1) { + int half = (lower + upper) / 2; + if (u < cdf_y[half]) + upper = half; + else + lower = half; + } + + float frac = (u - cdf_y[lower]) / (cdf_y[upper] - cdf_y[lower]); + return (x0 + delta * lower) * frac + (x0 + delta * upper) * (1.0f - frac); +} + extern "C" { |
