New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MLTIntegrator #43

Closed
wahn opened this Issue Mar 28, 2018 · 6 comments

Comments

Projects
None yet
1 participant
@wahn
Copy link
Owner

wahn commented Mar 28, 2018

Lets implement the Rust counterpart to the C++ class MLTIntegrator:

class MLTIntegrator : public Integrator {
  public:
    // MLTIntegrator Public Methods
    MLTIntegrator(std::shared_ptr<const Camera> camera, int maxDepth,
                  int nBootstrap, int nChains, int mutationsPerPixel,
                  Float sigma, Float largeStepProbability)
        : camera(camera),
          maxDepth(maxDepth),
          nBootstrap(nBootstrap),
          nChains(nChains),
          mutationsPerPixel(mutationsPerPixel),
          sigma(sigma),
          largeStepProbability(largeStepProbability) {}
    void Render(const Scene &scene);
    Spectrum L(const Scene &scene, MemoryArena &arena,
               const std::unique_ptr<Distribution1D> &lightDistr,
               const std::unordered_map<const Light *, size_t> &lightToIndex,
               MLTSampler &sampler, int k, Point2f *pRaster);

  private:
    // MLTIntegrator Private Data
    std::shared_ptr<const Camera> camera;
    const int maxDepth;
    const int nBootstrap;
    const int nChains;
    const int mutationsPerPixel;
    const Float sigma, largeStepProbability;
};

@wahn wahn added the enhancement label Mar 28, 2018

@wahn wahn self-assigned this Mar 28, 2018

@wahn

This comment has been minimized.

Copy link
Owner Author

wahn commented Mar 28, 2018

I think this is the scene I will use to test the Rust version of the MLTIntegrator:

caustic

The image above was still rendered by the C++ version.

MakeNamedMedium "vol" 
        "string type" [ "homogeneous" ] 
        "rgb sigma_a" [ 0.0199999996 0.0199999996 0.0199999996 ] 
        "rgb sigma_s" [ 0.3499999940 0.3499999940 0.3499999940 ] 
Film "image" 
        "integer xresolution" [ 800 ] 
        "integer yresolution" [ 800 ] 
        "string filename" [ "caustic.exr" ] 
Integrator "mlt" 
        "integer mutationsperpixel" [ 16384 ] 
MediumInterface "" "vol"
LookAt -0.75 0.800000012 -1.25
        -1 0.800000012 0
        0 1 0
Camera "perspective" 
        "float fov" [ 95 ] 

#############################################
WorldBegin

MediumInterface "" "vol"

AttributeBegin
    MediumInterface "vol" ""
    Material "" 
    Shape "sphere" 
            "float radius" [ 2 ] 
AttributeEnd

AttributeBegin
    Rotate -60 0 0 1
    LightSource "infinite" 
            "string mapname" [ "textures/skylight-day.exr" ] 
            "rgb scale" [ 1.5000000000 1.5000000000 1.3999999762 ] 
AttributeEnd
LightSource "spot" 
        "float coneangle" [ 6.3499999046 ] 
        "point from" [ -3 6 -2 ] 
        "point to" [ -1 1 0 ] 
        "rgb I" [ 2500 2500 2500 ] 

AttributeBegin
    Translate -1 1 0
    Material "glass" 
    Shape "sphere" 
            "float radius" [ 0.5000000000 ] 
AttributeEnd
Material "matte" 
        "rgb Kd" [ 0.2000000030 0.2000000030 0.2000000030 ] 
Translate 0 -0.100000001 0
Shape "trianglemesh" 
        "integer indices" [ 0 1 2 2 3 0 ] 
        "point P" [ -15 0 -15 15 0 -15 15 0 15 -15 0 15 ] 
WorldEnd
@wahn

This comment has been minimized.

Copy link
Owner Author

wahn commented Mar 28, 2018

Here is a comparison between bi-directional path tracing on the left and Metropolis Light Transport (MLT) on the right:

bdpt_vs_mlt

$ diff f16-22a.pbrt f16-22b.pbrt
8,11c8,10
<         "string filename" [ "f16-22a.exr" ] 
< Sampler "02sequence" 
<         "integer pixelsamples" [ 64 ] 
< Integrator "bdpt" 
---
>         "string filename" [ "f16-22ab.exr" ] 
> Integrator "mlt" 
>         "integer mutationsperpixel" [ 128 ] 

You can see that MLT gives a lower variance result, thanks to being able to efficiently explore the local path space once a high-contribution path has been found.

wahn added a commit that referenced this issue Mar 29, 2018

@wahn

This comment has been minimized.

Copy link
Owner Author

wahn commented May 25, 2018

Commit 87b0b5e can generate bootstrap paths multi-threaded.

@wahn

This comment has been minimized.

Copy link
Owner Author

wahn commented Jun 8, 2018

Commit aa11e0f does finally render exactly like the C++ version (using mlt):

> imf_diff -d -f pbrt_cpp.png pbrt_rust.png
pbrt_cpp.png pbrt_rust.png: no differences.
== "pbrt_cpp.png" and "pbrt_rust.png" are identical

See image above on the right.

What's left to do is to use multi-threading for the render_mlt(...) render loop (generating bootstrap samples is already multi-threaded). I will create another ticket for that and close this one.

@wahn wahn closed this Jun 8, 2018

@wahn

This comment has been minimized.

Copy link
Owner Author

wahn commented Jun 8, 2018

Actually it was really easy to multi-thread that part of the code using the rayon crate. So, no additional ticket/issue. Here is the commit: dd7503e ...

@wahn

This comment has been minimized.

Copy link
Owner Author

wahn commented Jun 9, 2018

Here the original scene in higher resolution (800x800) rendered via MLT and Rust, but using a HDR instead of EXR for the infinite light source:

caustics_rust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment