Advertisement
Guest User

Untitled

a guest
Aug 1st, 2012
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.59 KB | None | 0 0
  1. #if 0
  2. //This function is the most intuitive--it samples a red photon.  Note that the ray is NOT attenuated on any bounce!
  3. float3 radiance(const Ray* ray, const Scene* scene, uint2* rvec) {
  4.     HitRecord hits_camera[N];
  5.     int max_depth = generate_path(ray,N, scene,rvec, hits_camera,NULL); //generate a random path; each ray is generated from a cosine-weighted distribution
  6.  
  7.     float3 accumulated = (float3)(0.0f,0.0f,0.0f);
  8.     for (int i=0;i<max_depth;++i) {
  9.         const HitRecord* hit = hits_camera + i;
  10.  
  11.         accumulated += hit->material->color_emission;
  12.  
  13.         //Terminate ray
  14.         if (rand_float(rvec)>hit->material->color_diffuse.x) break; //terminate based on red
  15.     }
  16.  
  17.     return accumulated;
  18. }
  19. #else
  20. //This samples red, green, and blue.
  21. float3 radiance(const Ray* ray, const Scene* scene, uint2* rvec) {
  22.     HitRecord hits_camera[N];
  23.     int max_depth = generate_path(ray,N, scene,rvec, hits_camera,NULL); //generate a random path; each ray is generated from a cosine-weighted distribution
  24.     float3 accumulated = (float3)(0.0f,0.0f,0.0f);
  25.     float3 mask = (float3)(1.0f,1.0f,1.0f);
  26.     for (int i=0;i<max_depth;++i) {
  27.         const HitRecord* hit = hits_camera + i;
  28.         accumulated += mask * hit->material->color_emission;
  29.  
  30.         //Terminate ray (if not multiply by a normalized color, so as not to attenuate the ray's intensity)
  31.         float3 f = hit->material->color_diffuse;
  32.         float p_reflect = (f.x + f.y + f.z)/3.0f;
  33.         if (rand_float(rvec)>p_reflect) break;
  34.         f /= p_reflect;
  35.         mask *= f;
  36.     }
  37.  
  38.     return accumulated;
  39. }
  40. #endif[
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement