31 #include <pathtracer.h> 34 #include <mesh/MeshStorage.h> 35 #include <cugar/basic/timer.h> 36 #include <cugar/basic/primitives.h> 37 #include <cugar/basic/memory_arena.h> 38 #include <pathtracer_core.h> 39 #include <pathtracer_queues.h> 40 #include <pathtracer_kernels.h> 41 #include <pathtracer_vertex_processor.h> 61 template <
typename TDirectLightingSampler>
64 TDirectLightingSampler dl;
73 mesh_vtls->get_bvh_clusters_count(),
74 mesh_vtls->get_bvh_cluster_offsets());
81 mesh_vtls->get_bvh_nodes(),
82 mesh_vtls->get_bvh_parents(),
83 mesh_vtls->get_bvh_ranges(),
84 mesh_vtls->get_bvh_clusters_count(),
85 mesh_vtls->get_bvh_clusters(),
86 mesh_vtls->get_bvh_cluster_offsets());
91 PathTracer::PathTracer() :
92 m_generator(32,
cugar::LFSRGeneratorMatrix::GOOD_PROJECTIONS),
93 m_random(&m_generator, 1u, 1351u)
96 m_vtls_rl =
new VTLRLStorage;
101 const uint2 res = renderer.
res();
102 const uint32 n_pixels = res.x * res.y;
105 m_options.parse(argc, argv);
107 const char* nee_alg[] = {
"mesh",
"vpl",
"rl" };
109 fprintf(stderr,
" PT settings:\n");
110 fprintf(stderr,
" path-length : %u\n", m_options.max_path_length);
111 fprintf(stderr,
" direct-nee : %u\n", m_options.direct_lighting_nee ? 1 : 0);
112 fprintf(stderr,
" direct-bsdf : %u\n", m_options.direct_lighting_bsdf ? 1 : 0);
113 fprintf(stderr,
" indirect-nee : %u\n", m_options.indirect_lighting_nee ? 1 : 0);
114 fprintf(stderr,
" indirect-bsdf : %u\n", m_options.indirect_lighting_bsdf ? 1 : 0);
115 fprintf(stderr,
" visible-lights : %u\n", m_options.visible_lights ? 1 : 0);
116 fprintf(stderr,
" direct lighting : %u\n", m_options.direct_lighting ? 1 : 0);
117 fprintf(stderr,
" diffuse : %u\n", m_options.diffuse_scattering ? 1 : 0);
118 fprintf(stderr,
" glossy : %u\n", m_options.glossy_scattering ? 1 : 0);
119 fprintf(stderr,
" indirect glossy : %u\n", m_options.indirect_glossy ? 1 : 0);
120 fprintf(stderr,
" RR : %u\n", m_options.rr ? 1 : 0);
121 fprintf(stderr,
" nee algorithm : %s\n", nee_alg[ m_options.nee_type ]);
141 arena.
alloc<int64>( 16 );
143 fprintf(stderr,
" allocating queue storage: %.1f MB\n",
float(arena.size) / (1024*1024));
144 m_memory_pool.alloc(arena.size);
148 const uint32 n_dimensions = 6 * (m_options.max_path_length + 1);
149 fprintf(stderr,
" initializing sampler: %u dimensions\n", n_dimensions);
150 m_sequence.setup(n_dimensions, SHIFT_RES);
152 const uint32 n_light_paths = n_pixels;
154 fprintf(stderr,
" creating mesh lights... started\n");
159 fprintf(stderr,
" creating mesh lights... done\n");
166 m_options.nee_type = NEE_ALGORITHM_MESH;
168 if (m_options.nee_type == NEE_ALGORITHM_RL)
170 fprintf(stderr,
" creating mesh VTLs... started\n");
171 m_mesh_vtls->init(n_light_paths, renderer, 0u );
172 fprintf(stderr,
" creating mesh VTLs... done (%u VTLs, %u clusters)\n", m_mesh_vtls->get_vtl_count(), m_mesh_vtls->get_bvh_clusters_count());
174 fprintf(stderr,
" initializing VTLs RL... started\n");
175 ::init( m_vtls_rl, m_mesh_vtls );
176 fprintf(stderr,
" initializing VTLs RL... done (%.1f MB)\n", m_vtls_rl->needed_bytes(VTL_RL_HASH_SIZE, m_mesh_vtls->get_bvh_clusters_count()) /
float(1024*1024));
180 void PathTracer::update_vtls_rl(
const uint32 instance)
182 if ((instance % 32) == 0)
191 CUDA_CHECK(cugar::cuda::sync_and_check_error(
"vtl-rl update"));
204 const uint2 res = renderer.
res();
205 const uint32 n_pixels = res.x * res.y;
231 uint64* device_timers = arena.alloc<uint64>( 16 );
239 if (m_options.nee_type == NEE_ALGORITHM_RL)
240 update_vtls_rl( instance );
243 m_sequence.set_instance(instance);
249 if (m_options.nee_type == NEE_ALGORITHM_RL)
252 PathTracingContext<DirectLightingRL> context;
253 context.options = m_options;
254 context.in_bounce = 0;
255 context.in_queue = in_queue;
256 context.scatter_queue = scatter_queue;
257 context.shadow_queue = shadow_queue;
258 context.sequence = m_sequence.view();
259 context.frame_weight = 1.0f / float(renderer_view.instance + 1);
260 context.device_timers = device_timers;
261 context.bbox = m_bbox;
264 m_mesh_vtls->view() );
267 path_trace_loop( context, vertex_processor, renderer, renderer_view, stats );
272 MeshLight mesh_light = m_options.nee_type == NEE_ALGORITHM_VPL ? renderer_view.mesh_vpls : renderer_view.mesh_light;
275 PathTracingContext<DirectLightingMesh> context;
276 context.options = m_options;
277 context.in_bounce = 0;
278 context.in_queue = in_queue;
279 context.scatter_queue = scatter_queue;
280 context.shadow_queue = shadow_queue;
281 context.sequence = m_sequence.view();
282 context.frame_weight = 1.0f / float(renderer_view.instance + 1);
283 context.device_timers = device_timers;
284 context.bbox = m_bbox;
288 path_trace_loop( context, vertex_processor, renderer, renderer_view, stats );
293 const float time = timer.seconds();
300 fprintf(stderr,
"\r %.1fs (%.1fms = rt[%.1fms + %.1fms + %.1fms] + shade[%.1fms + %.1fms] - %uK cells) ",
308 m_options.nee_type == NEE_ALGORITHM_RL ? m_vtls_rl->size() / 1000 : 0);
310 #if defined(DEVICE_TIMING) && DEVICE_TIMING 311 if (instance % 64 == 0)
312 print_timer_stats( device_timers, stats );
334 m_options.direct_lighting = !m_options.direct_lighting;
344 fprintf(stats,
"%f, %f, %f, %f, %f\n",
345 m_stats.primary_rt_time.mean() * 1000.0f,
346 m_stats.path_rt_time.mean() * 1000.0f,
347 m_stats.shadow_rt_time.mean() * 1000.0f,
348 m_stats.path_shade_time.mean() * 1000.0f,
349 m_stats.shadow_shade_time.mean() * 1000.0f);
Definition: direct_lighting_rl.h:45
Definition: pathtracer_kernels.h:49
void init(int argc, char **argv, RenderingContext &renderer)
Definition: pathtracer_impl.h:99
float shadow_shade_time
time spent for shading shadow samples (i.e. in solve_occlusion)
Definition: pathtracer_kernels.h:303
void render(const uint32 instance, RenderingContext &renderer)
Definition: pathtracer_impl.h:197
void update_variances(const uint32 instance)
void start()
start timing
Definition: timer.cpp:116
Definition: mesh_lights.h:59
Definition: direct_lighting_mesh.h:41
Definition: clustered_rl.h:161
CUGAR_HOST_DEVICE T * alloc(const uint64 sz, const uint64 alignment=sizeof(T))
Definition: memory_arena.h:69
void dump_speed_stats(FILE *stats)
Definition: pathtracer_impl.h:342
Definition: pathtracer_vertex_processor.h:46
Definition: pathtracer_kernels.h:284
float path_rt_time
time spent for tracing scattering rays
Definition: pathtracer_kernels.h:300
MeshLightsStorage & get_mesh_lights()
float shadow_rt_time
time spent for tracing shadow rays
Definition: pathtracer_kernels.h:301
float primary_rt_time
time spent for tracing primary rays
Definition: pathtracer_kernels.h:299
Definition: pathtracer_core.h:570
RenderingContextView view(const uint32 instance)
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
void keyboard(unsigned char character, int x, int y, bool &invalidate)
Definition: pathtracer_impl.h:327
Definition: clustered_rl.h:87
void path_trace_loop(TPTContext &context, TPTVertexProcessor &vertex_processor, RenderingContext &renderer, RenderingContextView &renderer_view, PTLoopStats &stats)
Definition: pathtracer_kernels.h:310
Definition: renderer.h:52
void alloc_queues(PTOptions options, const uint32 n_pixels, PTRayQueue &input_queue, PTRayQueue &scatter_queue, PTRayQueue &shadow_queue, cugar::memory_arena &arena)
Definition: pathtracer_kernels.h:91
void rescale_frame(const uint32 instance)
Definition: memory_arena.h:44
Definition: renderer_view.h:80
Definition: pathtracer_queues.h:44
cugar::Bbox3f compute_bbox()
float path_shade_time
time spent for shading path vertices
Definition: pathtracer_kernels.h:302