uci-rendering / psdr-cuda

Path-space differentiable renderer
BSD 3-Clause "New" or "Revised" License
155 stars 11 forks source link

[Question] Estimating the Interior Integral between paper and code #30

Closed cococolorful closed 2 years ago

cococolorful commented 2 years ago

Sorry to bother you, in fact, after reading the paper, I still can't figure out some points, so I try to improve my understanding of the paper by reading the code.

image

In lines 6 and 7 of the pseudocode, there is a mapping of p to x, but I only see code for sampling light in the code, and I don't see any mapping-related functions. Then I further checked the sampling code, as shown below, there is only the Jacobian formula, and for the processing of the mapping, it seems to directly let x=p

template <bool ad>
PositionSample<ad> Mesh::__sample_position(const Vector2f<ad> &_sample2, Mask<ad> active) const {
    PSDR_ASSERT(m_ready && m_emitter != nullptr);
    PSDR_ASSERT(m_triangle_info != nullptr);

    PositionSample<ad> result;
    Vector2f<ad> sample2 = _sample2;

    IntC idx;
    std::tie(idx, std::ignore) = m_face_distrb->sample_reuse<ad>(sample2.x());
    sample2 = warp::square_to_uniform_triangle<ad>(sample2);

    TriangleInfo<ad> tri_info;
    if constexpr ( ad ) {
        tri_info = gather<TriangleInfoD>(*m_triangle_info, IntD(idx), active);
        result.J = tri_info.face_area/detach(tri_info.face_area);
    } else {
        tri_info = gather<TriangleInfoC>(detach(*m_triangle_info), idx, active);
        result.J = 1.f;
    }
    result.p = bilinear<ad>(tri_info.p0, tri_info.e1, tri_info.e2, sample2);
    result.n = tri_info.face_normal;
    result.pdf = m_inv_total_area;
    result.is_valid = true;
    return result;
}

Then I looked at the supplementary material of the paper and saw this mapping function 𝒙 = X(𝒑, πœ‹) in the second part of the supplementary material, which is defined as follows for a triangle image

Then I got confused again, I mean, what exactly does this mapping represent. For example, in the example given in the first part of the supplementary material, to scale a sphere, define the mapping as X(p, π‘Ÿ ) = π‘Ÿp, and then calculate the derivative with respect to r. And for the vertex coordinates (x, y, z) of all triangles we want to optimize for a model. What does πœ‹ in Equation 37 in the pseudocode represent? Scalar time? Or a vector representation of all triangle vertex coordinates? And what is p_i-dot,I can't understand these things, please help me!:sob::sob::sob:

LiuLinyun commented 2 years ago

I am also a reader of this paper and project, may my comprehension will help you.

First, variable 'x' in paper means it is a point need to be optimized and can be "moved" by scene parameters, which means it requires a gradient; variable 'p' in paper means it is fixed and can not be "moved" by scene parameters, which does not require a gradient. In this project code, 'x' is computed out by a chain-ruled auto differentiable graph and can not be detached by this computational graph, after calling backward() method, it will get its gradient; and 'p' is a static variable need to be detached with this chain-ruled graph to make it can not be "moved" by scene parameters.

Second, when you are reading boundary integrator codes, you may find only sampled edge point position and its jacobi term need gradient, all other variables are fixed as detached variables, because only sampled edge point position can be optimized and "moved" by scene parameters.

Simply, mapping 'x' to 'p' is according to code "p = enoki::detach(x) ", and mapping 'p' to 'x' means attach variable 'p' to chain-ruled computational graph, but there is no proper corresponding code, if you want to get 'x', only you need to do is just keep it is computed out by chain-ruled graph and not detach it.

cococolorful commented 2 years ago

I am also a reader of this paper and project, may my comprehension will help you.

First, variable 'x' in paper means it is a point need to be optimized and can be "moved" by scene parameters, which means it requires a gradient; variable 'p' in paper means it is fixed and can not be "moved" by scene parameters, which does not require a gradient. In this project code, 'x' is computed out by a chain-ruled auto differentiable graph and can not be detached by this computational graph, after calling backward() method, it will get its gradient; and 'p' is a static variable need to be detached with this chain-ruled graph to make it can not be "moved" by scene parameters.

Second, when you are reading boundary integrator codes, you may find only sampled edge point position and its jacobi term need gradient, all other variables are fixed as detached variables, because only sampled edge point position can be optimized and "moved" by scene parameters.

Simply, mapping 'x' to 'p' is according to code "p = enoki::detach(x) ", and mapping 'p' to 'x' means attach variable 'p' to chain-ruled computational graph, but there is no proper corresponding code, if you want to get 'x', only you need to do is just keep it is computed out by chain-ruled graph and not detach it.

谒谒倧佬