Example #1
0
    def sample_p(self, p, u1, u2):
        """Sample at point p."""
        # Compute coordinate system for sphere sampling
        p_center = self.object_to_world(Point(0, 0, 0))
        wc = normalize(p_center - p)
        wc_x, wc_y = coordinate_system(wc)

        # Sample uniformly on sphere if $\pt{}$ is inside it
        if (distance_squared(p, p_center) - self.radius * self.radius) < 1e-4:
            return self.sample(u1, u2)

        # Sample sphere uniformly inside subtended cone
        sin_theta_max2 = self.radius * self.radius / distance_squared(
            p, p_center)
        cos_theta_max = math.sqrt(max(0.0, 1.0 - sin_theta_max2))
        raise Exception("next_line")
        # r = Ray(p, uniform_sample_cone(u1, u2, cos_theta_max, wcX, wcY, wc), 1e-3)
        r = Ray(p)
        intersect, t_hit, ray_epsilon, dg_sphere = self.intersect(r)
        if not intersect:
            t_hit = dot(p_center - p, normalize(r.d))
        ps = r(t_hit)
        ns = Normal(normalize(ps - p_center))
        if (self.reverse_orientation):
            ns *= -1.0
        return ps, ns
Example #2
0
    def sample_p(self, p, u1, u2):
        """Sample at point p."""
        # Compute coordinate system for sphere sampling
        p_center = self.object_to_world(Point(0, 0, 0))
        wc = normalize(p_center - p)
        wc_x, wc_y = coordinate_system(wc)

        # Sample uniformly on sphere if $\pt{}$ is inside it
        if (distance_squared(p, p_center) - self.radius * self.radius) < 1e-4:
            return self.sample(u1, u2)

        # Sample sphere uniformly inside subtended cone
        sin_theta_max2 = self.radius * self.radius / distance_squared(p, p_center)
        cos_theta_max = math.sqrt(max(0.0, 1.0 - sin_theta_max2))
        raise Exception("next_line")
        # r = Ray(p, uniform_sample_cone(u1, u2, cos_theta_max, wcX, wcY, wc), 1e-3)
        r = Ray(p)
        intersect, t_hit, ray_epsilon, dg_sphere = self.intersect(r)
        if not intersect:
            t_hit = dot(p_center - p, normalize(r.d))
        ps = r(t_hit)
        ns = Normal(normalize(ps - p_center))
        if self.reverse_orientation:
            ns *= -1.0
        return ps, ns
Example #3
0
    def pdf_wi(self, p, wi):
        """Intersect sample ray with area light geometry."""
        p_center = self.object_to_world(Point(0, 0, 0))
        # Return uniform weight if point inside sphere
        if (distance_squared(p, p_center) - self.radius * self.radius) < 1e-4:
            return Shape.pdf_wi(self, p, wi)

        # Compute general sphere weight
        sin_theta_max2 = self.radius * self.radius / distance_squared(p, p_center)
        cos_theta_max = math.sqrt(max(0.0, 1.0 - sin_theta_max2))
        raise Exception("next_line")
        # return uniform_cone_pdf(cos_theta_max)
        return 0.0
Example #4
0
    def pdf_wi(self, p, wi):
        """Intersect sample ray with area light geometry."""
        p_center = self.object_to_world(Point(0, 0, 0))
        # Return uniform weight if point inside sphere
        if (distance_squared(p, p_center) - self.radius * self.radius) < 1e-4:
            return Shape.pdf_wi(self, p, wi)

        # Compute general sphere weight
        sin_theta_max2 = self.radius * self.radius / distance_squared(
            p, p_center)
        cos_theta_max = math.sqrt(max(0.0, 1.0 - sin_theta_max2))
        raise Exception("next_line")
        # return uniform_cone_pdf(cos_theta_max)
        return 0.0
Example #5
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