31 #include <pathtracer_core.h> 32 #include <spatial_hash.h> 33 #include <cugar/basic/cuda/hash.h> 51 static const uint32 DIFFUSE_COMP = 0x1u;
52 static const uint32 GLOSSY_COMP = 0x2u;
53 static const uint32 ALL_COMPS = 0x3u;
58 const static uint32 INVALID = 0xFFFFFFFFu;
59 const static uint32 INVALID_SLOT = 0xFFFFFFFFu & ((1u << 29) - 1u);
61 FERMAT_HOST_DEVICE
CacheInfo() : packed(INVALID) {}
62 FERMAT_HOST_DEVICE CacheInfo(
const uint32 _packed) : packed(_packed) {}
63 FERMAT_HOST_DEVICE CacheInfo(
const uint32 _pixel,
const uint32 _comp,
const uint32 _new_entry) : pixel(_pixel), comp(_comp), new_entry(_new_entry){}
66 bool is_invalid()
const {
return pixel == INVALID_SLOT; }
69 bool is_valid()
const {
return pixel != INVALID_SLOT; }
79 FERMAT_HOST_DEVICE
operator uint32()
const {
return packed; }
83 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
86 FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
101 template <
typename TPTContext>
108 const float cone_radius,
110 const uint32 prev_vertex_info,
115 CacheInfo prev_cache_info(prev_vertex_info);
118 uint32 new_cache_slot = prev_cache_info.pixel;
119 bool new_cache_entry =
false;
125 if (prev_cache_info.is_invalid() && context.in_bounce >= context.options.psf_depth && p_prev < context.options.psf_max_prob)
129 const uint32 pixel_hash = pixel_info.pixel + renderer.instance * renderer.res_x * renderer.res_y;
132 const float jitter[6] = {
142 const float jitter[6] = {0};
147 const float cone_scale = context.options.psf_width;
148 const float filter_scale = (context.in_bounce == 0.0f ? 2.0f : 1.0f);
154 dot(ev.in, ev.geom.normal_s) > 0.0f ? ev.geom.normal_s : -ev.geom.normal_s,
159 cone_radius * cone_scale,
165 if (context.psf_hashmap.insert(shading_key,
cugar::hash(shading_key), &new_cache_slot) ==
true)
167 FERMAT_ASSERT(new_cache_slot < cugar::cuda::load<cugar::cuda::LOAD_VOLATILE>(context.psf_hashmap.count));
169 context.psf_values[new_cache_slot] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
171 FERMAT_ASSERT(new_cache_slot < cugar::cuda::load<cugar::cuda::LOAD_VOLATILE>(context.psf_hashmap.count));
181 context.ref_queue.warp_append(
184 (pixel_info.comp & Bsdf::kDiffuseMask) ? w_mod :
cugar::Vector4f(0.0f),
185 (pixel_info.comp & Bsdf::kGlossyMask) && context.in_bounce ? w_mod :
cugar::Vector4f(0.0f)
191 new_cache_entry =
true;
194 return CacheInfo(new_cache_slot, 0, new_cache_entry);
213 template <
typename TPTContext>
216 const TPTContext& context,
219 const uint32 prev_vertex_info,
220 const uint32 vertex_info,
228 uint32& out_vertex_info)
230 const CacheInfo new_cache_info(vertex_info);
232 const bool new_cache_entry = new_cache_info.new_entry;
234 const CacheInfo out_cache_info = context.in_bounce < context.options.psf_depth ?
CacheInfo(CacheInfo::INVALID) :
236 CacheInfo(new_cache_info.pixel, DIFFUSE_COMP, 0) :
237 CacheInfo(new_cache_info.pixel, ALL_COMPS, 0);
239 out_vertex_info = out_cache_info;
256 if (new_cache_entry && out_cache_info.is_valid())
258 out_w_d = demodulate( f_d,
cugar::Vector4f(ev.material.diffuse).xyz() ) * f_L;
259 out_w_g = f_g * w.xyz() * f_L;
263 out_w_d = f_d * w.xyz() * f_L;
264 out_w_g = f_g * w.xyz() * f_L;
283 template <
typename TPTContext>
286 const TPTContext& context,
289 const uint32 prev_vertex_info,
290 const uint32 vertex_info,
292 const uint32 out_comp,
296 uint32& out_vertex_info)
298 const CacheInfo prev_cache_info(prev_vertex_info);
299 const CacheInfo new_cache_info(vertex_info);
301 const uint32 new_cache_slot = new_cache_info.pixel;
302 const bool new_cache_entry = new_cache_info.new_entry;
304 const CacheInfo out_cache_info = prev_cache_info.is_invalid() && (out_comp & Bsdf::kGlossyMask) ?
308 out_vertex_info = out_cache_info;
313 if (new_cache_entry && (out_comp & Bsdf::kDiffuseMask))
330 template <
typename TPTContext>
333 const TPTContext& context,
336 const uint32 prev_vertex_info,
337 const uint32 vertex_info,
348 const CacheInfo prev_cache_info(prev_vertex_info);
354 const uint32 pixel_index = pixel_info.pixel;
355 const uint32 pixel_comp = pixel_info.comp;
356 const float frame_weight = context.frame_weight;
359 if (prev_cache_info.is_invalid())
361 add_in<false>(composited_channel, pixel_index, clamped_out_w, frame_weight);
364 if (context.in_bounce == 0)
365 add_in<false>(direct_channel, pixel_index, clamped_out_w, frame_weight);
368 if (pixel_comp & Bsdf::kDiffuseMask) add_in<true>(diffuse_channel, pixel_index, clamped_out_w, frame_weight);
369 if (pixel_comp & Bsdf::kGlossyMask) add_in<true>(specular_channel, pixel_index, clamped_out_w, frame_weight);
375 cugar::atomic_add(&context.psf_values[prev_cache_info.pixel].x, clamped_out_w.x);
376 cugar::atomic_add(&context.psf_values[prev_cache_info.pixel].y, clamped_out_w.y);
377 cugar::atomic_add(&context.psf_values[prev_cache_info.pixel].z, clamped_out_w.z);
393 template <
typename TPTContext>
396 const TPTContext& context,
399 const uint32 vertex_info,
400 const bool shadow_hit,
411 const uint32 pixel_index = pixel_info.pixel;
412 const uint32 pixel_comp = pixel_info.comp;
413 const float frame_weight = context.frame_weight;
418 if (shadow_hit ==
false)
421 if (cache_info.is_valid())
424 const uint32 cache_slot = cache_info.pixel;
427 const cugar::Vector3f w = (cache_info.comp == DIFFUSE_COMP) ? w_d : w_d + w_g;
436 if (cache_info.comp == DIFFUSE_COMP)
438 add_in<false>(composited_channel, pixel_index, clamp_sample( w_g ), frame_weight);
441 FBufferChannelView& fb_channel = context.in_bounce == 0 || (pixel_comp & Bsdf::kGlossyMask) ?
445 add_in<true>(fb_channel, pixel_index, clamp_sample( w_g ), context.frame_weight);
452 add_in<false>(composited_channel, pixel_index, clamp_sample( w_d + w_g ), frame_weight);
454 if (context.in_bounce == 0)
457 add_in<true>(diffuse_channel, pixel_index, clamp_sample( w_d ), context.frame_weight);
458 add_in<true>(specular_channel, pixel_index, clamp_sample( w_g ), context.frame_weight);
463 if (pixel_comp & Bsdf::kDiffuseMask) add_in<true>(diffuse_channel, pixel_index, clamp_sample( w_d + w_g ), frame_weight);
464 if (pixel_comp & Bsdf::kGlossyMask) add_in<true>(specular_channel, pixel_index, clamp_sample( w_d + w_g ), frame_weight);
FERMAT_DEVICE void accumulate_nee(const TPTContext &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)
[PSFPTVertexProcessor::accumulate_emissive]
Definition: psfpt_vertex_processor.h:395
float firefly_filter
[PSFPTVertexProcessor::accumulate_nee]
Definition: psfpt_vertex_processor.h:472
FERMAT_DEVICE uint32 preprocess_vertex(TPTContext &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: psfpt_vertex_processor.h:103
FERMAT_HOST_DEVICE FERMAT_FORCEINLINE PSFPTVertexProcessor(float _firefly_filter=1000.0f)
[PSFPTVertexProcessor::CacheInfo]
Definition: psfpt_vertex_processor.h:84
Definition: psfpt_vertex_processor.h:49
FERMAT_DEVICE void compute_scattering_weights(const TPTContext &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)
[PSFPTVertexProcessor::compute_nee_weights]
Definition: psfpt_vertex_processor.h:285
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE float atomic_add(float *value, const float op)
Definition: atomics.h:100
FERMAT_FORCEINLINE FERMAT_HOST_DEVICE uint64 spatial_hash(const cugar::Vector3f P, const cugar::Vector3f N, const cugar::Bbox3f bbox, const float samples[6], const float cone_radius, const uint32 normal_bits=4)
Definition: spatial_hash.h:44
Definition: framebuffer.h:274
FERMAT_DEVICE void accumulate_emissive(const TPTContext &context, RenderingContextView &renderer, const PixelInfo pixel_info, const uint32 prev_vertex_info, const uint32 vertex_info, const EyeVertex &ev, const cugar::Vector3f &out_w)
[PSFPTVertexProcessor::compute_scattering_weights]
Definition: psfpt_vertex_processor.h:332
Definition: bpt_utils.h:583
Definition: framebuffer.h:125
Definition: pathtracer_core.h:527
Definition: renderer_view.h:80
[PSFPTVertexProcessor::CacheInfo]
Definition: psfpt_vertex_processor.h:56
FERMAT_DEVICE void compute_nee_weights(const TPTContext &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)
[PSFPTVertexProcessor::preprocess_vertex]
Definition: psfpt_vertex_processor.h:215
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE uint32 hash(uint32 a)
Definition: numbers.h:649
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE float randfloat(unsigned i, unsigned p)
Definition: numbers.h:753