Fermat
cmlt.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 #pragma once
29 
30 #include <types.h>
31 #include <buffers.h>
32 #include <ray.h>
33 #include <lights.h>
34 #include <vertex_storage.h>
35 #include <bpt_options.h>
36 #include <bpt_queues.h>
37 #include <tiled_sequence.h>
38 #include <cugar/sampling/lfsr.h>
39 #include <renderer_interface.h>
40 
41 struct RenderingContext;
43 
44 struct CMLTContext;
45 
48 
53 
57 {
58  uint32 n_chains;
59  uint32 spp;
60  uint32 swap_frequency;
61  uint32 mmlt_frequency;
62  uint32 startup_skips;
63  uint32 reseeding;
64  bool single_connection;
65  bool rr;
66  bool light_perturbations;
67  bool eye_perturbations;
68  float perturbation_radius;
69 
70  CMLTOptions() :
72  n_chains(256 * 1024),
73  spp(1),
74  swap_frequency(32),
75  mmlt_frequency(0),
76  startup_skips(0),
77  single_connection(false),
78  rr(false),
79  light_perturbations(true),
80  eye_perturbations(true),
81  reseeding(8),
82  perturbation_radius(0.01f)
83  {
84  BPTOptionsBase::light_tracing = 0.0f;
85  }
86 
87  void parse(const int argc, char** argv)
88  {
89  BPTOptionsBase::parse(argc, argv);
90 
91  for (int i = 0; i < argc; ++i)
92  {
93  if (strcmp(argv[i], "-chains") == 0)
94  n_chains = atoi(argv[++i]) * 1024;
95  else if (strcmp(argv[i], "-spp") == 0)
96  spp = atoi(argv[++i]);
97  else if (strcmp(argv[i], "-c-swaps") == 0 || strcmp(argv[i], "-chart-swaps") == 0)
98  swap_frequency = atoi(argv[++i]);
99  else if (strcmp(argv[i], "-m-swaps") == 0 || strcmp(argv[i], "-mmlt-swaps") == 0)
100  mmlt_frequency = atoi(argv[++i]);
101  else if (strcmp(argv[i], "-skips") == 0 ||
102  strcmp(argv[i], "-startup-skips") == 0)
103  startup_skips = atoi(argv[++i]);
104  else if (strcmp(argv[i], "-sc") == 0 ||
105  strcmp(argv[i], "-single-conn") == 0 ||
106  strcmp(argv[i], "-single-connection") == 0)
107  single_connection = atoi(argv[++i]) > 0;
108  else if (strcmp(argv[i], "-rr") == 0 || strcmp(argv[i], "-RR") == 0)
109  rr = atoi(argv[++i]) > 0;
110  else if (strcmp(argv[i], "-light-perturbations") == 0)
111  light_perturbations = atoi(argv[++i]) > 0;
112  else if (strcmp(argv[i], "-eye-perturbations") == 0)
113  eye_perturbations = atoi(argv[++i]) > 0;
114  else if (strcmp(argv[i], "-perturbations") == 0)
115  light_perturbations = eye_perturbations = atoi(argv[++i]) > 0;
116  else if (strcmp(argv[i], "-rf") == 0 ||
117  strcmp(argv[i], "-reseed-freq") == 0 ||
118  strcmp(argv[i], "-reseeding") == 0)
119  reseeding = atoi(argv[++i]);
120  else if (strcmp(argv[i], "-perturbation-radius") == 0 ||
121  strcmp(argv[i], "-p-radius") == 0 ||
122  strcmp(argv[i], "-pr") == 0)
123  perturbation_radius = (float)atof(argv[++i]);
124  }
125  }
126 };
127 
131 {
132  CMLT();
133 
134  void init(int argc, char** argv, RenderingContext& renderer);
135 
136  void render(const uint32 instance, RenderingContext& renderer);
137 
138  void sample_seeds(const uint32 n_chains);
139 
140  void build_st_norms_cdf();
141 
142  void recover_primary_coordinates(CMLTContext& context, RenderingContextView& renderer_view);
143 
144  void destroy() { delete this; }
145 
146  static RendererInterface* factory() { return new CMLT(); }
147 
148  CMLTOptions m_options;
149 
150  TiledSequence m_sequence;
151 
152  BPTQueuesStorage m_queues;
153 
154  VertexStorage m_light_vertices;
155 
161  DomainBuffer<CUDA_BUFFER, float4> m_connections_value;
162  DomainBuffer<CUDA_BUFFER, uint4> m_connections_index;
163  DomainBuffer<CUDA_BUFFER, float> m_connections_cdf;
164  DomainBuffer<CUDA_BUFFER, uint32> m_connections_counter;
166  DomainBuffer<CUDA_BUFFER, uint32> m_st_counters;
168  DomainBuffer<CUDA_BUFFER, float> m_st_norms_cdf;
171  float m_image_brightness;
172  uint32 m_n_init_light_paths;
173  uint32 m_n_init_paths;
174  uint32 m_n_chains;
175  uint32 m_n_connections;
176  float m_time;
177 
178  cugar::LFSRGeneratorMatrix m_generator;
179  cugar::LFSRRandomStream m_random;
180 };
181 
Definition: cmlt.h:130
void destroy()
Definition: cmlt.h:144
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: bpt_queues.h:51
Definition: cmlt.h:56
Definition: renderer_view.h:80
Defines several random samplers.
Definition: bpt_options.h:42