Fermat
rpt.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>
36 #include <renderer_interface.h>
37 
38 struct RenderingContext;
39 
42 
49 
54 struct RPTVPLView
55 {
56  float4* pos; // packed VPL geometry
57  uint4* gbuffer; // packed VPL material descriptors
58  uint4* ebuffer; // packed VPL edf descriptors
59  float4* weight; // sampled BSDF value and probability
60  float4* weight2; // sampled BSDF value and probability
61  uint32* in_dir; // packed incoming (reversed, i.e. the outgoing one from the PT's perspective) direction and radiance
62  uint32* in_dir2; // packed incoming (reversed, i.e. the outgoing one from the PT's perspective) direction and radiance
63  float4* in_alpha; // unpacked incoming (reversed, i.e. the outgoing one from the PT's perspective) radiance
64  float4* in_alpha2; // unpacked incoming (reversed, i.e. the outgoing one from the PT's perspective) radiance
65 };
66 
72 {
73  DomainBuffer<CUDA_BUFFER, float4> m_pos; // packed VPL geometry
74  DomainBuffer<CUDA_BUFFER, uint4> m_gbuffer; // packed VPL material descriptors
75  DomainBuffer<CUDA_BUFFER, uint4> m_ebuffer; // packed VPL material descriptors
76  DomainBuffer<CUDA_BUFFER, float4> m_weight; // sampled BSDF value and probability
77  DomainBuffer<CUDA_BUFFER, float4> m_weight2; // sampled BSDF value and probability
78  DomainBuffer<CUDA_BUFFER, uint32> m_in_dir; // packed incoming (reversed, i.e. the outgoing one from the PT's perspective) direction
79  DomainBuffer<CUDA_BUFFER, uint32> m_in_dir2; // packed incoming (reversed, i.e. the outgoing one from the PT's perspective) direction
80  DomainBuffer<CUDA_BUFFER, float4> m_in_alpha; // unpacked incoming (reversed, i.e. the outgoing one from the PT's perspective) radiance
81  DomainBuffer<CUDA_BUFFER, float4> m_in_alpha2;// unpacked incoming (reversed, i.e. the outgoing one from the PT's perspective) radiance
82 
83  void alloc(const uint32 pixels)
84  {
85  m_pos.alloc(pixels);
86  m_gbuffer.alloc(pixels);
87  m_ebuffer.alloc(pixels);
88  m_weight.alloc(pixels);
89  m_weight2.alloc(pixels);
90  m_in_dir.alloc(pixels);
91  m_in_dir2.alloc(pixels);
92  m_in_alpha.alloc(pixels);
93  m_in_alpha2.alloc(pixels);
94  }
95 
96  RPTVPLView view()
97  {
98  RPTVPLView r;
99  r.pos = m_pos.ptr();
100  r.gbuffer = m_gbuffer.ptr();
101  r.ebuffer = m_ebuffer.ptr();
102  r.weight = m_weight.ptr();
103  r.weight2 = m_weight2.ptr();
104  r.in_dir = m_in_dir.ptr();
105  r.in_dir2 = m_in_dir2.ptr();
106  r.in_alpha = m_in_alpha.ptr();
107  r.in_alpha2 = m_in_alpha2.ptr();
108  return r;
109  }
110 };
111 
115 {
116  uint32 filter_width;
117  uint32 max_path_length;
118  bool direct_lighting;
119  bool direct_lighting_nee;
120  bool direct_lighting_bsdf;
121  bool indirect_lighting_nee;
122  bool indirect_lighting_bsdf;
123  bool visible_lights;
124  bool diffuse_scattering;
125  bool glossy_scattering;
126  bool indirect_glossy;
127  bool rr;
128  bool tiled_reuse;
129 
130  RPTOptions() :
131  max_path_length(6),
132  direct_lighting_nee(true),
133  direct_lighting_bsdf(true),
134  indirect_lighting_nee(true),
135  indirect_lighting_bsdf(true),
136  visible_lights(true),
137  direct_lighting(true),
138  diffuse_scattering(true),
139  glossy_scattering(true),
140  indirect_glossy(false),
141  rr(true),
142  filter_width(30),
143  tiled_reuse(false)
144  {}
145 
146  void parse(const int argc, char** argv)
147  {
148  for (int i = 0; i < argc; ++i)
149  {
150  if (strcmp(argv[i], "-pl") == 0 ||
151  strcmp(argv[i], "-path-length") == 0 ||
152  strcmp(argv[i], "-max-path-length") == 0)
153  max_path_length = atoi(argv[++i]);
154  else if (strcmp(argv[i], "-bounces") == 0)
155  max_path_length = atoi(argv[++i]) + 1;
156  else if (strcmp(argv[i], "-nee") == 0)
157  direct_lighting_nee = indirect_lighting_nee = atoi(argv[++i]) > 0;
158  else if (strcmp(argv[i], "-bsdf") == 0)
159  direct_lighting_bsdf = indirect_lighting_bsdf = atoi(argv[++i]) > 0;
160  else if (strcmp(argv[i], "-direct-nee") == 0)
161  direct_lighting_nee = atoi(argv[++i]) > 0;
162  else if (strcmp(argv[i], "-direct-bsdf") == 0)
163  direct_lighting_bsdf = atoi(argv[++i]) > 0;
164  else if (strcmp(argv[i], "-indirect-nee") == 0)
165  indirect_lighting_nee = atoi(argv[++i]) > 0;
166  else if (strcmp(argv[i], "-indirect-bsdf") == 0)
167  indirect_lighting_bsdf = atoi(argv[++i]) > 0;
168  else if (strcmp(argv[i], "-visible-lights") == 0)
169  visible_lights = atoi(argv[++i]) > 0;
170  else if (strcmp(argv[i], "-direct-lighting") == 0)
171  direct_lighting = atoi(argv[++i]) > 0;
172  else if (strcmp(argv[i], "-indirect-glossy") == 0)
173  indirect_glossy = atoi(argv[++i]) > 0;
174  else if (strcmp(argv[i], "-diffuse") == 0)
175  diffuse_scattering = atoi(argv[++i]) > 0;
176  else if (strcmp(argv[i], "-glossy") == 0)
177  glossy_scattering = atoi(argv[++i]) > 0;
178  else if (strcmp(argv[i], "-rr") == 0)
179  rr = atoi(argv[++i]) > 0;
180  else if (strcmp(argv[i], "-filter-width") == 0)
181  filter_width = (uint32)atof(argv[++i]);
182  else if (strcmp(argv[i], "-tiled") == 0 ||
183  strcmp(argv[i], "-tiled-reuse") == 0)
184  tiled_reuse = atoi(argv[++i]) > 0;
185  }
186  }
187 };
188 
196 {
197  RPT();
198 
199  void init(int argc, char** argv, RenderingContext& renderer);
200 
201  void render(const uint32 instance, RenderingContext& renderer);
202 
203  void setup_samples(const uint32 instance);
204 
205  void destroy() { delete this; }
206 
207  static RendererInterface* factory() { return new RPT(); }
208 
209  RPTOptions m_options;
210 
218 
219  RPTVPLStorage m_vpls;
220 
221  TiledSequence m_sequence;
222 
223  cugar::LFSRGeneratorMatrix m_generator;
224  cugar::LFSRRandomStream m_random;
225 
226  float m_time;
227 };
228 
Definition: rpt.h:71
void destroy()
Definition: rpt.h:205
Definition: lfsr.h:66
Definition: tiled_sequence.h:131
Definition: renderer_interface.h:45
Definition: lfsr.h:109
Definition: rpt.h:54
Definition: renderer.h:52
Definition: rpt.h:114
Defines several random samplers.
Definition: rpt.h:195