Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 47 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. float3 direct_light(const float3& position) {
  2.     // direct light inside volume including phase function and beam transmittance
  3. }
  4.  
  5. float3 homogeneous2(const Ray& ray, float3& transmittance) {
  6.     float3 radiance(0.f);
  7.    
  8.     if (Algorithm::Tracking == algorithm) {
  9.         const float3 sigma_a = material.absorption(float3::identity());
  10.  
  11.         const float3 sigma_s = material.scattering(float3::identity());
  12.  
  13.         const float3 extinction = sigma_a + sigma_s;
  14.  
  15.         const float3 scattering_albedo = sigma_s / extinction;
  16.  
  17.         transmittance = math::exp(-d * extinction);
  18.  
  19.         const float r = rng_.random_float();
  20.         const float scatter_distance = -std::log(1.f - r * (1.f - average(transmittance))) / average(extinction);
  21.  
  22.         const float3 p = ray.point(scatter_distance);
  23.  
  24.         float3 l = direct_light(p);
  25.  
  26.         l *= (1.f - transmittance) * scattering_albedo;
  27.  
  28.         radiance = l;
  29.     } else if (Algorithm::Delta_tracking == algorithm) {
  30.         const float max_extinction = average(material.max_extinction());
  31.         bool terminated = false;
  32.         float t = 0.f;
  33.  
  34.         float3 p;
  35.         float3 extinction;
  36.         float3 scattering_albedo;
  37.  
  38.         do {
  39.             const float r = rng_.random_float();
  40.             t = t -std::log(1.f - r) / max_extinction;
  41.             if (t > d) {
  42.                 break;
  43.             }
  44.  
  45.             p = ray.point(t);
  46.  
  47.             const float3 sigma_a = material.absorption(p);
  48.  
  49.             const float3 sigma_s = material.scattering(p);
  50.  
  51.             extinction = sigma_a + sigma_s;
  52.             const float r2 = rng_.random_float();
  53.             if (r2 < average(extinction) / max_extinction) {
  54.                 terminated = true;
  55.  
  56.                 scattering_albedo = sigma_s / extinction;
  57.             }
  58.         } while (!terminated);
  59.  
  60.         if (terminated) {
  61.             float3 l = direct_light(p);
  62.  
  63.             l *= scattering_albedo * extinction;
  64.  
  65.             radiance = l;
  66.  
  67.             transmittance = float3(0.f);
  68.         } else {
  69.             radiance = float3(0.f);
  70.             transmittance = float3(1.f);
  71.         }
  72.     } else if (Algorithm::Experiment == algorithm) {
  73.         // Exactly the same as Delta-tracking,
  74.         // except that L is multiplied by scattering_albedo, instead of sigma_s
  75.         const float max_extinction = average(material.max_extinction());
  76.         bool terminated = false;
  77.         float t = 0.f;
  78.  
  79.         float3 p;
  80.         float3 scattering_albedo;
  81.  
  82.         do {
  83.             const float r = rng_.random_float();
  84.             t = t -std::log(1.f - r) / max_extinction;
  85.             if (t > d) {
  86.                 break;
  87.             }
  88.  
  89.             p = ray.point(t);
  90.  
  91.             const float3 sigma_a = material.absorption(p);
  92.  
  93.             const float3 sigma_s = material.scattering(p);
  94.  
  95.             const float3 extinction = sigma_a + sigma_s;
  96.             const float r2 = rng_.random_float();
  97.             if (r2 < average(extinction) / max_extinction) {
  98.                 terminated = true;
  99.  
  100.                 scattering_albedo = sigma_s / extinction;
  101.             }
  102.         } while (!terminated);
  103.  
  104.         if (terminated) {
  105.             float3 l = direct_light(p);
  106.  
  107.             l *= scattering_albedo;
  108.  
  109.             radiance = l;
  110.  
  111.             transmittance = float3(0.f);
  112.         } else {
  113.             radiance = float3(0.f);
  114.             transmittance = float3(1.f);
  115.         }
  116.     }
  117.  
  118.     return radiance;
  119. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top