Ejemplo n.º 1
0
void LightSampler::sample_emitting_triangle(
    const ShadingRay::Time&             time,
    const Vector2d&                     s,
    const size_t                        triangle_index,
    const double                        triangle_prob,
    LightSample&                        light_sample) const
{
    // Fetch the emitting triangle.
    const EmittingTriangle& emitting_triangle = m_emitting_triangles[triangle_index];
    assert(emitting_triangle.m_triangle_prob == triangle_prob);

    // Store a pointer to the emitting triangle.
    light_sample.m_triangle = &emitting_triangle;

    // Uniformly sample the surface of the triangle.
    const Vector3d bary = sample_triangle_uniform(s);

    // Set the barycentric coordinates.
    light_sample.m_bary[0] = bary[0];
    light_sample.m_bary[1] = bary[1];

    // Compute the world space position of the sample.
    light_sample.m_point =
          bary[0] * emitting_triangle.m_v0
        + bary[1] * emitting_triangle.m_v1
        + bary[2] * emitting_triangle.m_v2;

    // Compute the world space shading normal at the position of the sample.
    light_sample.m_shading_normal =
          bary[0] * emitting_triangle.m_n0
        + bary[1] * emitting_triangle.m_n1
        + bary[2] * emitting_triangle.m_n2;
    light_sample.m_shading_normal = normalize(light_sample.m_shading_normal);

    // Set the world space geometric normal.
    light_sample.m_geometric_normal = emitting_triangle.m_geometric_normal;

    // Compute the probability density of this sample.
    light_sample.m_probability = triangle_prob * emitting_triangle.m_rcp_area;
}
Ejemplo n.º 2
0
void LightSampler::sample_emitting_triangle(
    const Vector2d&         s,
    const size_t            triangle_index,
    const double            triangle_prob,
    LightSample&            sample) const
{
    // Fetch and set the emitting triangle.
    const EmittingTriangle& triangle = m_emitting_triangles[triangle_index];
    sample.m_triangle = ▵

    // Uniformly sample the surface of the triangle.
    const Vector3d bary = sample_triangle_uniform(s);

    // Set the barycentric coordinates.
    sample.m_bary[0] = bary[0];
    sample.m_bary[1] = bary[1];

    // Compute the world space position of the sample.
    sample.m_point =
          bary[0] * triangle.m_v0
        + bary[1] * triangle.m_v1
        + bary[2] * triangle.m_v2;

    // Compute the world space shading normal at the position of the sample.
    sample.m_shading_normal =
          bary[0] * triangle.m_n0
        + bary[1] * triangle.m_n1
        + bary[2] * triangle.m_n2;
    sample.m_shading_normal = normalize(sample.m_shading_normal);

    // Set the world space geometric normal.
    sample.m_geometric_normal = triangle.m_geometric_normal;

    // Compute the probability of choosing this sample.
//  assert(feq(triangle_prob * triangle.m_rcp_area, m_rcp_total_emissive_area));    // subject to numerical instability
    sample.m_probability = m_rcp_total_emissive_area;
}