<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Direct calculation of the optimal weight for MIS</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Keldysh Institute for Applied Mathematics</institution>
          ,
          <addr-line>Moscow</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>National Research University of Information Technologies</institution>
          ,
          <addr-line>Mechanics, and Optics, St. Petersburg</addr-line>
          ,
          <country country="RU">Russia</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>Sergey V. Ershov, PhD, senior researcher in the Keldysh Institute of Applied Math of RAS</institution>
        </aff>
      </contrib-group>
      <fpage>3</fpage>
      <lpage>6</lpage>
      <abstract>
        <p>A Monte-Carlo ray tracing is nowadays standard approach for lighting simulation and generation of realistic images. A widely used method for noise reduction in Monte-Carlo ray tracing is combing different means of sampling, known as Multiple Importance Sampling (MIS). For bi-directional Monte-Carlo ray tracing with photon maps (BDPM) the join paths are obtained by merging camera and light sub-paths. Since several light paths are checked against the same camera path and vice versa, the join paths obtained are not statistically independent. Thus the noise in this method does not obey the laws which are correct in simple classic Monte-Carlo with independent samples. And, correspondingly, the MIS weights that minimize that noise must also be calculated differently. In this paper we calculate these weights for a simple model scene directly minimizing the noise of calculation. This is a pure direct numerical minimization that does not involve any doubtful hypothesis or approximations. We show that the weights obtained are qualitatively different from those calculated from classic “balance heuristic” for Monte-Carlo with independent samples. They depend on the scene distance, but not only on scattering properties of the surfaces and the distribution of light source emission.</p>
      </abstract>
      <kwd-group>
        <kwd>Monte-Carlo ray tracing</kwd>
        <kwd>bi-directional ray tracing</kwd>
        <kwd>photon maps</kwd>
        <kwd>reduction of noise</kwd>
        <kwd>multiple importance sampling</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction</title>
      <p>
        A powerful method of solution of the rendering
equations is Monte Carlo ray tracing (MCRT). It is
widely used in calculation of the global illumination [
        <xref ref-type="bibr" rid="ref1 ref2">1,
2</xref>
        ]. Its main problem is noise, and it strongly depends on
the method of generation of random points. Therefore
there were and are a lot of papers devoted to the optimal
choice of the probability distribution of ray scattering
[
        <xref ref-type="bibr" rid="ref3 ref4 ref5 ref6 ref7 ref8 ref9">3–9</xref>
        ]. One of the powerful approaches here is the
socalled Multiple Importance Sampling (MIS). Its idea is
that
generate
several random
samples
(rays)
according to
distributions
different “strategies” i.e.
probability
and
then
sum
with
weights
their
contributions to image luminance.
      </p>
      <p>
        The mathematics behind that was produced in the
famous thesis by E Veach [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] where the theorem was
proved
about several simple
schemes
of
weight
calculation. It was proved there that the resulting noise
is close to its minimal value. This theorem applies to the
classic MCRT method when successive random points
are absolutely independent.
      </p>
      <p>Lighting simulation meanwhile frequently uses not
that simple MCRT but more advanced methods like
bidirectional</p>
      <p>
        Monte-Carlo
path
tracing
(BDPT),
bidirectional Monte-Carlo ray tracing with photon maps
(BDPM) [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], their combination termed
sometimes
BDCM [
        <xref ref-type="bibr" rid="ref8 ref9">8, 9</xref>
        ] etc. Here the successive trajectories are
not quite independent, for example, in the BDPM the
same forward path is “merged” with all the backward
paths. Therefore the resulting joined full trajectories
have common ”tail” and thus are not independent.
      </p>
      <p>
        As a result, the noise in these methods follows other
