Fermat
pathtracer.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 <tiled_sequence.h>
35 #include <cugar/sampling/lfsr.h>
37 #include <cugar/linalg/bbox.h>
38 #include <renderer_interface.h>
39 
40 struct RenderingContext;
41 struct MeshVTLStorage;
42 struct ClusteredRLStorage;
44 
48 
153 
156 
160 
161 enum NEEAlgorithm {
162  NEE_ALGORITHM_MESH = 0,
163  NEE_ALGORITHM_VPL = 1,
164  NEE_ALGORITHM_RL = 2
165 };
166 
169 struct PTOptions
170 {
171  uint32 max_path_length;
172  uint32 direct_lighting : 1;
173  uint32 direct_lighting_nee : 1;
174  uint32 direct_lighting_bsdf : 1;
175  uint32 indirect_lighting_nee : 1;
176  uint32 indirect_lighting_bsdf : 1;
177  uint32 visible_lights : 1;
178  uint32 diffuse_scattering : 1;
179  uint32 glossy_scattering : 1;
180  uint32 indirect_glossy : 1;
181  uint32 rr : 1;
182  uint32 nee_type : 2;
183  uint32 backend;
184 
185  #if !defined(OPTIX_COMPILATION)
186  PTOptions() :
187  max_path_length(6),
188  direct_lighting_nee(true),
189  direct_lighting_bsdf(true),
190  indirect_lighting_nee(true),
191  indirect_lighting_bsdf(true),
192  visible_lights(true),
193  direct_lighting(true),
194  diffuse_scattering(true),
195  glossy_scattering(true),
196  indirect_glossy(false),
197  rr(true),
198  nee_type(NEE_ALGORITHM_VPL),
199  backend(0) {}
200  #endif
201 
202  void parse(const int argc, char** argv)
203  {
204  for (int i = 0; i < argc; ++i)
205  {
206  if (strcmp(argv[i], "-pl") == 0 ||
207  strcmp(argv[i], "-path-length") == 0 ||
208  strcmp(argv[i], "-max-path-length") == 0)
209  max_path_length = atoi(argv[++i]);
210  else if (strcmp(argv[i], "-bounces") == 0)
211  max_path_length = atoi(argv[++i]) + 1;
212  else if (strcmp(argv[i], "-nee") == 0)
213  direct_lighting_nee = indirect_lighting_nee = atoi(argv[++i]) > 0;
214  else if (strcmp(argv[i], "-bsdf") == 0)
215  direct_lighting_bsdf = indirect_lighting_bsdf = atoi(argv[++i]) > 0;
216  else if (strcmp(argv[i], "-direct-nee") == 0)
217  direct_lighting_nee = atoi(argv[++i]) > 0;
218  else if (strcmp(argv[i], "-direct-bsdf") == 0)
219  direct_lighting_bsdf = atoi(argv[++i]) > 0;
220  else if (strcmp(argv[i], "-indirect-nee") == 0)
221  indirect_lighting_nee = atoi(argv[++i]) > 0;
222  else if (strcmp(argv[i], "-indirect-bsdf") == 0)
223  indirect_lighting_bsdf = atoi(argv[++i]) > 0;
224  else if (strcmp(argv[i], "-visible-lights") == 0)
225  visible_lights = atoi(argv[++i]) > 0;
226  else if (strcmp(argv[i], "-direct-lighting") == 0)
227  direct_lighting = atoi(argv[++i]) > 0;
228  else if (strcmp(argv[i], "-indirect-glossy") == 0)
229  indirect_glossy = atoi(argv[++i]) > 0;
230  else if (strcmp(argv[i], "-diffuse") == 0)
231  diffuse_scattering = atoi(argv[++i]) > 0;
232  else if (strcmp(argv[i], "-glossy") == 0)
233  glossy_scattering = atoi(argv[++i]) > 0;
234  else if (strcmp(argv[i], "-rr") == 0)
235  rr = atoi(argv[++i]) > 0;
236  else if (strcmp(argv[i], "-nee-algorithm") == 0 ||
237  strcmp(argv[i], "-nee-alg") == 0)
238  {
239  if (strcmp(argv[i+1], "mesh") == 0)
240  nee_type = NEE_ALGORITHM_MESH;
241  else if (strcmp(argv[i+1], "vpl") == 0)
242  nee_type = NEE_ALGORITHM_VPL;
243  else if (strcmp(argv[i+1], "rl") == 0)
244  nee_type = NEE_ALGORITHM_RL;
245 
246  ++i;
247  }
248  }
249  }
250 };
251 
254 struct PTStats
255 {
256  cugar::Variance_estimator<float> primary_rt_time;
258  cugar::Variance_estimator<float> shadow_rt_time;
259  cugar::Variance_estimator<float> path_shade_time;
260  cugar::Variance_estimator<float> shadow_shade_time;
261 };
262 
266 {
267  //typedef ClusteredRLStorage VTLRLStorage;
269 
270  PathTracer();
271 
272  void init(int argc, char** argv, RenderingContext& renderer);
273 
274  void render(const uint32 instance, RenderingContext& renderer);
275 
276  void setup_samples(const uint32 instance);
277 
278  void keyboard(unsigned char character, int x, int y, bool& invalidate);
279 
280  void destroy() { delete this; }
281 
282  void dump_speed_stats(FILE* stats);
283 
284  void update_vtls_rl(const uint32 instance);
285 
286  static RendererInterface* factory() { return new PathTracer(); }
287 
288  DomainBuffer<CUDA_BUFFER, uint8> m_memory_pool;
289 
290  PTOptions m_options;
291  TiledSequence m_sequence;
292 
293  cugar::LFSRGeneratorMatrix m_generator;
294  cugar::LFSRRandomStream m_random;
295 
296  MeshVTLStorage* m_mesh_vtls;
297  VTLRLStorage* m_vtls_rl;
298  cugar::Bbox3f m_bbox;
299 
300  float m_time;
301 
302  uint32 m_pathtracer_raygen;
303 
304  PTStats m_stats;
305 };
306 
Definition: mesh_lights.h:59
Definition: clustered_rl.h:161
Definition: pathtracer.h:169
Defines an axis-aligned bounding box class.
Definition: pathtracer.h:265
Definition: lfsr.h:66
Definition: tiled_sequence.h:131
Definition: renderer_interface.h:45
Definition: lfsr.h:109
Definition: clustered_rl.h:87
Definition: renderer.h:52
void destroy()
Definition: pathtracer.h:280
Defines utilities for variance estimation.
Definition: pathtracer.h:254
Defines several random samplers.