Пример #1
0
 def pdf_wi(self, p, wi):
     """Intersect sample ray with area light geometry."""
     dg_light = DifferentialGeometry()
     ray = Ray(p, wi, 1e-3)
     ray.depth = -1 # temp hack to ignore alpha mask
     intersect, t_hit, ray_epsilon, dg_light = self.intersect(ray)
     if not intersect:
         return 0.0
     # convert light sample weight to solid angle measure
     pdf = distance_squared(p, ray(t_hit)) / \
           (abs_dot(dg_light.nnm -wi) * self.area())
     if pdf == float('inf'):
         return 0.0
     return pdf
Пример #2
0
    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
Пример #3
0
    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