rules than in the simple or classic MCRT [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. Therefore
the weights that minimize this noise are likely different
from those which minimize the noise functional in the
classic MCRT. We shall prove it for the example of a
very simple model scene. In this scene the noise level is
dictated by geometric factors, but not by object optical
properties in form of bi-directional distribution function
(BDF), while the Veach formulae [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
        ] relate weights
to the BDFs along the ray path.
      </p>
      <p>In this paper we calculate the optimal weights
directly, i.e. find the minimum of the sample variance of
the pixel value. This is performed for a simple model
scene. We demonstrate that these weights depend on the
geometry of the scene and on the number of light and
camera rays per iteration,
while the known</p>
      <p>
        MIS
formulae from [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
        ] include only the BDFs and
distribution of light source emission.
2.
      </p>
    </sec>
    <sec id="sec-2">
      <title>BDPM and weights in it</title>
      <p>The basic idea of BDPM is that we trace several
camera and several light rays. Then for each pair of
light + camera paths, we try to merge them in a join
trajectory that connects light and camera. If they do join
we increment the accumulated luminance. Then the next
pair is processed. After all light rays had been checked
against all camera rays they all are discarded and new
sets of rays are generated etc. Generation of the sets of
rays and then cycling over all pairs constitute one
iteration of the process. The luminance calculated in
different iterations is statistically independent.</p>
      <p>So, an iteration which uses   camera rays (through
given</p>
      <p>pixel!!) and  
increases accumulated luminance of a pixel by</p>
      <p>light rays (for all pixels!)
=
1
 
1</p>
      <p>=1
   =1</p>
      <p>,
where   , is the contribution from the pair of  -th light
and  -th camera rays. Similarly to it can be written as
  + ,  ( )( ⃗
( )) ( )( ⃗
( )
−  ⃗
) (⋯ ;  ⃗</p>
      <p>( ))
where</p>
      <p>cycles over all camera path vertices and 
cycles over all light path vertices,  is the integration
kernel and  is BDF in luminance units at the point  ⃗</p>
      <p>( ).</p>
      <p>
        Like in [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
        ],   ,
      </p>
      <p>is the weight for junction at the 
th camera vertex when the join path of  vertices (i.e.
the light half of the join path has  − 
must be a function of that full path such that</p>
      <p>vertices). It
 =


(1)
(2)
Copyright © 2020 for this paper by its authors. Use permitted under Creative Commons License Attribution 4.0 International (CC BY
 −1
 =0
  ,
weights for joint paths of different total length  (this is
obvious because they are functions of  arguments).</p>
    </sec>
    <sec id="sec-3">
      <title>Direct calculation of optimal weights</title>
      <p>It follows from (1) and (2) that the increment of the
pixel luminance from one algorithm iteration is also
linear in weights: it is a sum of weights times some
random functions:

=
1
∞</p>
      <p>=1  =0  ,
  , ( ⃗ , )  , ( ⃗ , )
conditions
where</p>
      <p>enumerates light rays in one iteration, 
enumerates camera rays (through this pixel) in one
iteration and  ⃗ is the join path from them.   ,
( ⃗ , ) is
the contribution from the this pair ( ,  ) constrained to
1. The paths merge into join path
3. The join path has  vertices
2. They merge at the  -th camera vertex</p>
      <p>If these conditions are not satisfied   ,
resolves ambiguity how to define the join path if the
camera and light halves did not merge.</p>
      <p>The sets of join paths from different iterations are
independent. So for this linear form the average over
iterations (= the limiting luminance) is also linear in
weights whose “coefficients” are averages that can be
calculated in ray tracing.</p>
      <p>Therefore we can find those weights that minimize
the variance of the pixel luminance, i.e. the noise. These
are the optimal weights. Its direct calculation that does
not include
an
approximations
and
hypothesis is
regrettably very expensive numerically. So we shall
perform it for a simple model scene, but even this
example will give us some important conclusions.</p>
      <p>Simple model scene and calculations for it
vanish. This</p>
      <sec id="sec-3-1">
        <title>Scene layout</title>
        <p>To simplify our calculations we use a model scene
where all join paths have the same (and small) length. It
consists of 3 parallel planes with diffuse transparency;
planes 1 and 3 have the Lambert BDF. BDF of the
middle plane 2 is arbitrary and can be made very sharp
(when direction of a transmitted ray is close to that of
the incident ray). The planes are orthogonal to Oz and
where  ⃗1 = 0⃗ is fixed and the segment between lights
source and plane 3 is ignored because does not affect
the
path contribution.</p>
        <p>Therefore the full path is
completely described by its two variable vertices,  ⃗2
and  ⃗3.
and  1</p>
        <p>.
hit then.</p>
        <p>The camera and light rays can meet at planes 1, 2
and 3 whose contributions are taken with</p>
        <p>If camera and light ray meet at plane  , it is
ambiguous whether  ⃗</p>
        <p>is camera or light hit (they can
differ by integration kernel radius). We choose camera
Calculation of contribution</p>
        <p>Camera path is ( ⃗1
( ⃗3( )
,  ⃗2
( )</p>
        <p>( )
,  ⃗1 ) where  ⃗
at the  -th plane,  ⃗
to plane 1), and  ⃗1
( )
( )
,  ⃗2
( )</p>
        <p>,  ⃗3( )) and light path is
( ) is the hit point of camera ray
( ) is the hit point of light ray at the
= 0⃗ is fixed. As said above we do
 -th plane (light ray goes from plane 3 to plane 2 then
not consider the light ray before it hits the plane 3; just
we start the ray by choosing the point  ⃗3</p>
        <p>The contribution of these two sub-paths is
( )at random.
 =  0( ⃗2
) ( )( ⃗1
( )) ( )( ⃗1
( )) ( ⃗1
( )
( )</p>
        <p>( )
,  ⃗3
−  ⃗1
( )</p>
        <p>) 1(⋯ )
+ 1( ⃗2
+  2( ⃗2
( )
( )
( )
−  ⃗3</p>
        <p>) 3(⋯ )
where  1 =  2 =  −1 while
,  ⃗3
( )
) ( )( ⃗2
( )) ( )( ⃗2</p>
        <p>( )
,  ⃗3
( )) ( )( ⃗3
( )) ( )( ⃗3
( )
) ( ⃗2
) ( ⃗3
( )
( )
−  ⃗2
( )
) 2(⋯ )
 2 =</p>
        <p>1
2  2

−
 2
2 2</p>
        <p>1
cos
we use the simplest one:
where  is the angle between the incident and scattered
rays,  is the angle between the scattered ray and the
normal and  is the width. As to the integration kernel,
 ( ⃗) =
1</p>
        <p>1, | ⃗| ≤ 
  2 0, | ⃗| &gt; 
2
 =0
( )
ray
where  is integration radius. It is small.
and light path as  ⃗ ≡ ( ⃗3
( )
( )</p>
        <p>,  ⃗1( )) we can write
Denoting the camera path as  ⃗ ≡ ( ⃗1
( )
( )
,  ⃗3( ))
 ( ⃗,  ⃗) =</p>
        <p>( ⃗2( ⃗,  ⃗),  ⃗3( ⃗,  ⃗))  ( ⃗,  ⃗)
where
of which uses   light rays and   camera rays, is
Pixel luminance calculated during 
iterations, each
energies
can</p>
        <p>calculated
( )
be
−   ,</p>
        <p>(2)
  ≡
 ( , )
≡

1</p>
        <p>(2)
  ,
1</p>
        <p>=1  =1
and  1 into single array:
 ( ⃗ , ,  ⃗ , )
(3)</p>
        <p>The contribution from each iteration (3) is random
variable and contributions from
different iteration.</p>
        <p>Therefore the variance of calculated luminance is



1</p>
        <p>( ) =</p>
        <p>( )
( ) = ⟨ 2
⟩ − ⟨ ⟩
2</p>
        <p>The averages are over the ray ensembles. They can
be
approximately
estimated
from
the
sum
over
iterations (the usual practice called sample mean and
sample variance).</p>
      </sec>
      <sec id="sec-3-2">
        <title>Tabulated weights</title>
        <p>For numerical calculations let us subdivide the
whole admissible area in ( ⃗2,  ⃗3) space in cells. The
weight is constant   ,</p>
        <p>within cell. Since formally  ⃗2
and  ⃗3 can be infinite we take some finite area and
subdivide it in a usual way, unbounded space outside it
constituting “the last cell”. Let   ( ⃗2,  ⃗3) be 1 inside
the  -th cell and 0 outside it. Then the contribution
from the  -th iteration (3) becomes</p>
        <p>( ⃗ , ,  ⃗ , )  ( ⃗ , ,  ⃗ , )
Combining the tables that relate to the weights  0</p>
        <p>≡
  ≡
  ≡
 0
 1




 
 
(0)
(1)
(0)
(1)
we can write</p>
        <p>= ⟨  ||  ⟩ +  
Then, since
independent the average value and the mean square are
 =  | ⟩ + 
 2 = ⟨</p>
        <p>| | ⟩ + 2  | ⟩ +  2
where the overbar denotes the average, and</p>
        <p>≡ | ⟩⟨ |
⟨ | ≡  ⟨ |
1

−
thus</p>
        <p>The mathematical expectation of pixel luminance is
the same for all weights, thus the limiting average
= 0. But for a finite number of iterations, when
convergence is incomplete, the sample average can be
slightly depending on weights. Thus the sample average
≠ 0 and while calculating the sample variance over
a finite number of iterations we must account for this
dependence. This sample variance over 
iterations is

( ) =
⟨ | | ⟩ + 2  | ⟩ +  2
 | ⟩ + 
2
so the weights which minimize it satisfy

−</p>
        <p>| ⟩ = −| ⟩ + ⟨ ⟩ 
which is just a system of simultaneous linear equations.</p>
        <p>However numerical experiments shown that the
solution can be rather ragged. To improve the situation a
regularization term can be added to the minimization
equation which is a penalty for high gradients.</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>Results</title>
      <p>We performed the calculations for the case when
plane positions  2 = 1,  3 = 3,
BDF of plane 2 has width  = 3
∘
illumination density  is
 ( 3) =
1


300 
2
1
0</p>
      <p>= 20 is the radius of illuminated area and
 = 0.02 is the “aperture” (radius) of its bright central
part
•
•
 ⃗3
BTW
integration radius 
the number of rays  
= 0.003
= 100,</p>
      <p>The scene is axisymmetrical. Therefore all functions
infinity. So we chose a finite area for each, now 0 ≤
 2 ≤ 2, 0 ≤  3 ≤ 0.05, subdivided it into equal cells and
then added the last cell which completes to the whole
infinite domain, e.g. 1
2</p>
      <p>&lt;  2 &lt; ∞.</p>
      <p>Trial calculations were done for several numbers of
cells. It happened that although the calculated weights
differ, the noise level is nearly the same (as it is
common for optimization). Since the weights are not
needed per se, but only the noise reduction by them, we
can use as small cells as enough to saturate the noise
level.</p>
      <p>It happened that it was enough 1 cell in  (i.e.
weights actually do not depend on it!), 2 cells in  2 (0 ≤
 2 ≤ 21 and 21 &lt;  2 &lt; ∞) and 26 cells in  3 (the first 25 of
size 0.002 and the last 0.05 &lt;  3 &lt; ∞).</p>
      <p>The noise was calculated for the following cases.
The calculation results are shown in Table 1:
1. rays meet at plane 1 only
2. rays meet at plane 2 only
3. rays meet at plane 3 only
4. rays meet at plane 3 only
5. optimal weights are used</p>
      <p>Table 1. The calculation results
case    ×105 RMS,%
1 1 26.484 208%
2 0 26.352 254%
3 0 25.997 146%
   
0 0
1 0
0 1
1,  3 ≤  0,  3 ≤ 
0,  3 &gt;  1,  3 &gt; 
optimal</p>
      <p>Optimal weights were calculated from statistic
accumulated in 10000 iterations (Fig. 2). Optimization
was constrained to  0 = 0.</p>
      <p>Fig. 2: The optimal weight  1 as a function of  2;</p>
      <p>2 = 1 −  1 ;  0 was constrained to 0</p>
    </sec>
    <sec id="sec-5">
      <title>Conclusions</title>
      <p>We see that even in case of a direct optimization
(which gives the best result without false minima,
approximations etc.) the gain is moderate; it is about
3fold as compared to the best “fixed BDD” strategy.
This is not bad because 3fold in noise is equivalent to a
9fold increase of speed.</p>
      <p>At qualitative level we see that the optimal weights
are not local i.e. we cannot calculate the weight (which
is as we remember a function of the vertices of join
path) from that path only. Indeed, in the above
calculation illumination of the rightmost plane was
3333 times lower for  3 &gt;  . Let us compare it with the
case of uniform illumination. In this case the optimal
weight is very close to  2 = 1 (for all paths), so for a
join path with | 3| ≤  the optimal weight is different
for the uniform and not uniform illumination. In other
words, the weight for this path depends on illumination
outside it.</p>
      <p>Surely the optimal weight is still a function of the
join path but this function depends on the global scene
characteristics.</p>
      <p>
        Meanwhile in the “balance heuristic” or “power
heuristic” [
        <xref ref-type="bibr" rid="ref3 ref4">3, 4</xref>
        ] this function is known in advance. Very
roughly, it calculates the weight from the ratio of BDF
at junction point to the sum of BDFs at all the vertices
of the join path. We therefore conclude that the
balance/power heuristic, derived for the usual MCRT, is
not truly optimal for BDPM because there the
“samples” (join paths) are correlated because use the
same light and/or camera path several times.
      </p>
    </sec>
    <sec id="sec-6">
      <title>Acknowledgments</title>
      <p>The study was carried out within the framework of
the RFBR grants 18-01-00569, 18-31-20032 and
20-0100547.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Matt</given-names>
            <surname>Pharr</surname>
          </string-name>
          and
          <string-name>
            <given-names>Greg</given-names>
            <surname>Humphreys</surname>
          </string-name>
          .
          <year>2010</year>
          .
          <article-title>Physically Based Rendering, Second Edition: From Theory to Implementation (2nd ed</article-title>
          .). Morgan Kaufmann Publishers Inc., San Francisco, CA, USA.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>H. W.</given-names>
            <surname>Jensen</surname>
          </string-name>
          ,
          <article-title>Global illumination using photon maps</article-title>
          ,
          <source>in Proceedings of the Eurographics Workshop on Rendering Techniques '96</source>
          , (London, UK, UK), pp.
          <fpage>21</fpage>
          -
          <lpage>30</lpage>
          , SpringerVerlag,
          <year>1996</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>Eric</given-names>
            <surname>Veach</surname>
          </string-name>
          .
          <article-title>A dissertation: Robust Monte-Carlo methods for light transport simulation</article-title>
          ,
          <year>1997</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>Jiri</given-names>
            <surname>Vorba</surname>
          </string-name>
          .
          <article-title>Bidirectional photon mapping</article-title>
          .
          <source>In Proceedings of CESCG 2011: The 15th Central European Seminar on Computer Graphics</source>
          , Prague,
          <year>2011</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>I.</given-names>
            <surname>Georgiev</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Křivánek</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Davidovič</surname>
          </string-name>
          , and
          <string-name>
            <surname>Ph</surname>
          </string-name>
          .
          <source>Slusallek</source>
          .
          <year>2012</year>
          .
          <article-title>Light transport simulation with vertex connection and merging</article-title>
          .
          <source>ACM Trans. Graph</source>
          .
          <volume>31</volume>
          ,
          <issue>6</issue>
          ,
          <string-name>
            <surname>Article 192</surname>
          </string-name>
          (
          <year>November 2012</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>S.</given-names>
            <surname>Ershov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Zhdanov</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Voloboy</surname>
          </string-name>
          .
          <article-title>Estimation of noise in calculation of scattering medium luminance by MCRT</article-title>
          .
          <source>Mathematica Montisnigri</source>
          , XLV:
          <fpage>60</fpage>
          -
          <lpage>73</lpage>
          ,
          <year>2019</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>S.</given-names>
            <surname>Ershov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Zhdanov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Voloboy</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Sorokin</surname>
          </string-name>
          .
          <article-title>Treating diffuse elements as quasi-specular to reduce noise in bidirectional ray tracing</article-title>
          // Keldysh Institute Preprints.
          <year>2018</year>
          . No.
          <volume>122</volume>
          . 30 p. doi:
          <volume>10</volume>
          .20948/prepr-2018-122-e
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>S.</given-names>
            <surname>Popov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Ramamoorthi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Durand</surname>
          </string-name>
          , and
          <string-name>
            <given-names>G.</given-names>
            <surname>Drettakis</surname>
          </string-name>
          ,
          <article-title>Probabilistic Connections for Bidirectional Path Tracing</article-title>
          , Computer Graphics Forum,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>N.</given-names>
            <surname>Dodik</surname>
          </string-name>
          ,
          <article-title>Implementing probabilistic connections for bidirectional path tracing in the Mitsuba Renderer</article-title>
          , Sept.
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>