Fermat
pathtracer_vertex_processor.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 <pathtracer_core.h>
31 
34 
37 
47 {
56  template <typename PTContext>
57  FERMAT_DEVICE
59  const PTContext& context,
60  const RenderingContextView& renderer,
61  const PixelInfo pixel_info,
62  const EyeVertex& ev,
63  const float cone_radius,
64  const cugar::Bbox3f scene_bbox,
65  const uint32 prev_vertex_info,
66  const cugar::Vector3f w,
67  const float p_prev)
68  {
69  return uint32(0xFFFFFFFF);
70  }
71 
87  template <typename PTContext>
88  FERMAT_DEVICE
90  const PTContext& context, // the current context
91  const RenderingContextView& renderer, // the current renderer
92  const PixelInfo pixel_info, // packed pixel info
93  const uint32 prev_vertex_info, // packed previous vertex info
94  const uint32 vertex_info, // packed vertex info
95  const EyeVertex& ev, // the local vertex
96  const cugar::Vector3f& f_d, // the diffuse BSDF weight
97  const cugar::Vector3f& f_g, // the glossy BSDF weight
98  const cugar::Vector3f& w, // the current path weight
99  const cugar::Vector3f& f_L, // the current light EDF sample contribution
100  cugar::Vector3f& out_w_d, // the output diffuse weight
101  cugar::Vector3f& out_w_g, // the output glossy weight
102  uint32& out_vertex_info) // the output packed vertex info
103  {
105  out_w_d = (context.in_bounce == 0 ? f_d : f_d + f_g) * w * f_L;
106  out_w_g = (context.in_bounce == 0 ? f_g : f_d + f_g) * w * f_L;
107  out_vertex_info = 0xFFFFFFFF; // mark this unused
109  }
111 
126  template <typename PTContext>
127  FERMAT_DEVICE
129  const PTContext& context, // the current context
130  const RenderingContextView& renderer, // the current renderer
131  const PixelInfo pixel_info, // packed pixel info
132  const uint32 prev_vertex_info, // packed previous vertex info
133  const uint32 vertex_info, // packed vertex info
134  const EyeVertex& ev, // the local vertex
135  const uint32 out_comp, // the bsdf scattering component
136  const cugar::Vector3f& g, // the bsdf scattering weight (= f/p)
137  const cugar::Vector3f& w, // the current path weight
138  cugar::Vector3f& out_w, // the output path weight
139  uint32& out_vertex_info) // the output vertex info
140  {
141  out_w = g * w;
142  out_vertex_info = 0xFFFFFFFF; // mark this unused
143  }
145 
156  template <typename PTContext>
157  FERMAT_DEVICE
159  const PTContext& context, // the current context
160  RenderingContextView& renderer, // the current renderer
161  const PixelInfo pixel_info, // packed pixel info
162  const uint32 prev_vertex_info, // packed previous vertex info
163  const uint32 vertex_info, // packed vertex info
164  const EyeVertex& ev, // the local vertex
165  const cugar::Vector3f& w) // the current path weight
166  {
167  FBufferView& fb = renderer.fb;
168  FBufferChannelView& composited_channel = fb(FBufferDesc::COMPOSITED_C);
169  FBufferChannelView& direct_channel = fb(FBufferDesc::DIRECT_C);
170  FBufferChannelView& diffuse_channel = fb(FBufferDesc::DIFFUSE_C);
171  FBufferChannelView& specular_channel = fb(FBufferDesc::SPECULAR_C);
172 
173  const uint32 pixel_index = pixel_info.pixel;
174  const uint32 pixel_comp = pixel_info.comp;
175  const float frame_weight = context.frame_weight;
176 
177  // accumulate to the image
178  add_in<false>(composited_channel, pixel_index, w, frame_weight);
179 
180  // accumulate the per-component value to the proper output channel
181  if (context.in_bounce == 0)
182  add_in<false>(direct_channel, pixel_index, w, frame_weight);
183  else
184  {
185  if (pixel_comp & Bsdf::kDiffuseMask) add_in<true>(diffuse_channel, pixel_index, w, frame_weight);
186  if (pixel_comp & Bsdf::kGlossyMask) add_in<true>(specular_channel, pixel_index, w, frame_weight);
187  }
188  }
190 
202  template <typename PTContext>
203  FERMAT_DEVICE
205  const PTContext& context, // the current context
206  RenderingContextView& renderer, // the current renderer
207  const PixelInfo pixel_info, // packed pixel info
208  const uint32 vertex_info, // packed vertex info
209  const bool shadow_hit, // the hit information
210  const cugar::Vector3f& w_d, // the diffuse NEE weight
211  const cugar::Vector3f& w_g) // the glossy NEE weight
212  {
213  if (shadow_hit == false)
214  {
215  FBufferView& fb = renderer.fb;
216  FBufferChannelView& composited_channel = fb(FBufferDesc::COMPOSITED_C);
217  FBufferChannelView& diffuse_channel = fb(FBufferDesc::DIFFUSE_C);
218  FBufferChannelView& specular_channel = fb(FBufferDesc::SPECULAR_C);
219 
220  const uint32 pixel_index = pixel_info.pixel;
221  const uint32 pixel_comp = pixel_info.comp;
222  const float frame_weight = context.frame_weight;
223 
224  add_in<false>( composited_channel, pixel_index, w_d + w_g, frame_weight );
225 
226  if (context.in_bounce == 0)
227  {
228  // accumulate the per-component values to the respective output channels
229  add_in<true>( diffuse_channel, pixel_index, w_d, frame_weight );
230  add_in<true>( specular_channel, pixel_index, w_g, frame_weight );
231  }
232  else
233  {
234  // accumulate the per-component value to the proper output channel
235  if (pixel_comp & Bsdf::kDiffuseMask) add_in<true>( diffuse_channel, pixel_index, w_d, frame_weight );
236  if (pixel_comp & Bsdf::kGlossyMask) add_in<true>( specular_channel, pixel_index, w_g, frame_weight );
237  }
238  }
239  }
241 };
242 
FERMAT_DEVICE void accumulate_nee(const PTContext &context, RenderingContextView &renderer, const PixelInfo pixel_info, const uint32 vertex_info, const bool shadow_hit, const cugar::Vector3f &w_d, const cugar::Vector3f &w_g)
[PTVertexProcessor::accumulate_emissive]
Definition: pathtracer_vertex_processor.h:204
FERMAT_DEVICE uint32 preprocess_vertex(const PTContext &context, const RenderingContextView &renderer, const PixelInfo pixel_info, const EyeVertex &ev, const float cone_radius, const cugar::Bbox3f scene_bbox, const uint32 prev_vertex_info, const cugar::Vector3f w, const float p_prev)
Definition: pathtracer_vertex_processor.h:58
Definition: pathtracer_vertex_processor.h:46
Definition: framebuffer.h:274
FERMAT_DEVICE void compute_nee_weights(const PTContext &context, const RenderingContextView &renderer, const PixelInfo pixel_info, const uint32 prev_vertex_info, const uint32 vertex_info, const EyeVertex &ev, const cugar::Vector3f &f_d, const cugar::Vector3f &f_g, const cugar::Vector3f &w, const cugar::Vector3f &f_L, cugar::Vector3f &out_w_d, cugar::Vector3f &out_w_g, uint32 &out_vertex_info)
Definition: pathtracer_vertex_processor.h:89
Definition: bpt_utils.h:583
Definition: framebuffer.h:125
Definition: pathtracer_core.h:527
FERMAT_DEVICE void accumulate_emissive(const PTContext &context, RenderingContextView &renderer, const PixelInfo pixel_info, const uint32 prev_vertex_info, const uint32 vertex_info, const EyeVertex &ev, const cugar::Vector3f &w)
[PTVertexProcessor::compute_scattering_weights]
Definition: pathtracer_vertex_processor.h:158
Definition: renderer_view.h:80
FERMAT_DEVICE void compute_scattering_weights(const PTContext &context, const RenderingContextView &renderer, const PixelInfo pixel_info, const uint32 prev_vertex_info, const uint32 vertex_info, const EyeVertex &ev, const uint32 out_comp, const cugar::Vector3f &g, const cugar::Vector3f &w, cugar::Vector3f &out_w, uint32 &out_vertex_info)
[PTVertexProcessor::compute_nee_weights]
Definition: pathtracer_vertex_processor.h:128