def Le(self, w): """Return the light emitted by the object.""" if self.primitive is None: logger.error("Intersect.Le() called with no primitive.") return Spectrum(0.0) area = self.primitive.get_area_light() if area: return area.L(self.dg.p, self.dg.nn, w) else: return Spectrum(0.0)
def Li(self, scene, ray, sample, rng, intersection=None, T=None): """Compute the incident radiance along a given ray.""" # allocate local variables for isect and T if needed if not T: T = Spectrum(0.0) if not intersection: intersection = Intersection() Li = Spectrum(0.0) hit = scene.intersect(ray, intersection) if hit: Li = self.surface_integrator.Li(scene, self, ray, intersection, sample, rng) else: # handle ray that doesn't intersect any geometry for light in scene.lights: Li += light.Le(ray) # Lvi = self.volume_integrator.Li(scene, self, ray, sample, rng, T) # return T * Li + Lvi, intersection return Li, intersection, T
def Li(self, scene, renderer, ray, intersection, sample, rng): """Computes the radiance along a ray.""" return Spectrum(1.0) L = Spectrum(0.0) # evaluate BSDF at hit point bsdf = intersection.get_bsdf(ray) # initialize common variables for Whitted integrator p = bsdf.dg_shading.p n = bsdf.dg_shading.nn wo = -ray.d # compute emitted light if ray hit an area light source L += intersection.Le(wo) # add contribution of each light source for light in self.scene.lights: light_sample = LightSample.from_rng(rng) Li, wi, pdf, visibility = light.sample_L(p, intersection.ray_epsilon, light_sample, ray.time) if Li.is_black() or pdf == 0.0: continue f = bsdf.f(wo, wi) if (not f.is_black()) and visibility.unoccluded(scene): L += f * Li * abs_dot(wi, n) * visibility.transmittance( scene, renderer, sample, rng) / pdf if ray.depth + 1 < self.max_depth: # trace rays for specular reflection and refraction L += specular_reflect(ray, bsdf, rng, intersection, renderer, scene, sample) L += specular_transmit(ray, bsdf, rng, intersection, renderer, scene, sample) return L
def __init__(self, cap=None): self.captures = [] self.dataTypes = [] self.x = [] self.y = [] self.xkey = '' self.ykey = '' self.freqMode = 'Frequency' self.mode = 'Combined' self.scansIncluded = [] self.histMode = True self.binsize = 0.03 self.spectra = [] self.combSpectrum = Spectrum() if not cap == None: self.addCapture(cap)
def run(self): """Execute the task.""" print "executing task %d/%d" % (self.task_num, self.task_count) # get sub-sampler for SamplerRendererTask sampler = self.main_sampler.get_sub_sampler(self.task_num, self.task_count) if not sampler: return # Declare local variables used for rendering loop rng = RNG(self.task_num) # allocate space for samples and intersections max_samples = sampler.maximum_sample_count() samples = self.orig_sample.duplicate(max_samples) rays = [None] * max_samples Ls = [None] * max_samples Ts = [None] * max_samples isects = [] # Intersection[max_samples] for i in range(max_samples): isects.append(Intersection()) # get samples from Sampler and update image while True: sample_count = sampler.get_more_samples(samples, rng) # if no more samples to compute, exit if sample_count <= 0: break # generate camera rays and compute radiance along rays for i in range(sample_count): # find camera ray for samples[i] ray_weight, ray_diff = self.camera.generate_ray_differential( samples[i]) rays[i] = ray_diff coeff = 1.0 / math.sqrt(sampler.samples_per_pixel) ray_diff.scale_differentials(coeff) # evaluate radiance along camera ray if ray_weight > 0.0: radiance, intersection, Ts_i = \ self.renderer.Li(self.scene, ray_diff, samples[i], rng, isects[i]) Ls_i = ray_weight * radiance else: Ls_i = Spectrum(0.0) Ts_i = Spectrum(1.0) Ls[i] = Ls_i Ts[i] = Ts_i # check for unexpected radiance values if Ls_i.has_nan(): logger.error( "Not-a-number radiance value returned for image sample. Setting to black." ) Ls_i = Spectrum(0.0) elif Ls_i.y() < -1e-5: logger.error( "Negative luminance value, %f, returned for image sample. Setting to black." % Ls_i.y()) Ls_i = Spectrum(0.0) elif Ls_i.y() == float('inf'): logger.error( "Infinite luminance value returned for image sample. Setting to black." ) Ls_i = Spectrum(0.0) # report sample results to Sampler, add contributions to image if sampler.report_results(samples, rays, Ls, isects, sample_count): for i in range(sample_count): self.camera.film.add_sample(samples[i], Ls[i]) # clean up after SamplerRendererTask is done with its image region pass