Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #if 0
- //This function is the most intuitive--it samples a red photon. Note that the ray is NOT attenuated on any bounce!
- float3 radiance(const Ray* ray, const Scene* scene, uint2* rvec) {
- HitRecord hits_camera[N];
- 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
- float3 accumulated = (float3)(0.0f,0.0f,0.0f);
- for (int i=0;i<max_depth;++i) {
- const HitRecord* hit = hits_camera + i;
- accumulated += hit->material->color_emission;
- //Terminate ray
- if (rand_float(rvec)>hit->material->color_diffuse.x) break; //terminate based on red
- }
- return accumulated;
- }
- #else
- //This samples red, green, and blue.
- float3 radiance(const Ray* ray, const Scene* scene, uint2* rvec) {
- HitRecord hits_camera[N];
- 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
- float3 accumulated = (float3)(0.0f,0.0f,0.0f);
- float3 mask = (float3)(1.0f,1.0f,1.0f);
- for (int i=0;i<max_depth;++i) {
- const HitRecord* hit = hits_camera + i;
- accumulated += mask * hit->material->color_emission;
- //Terminate ray (if not multiply by a normalized color, so as not to attenuate the ray's intensity)
- float3 f = hit->material->color_diffuse;
- float p_reflect = (f.x + f.y + f.z)/3.0f;
- if (rand_float(rvec)>p_reflect) break;
- f /= p_reflect;
- mask *= f;
- }
- return accumulated;
- }
- #endif[
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement