equal
deleted
inserted
replaced
10 #endif |
10 #endif |
11 |
11 |
12 #include <stdio.h> |
12 #include <stdio.h> |
13 #include <malloc.h> |
13 #include <malloc.h> |
14 #include "raytracer.h" |
14 #include "raytracer.h" |
|
15 |
|
16 int pyrit_verbosity = 2; |
15 |
17 |
16 // Hammersley spherical point distribution |
18 // Hammersley spherical point distribution |
17 // http://www.cse.cuhk.edu.hk/~ttwong/papers/udpoint/udpoints.html |
19 // http://www.cse.cuhk.edu.hk/~ttwong/papers/udpoint/udpoints.html |
18 Vector3 Raytracer::SphereDistribute(int i, int n, Float extent, Vector3 &normal) |
20 Vector3 Raytracer::SphereDistribute(int i, int n, Float extent, Vector3 &normal) |
19 { |
21 { |
317 + camera->v*(h/2.0*S/camera->f) + camera->p; |
319 + camera->v*(h/2.0*S/camera->f) + camera->p; |
318 Vector3 dx = camera->u * (S/camera->f); |
320 Vector3 dx = camera->u * (S/camera->f); |
319 Vector3 dy = camera->v * (-S/camera->f); |
321 Vector3 dy = camera->v * (-S/camera->f); |
320 |
322 |
321 #ifdef PTHREADS |
323 #ifdef PTHREADS |
322 infomsg("* pthreads enabled, using %d threads\n", num_threads); |
324 dbgmsg(1, "* pthreads enabled, using %d threads\n", num_threads); |
323 pthread_t threads[num_threads]; |
325 pthread_t threads[num_threads]; |
324 for (int t = 0; t < num_threads; t++) |
326 for (int t = 0; t < num_threads; t++) |
325 threads[t] = pthread_self(); |
327 threads[t] = pthread_self(); |
326 int t = 0; |
328 int t = 0; |
327 #endif |
329 #endif |
328 |
330 |
329 /* for each pixel... */ |
331 /* for each pixel... */ |
330 infomsg("* rendering row 0 ( 0%% done)"); |
332 dbgmsg(1, "* raytracing...\n"); |
|
333 dbgmsg(2, "- row 0 ( 0%% done)"); |
331 for (int y = 0; y < h; y += subsample) |
334 for (int y = 0; y < h; y += subsample) |
332 { |
335 { |
333 d = (RenderrowData*) malloc(sizeof(RenderrowData)); |
336 d = (RenderrowData*) malloc(sizeof(RenderrowData)); |
334 d->rt = this; |
337 d->rt = this; |
335 d->w = w; |
338 d->w = w; |
340 d->iter = buffer + y*3*w; |
343 d->iter = buffer + y*3*w; |
341 #ifdef PTHREADS |
344 #ifdef PTHREADS |
342 /* create new thread and increase 't' */ |
345 /* create new thread and increase 't' */ |
343 int rc = pthread_create(&threads[t++], NULL, renderrow, (void *)d); |
346 int rc = pthread_create(&threads[t++], NULL, renderrow, (void *)d); |
344 if (rc) { |
347 if (rc) { |
345 infomsg("\nERROR: return code from pthread_create() is %d\n", rc); |
348 dbgmsg(0, "\nE pthread_create unsuccessful, return code was %d\n", rc); |
346 exit(1); |
349 exit(1); |
347 } |
350 } |
348 /* when 't' owerflows, reset it */ |
351 /* when 't' owerflows, reset it */ |
349 if (t >= num_threads) |
352 if (t >= num_threads) |
350 t = 0; |
353 t = 0; |
356 #else |
359 #else |
357 renderrow((void *)d); |
360 renderrow((void *)d); |
358 free(d); |
361 free(d); |
359 #endif |
362 #endif |
360 dfix += dy*subsample; |
363 dfix += dy*subsample; |
361 infomsg("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%4d (%2d%% done)", y, y*100/(h-1)); |
364 dbgmsg(2, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%4d (%2d%% done)", y, y*100/(h-1)); |
362 } |
365 } |
363 infomsg("\n"); |
366 dbgmsg(2, "\n"); |
364 |
367 |
365 #ifdef PTHREADS |
368 #ifdef PTHREADS |
366 infomsg("* waiting for threads to finish\n"); |
369 dbgmsg(2, "- waiting for threads to finish\n"); |
367 for (t = 0; t < num_threads; t++) |
370 for (t = 0; t < num_threads; t++) |
368 if (pthread_join(threads[t], (void**)&d) == 0) |
371 if (pthread_join(threads[t], (void**)&d) == 0) |
369 free(d); |
372 free(d); |
370 #endif |
373 #endif |
371 } |
374 } |