Fermat
mlt.h
1 /*
2  * Fermat
3  *
4  * Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #pragma once
30 
31 #include <types.h>
32 #include <buffers.h>
33 #include <ray.h>
34 #include <lights.h>
35 #include <vertex_storage.h>
36 #include <bpt_options.h>
37 #include <bpt_queues.h>
38 #include <tiled_sequence.h>
39 #include <cugar/sampling/lfsr.h>
40 #include <cugar/color/rgbe.h>
41 #include <cugar/basic/memory_arena.h>
42 #include <renderer_interface.h>
43 
44 struct RenderingContext;
46 
47 struct MLTContext;
48 
52 {
53  uint32 n_chains;
54  uint32 spp;
55  uint32 reseeding_freq;
56  uint32 mis : 1;
57  float st_perturbations;
58  float screen_perturbations;
59  float exp_perturbations;
60  float H_perturbations;
61  float perturbation_radius;
62  uint32 flags;
63 
64  MLTOptions() :
66  n_chains(256 * 1024),
67  spp(1),
68  reseeding_freq(16),
69  st_perturbations(1.0f),
70  screen_perturbations(1.0f),
71  exp_perturbations(0.45f),
72  H_perturbations(0.45f),
73  perturbation_radius(0.1f),
74  mis(false),
75  flags(0)
76  {
77  // temporarily kill light tracing
78  BPTOptionsBase::light_tracing = 0.0f;
79  }
80 
81  void parse(const int argc, char** argv)
82  {
83  BPTOptionsBase::parse(argc, argv);
84 
85  for (int i = 0; i < argc; ++i)
86  {
87  if (strcmp(argv[i], "-chains") == 0)
88  n_chains = atoi(argv[++i]) * 1024;
89  else if (strcmp(argv[i], "-spp") == 0)
90  spp = atoi(argv[++i]);
91  else if (strcmp(argv[i], "-st-mutations") == 0 ||
92  strcmp(argv[i], "-st-perturbations") == 0)
93  st_perturbations = (float)atof(argv[++i]);
94  else if (strcmp(argv[i], "-screen-perturbations") == 0 ||
95  strcmp(argv[i], "-lens-perturbations") == 0 ||
96  strcmp(argv[i], "-lp") == 0)
97  screen_perturbations = (float)atof(argv[++i]);
98  else if (strcmp(argv[i], "-H-perturbations") == 0 ||
99  strcmp(argv[i], "-h-perturbations") == 0 ||
100  strcmp(argv[i], "-hp") == 0 ||
101  strcmp(argv[i], "-H") == 0 ||
102  strcmp(argv[i], "-h") == 0)
103  H_perturbations = (float)atof(argv[++i]);
104  else if (strcmp(argv[i], "-exp-perturbations") == 0 ||
105  strcmp(argv[i], "-e-perturbations") == 0 ||
106  strcmp(argv[i], "-exp") == 0 ||
107  strcmp(argv[i], "-ep") == 0)
108  exp_perturbations = (float)atof(argv[++i]);
109  else if (strcmp(argv[i], "-rf") == 0 ||
110  strcmp(argv[i], "-reseed") == 0 ||
111  strcmp(argv[i], "-reseed-freq") == 0)
112  reseeding_freq = atoi(argv[++i]);
113  else if (strcmp(argv[i], "-mis") == 0)
114  mis = atoi(argv[++i]) > 0;
115  else if (strcmp(argv[i], "-pr") == 0 ||
116  strcmp(argv[i], "-perturbation-radius") == 0)
117  perturbation_radius = (float)atof(argv[++i]);
118  else if (strcmp(argv[i], "-flags") == 0)
119  flags = strtol(argv[++i], NULL, 16u);
120  }
121 
122  const float prob_perturbations = exp_perturbations + H_perturbations;
123  if (prob_perturbations > 1.0f)
124  {
125  exp_perturbations /= prob_perturbations;
126  H_perturbations /= prob_perturbations;
127  }
128  }
129 };
130 
134 {
135  MLT();
136 
137  void init(int argc, char** argv, RenderingContext& renderer);
138 
139  void render(const uint32 instance, RenderingContext& renderer);
140 
141  void sample_seeds(MLTContext& context);
142 
143  void recover_seed_paths(MLTContext& context, RenderingContextView& renderer_view);
144 
145  void destroy() { delete this; }
146 
147  static RendererInterface* factory();
148 
149  void alloc(MLTContext& context, cugar::memory_arena& arena, const uint32 n_pixels, const uint32 n_chains);
150 
151  MLTOptions m_options;
152  TiledSequence m_sequence;
153  BPTQueuesStorage m_queues;
154  VertexStorage m_light_vertices;
155 
156  float m_image_brightness;
157  uint32 m_n_lights;
158  uint32 m_n_init_paths;
159  uint32 m_n_connections;
160 
161  DomainBuffer<CUDA_BUFFER, uint8> m_memory_pool;
162  DomainBuffer<CUDA_BUFFER, float> m_connections_cdf;
163  DomainBuffer<HOST_BUFFER, float> m_path_pdf_backup;
164 
165  cugar::LFSRGeneratorMatrix m_generator;
166  cugar::LFSRRandomStream m_random;
167 };
void destroy()
Definition: mlt.h:145
Definition: lfsr.h:66
Definition: tiled_sequence.h:131
Definition: vertex_storage.h:73
Definition: renderer_interface.h:45
Definition: lfsr.h:109
Definition: renderer.h:52
Definition: mlt_core.h:98
Definition: bpt_queues.h:51
Definition: memory_arena.h:44
Definition: renderer_view.h:80
Definition: mlt.h:51
Definition: mlt.h:133
Defines several random samplers.
Definition: bpt_options.h:42