Changeset View
Changeset View
Standalone View
Standalone View
source/blender/render/intern/source/rayshade.c
| Show First 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | for (obi=re->instancetable.first; obi; obi=obi->next) { | ||||
| if (obi->raytree) { | if (obi->raytree) { | ||||
| RE_rayobject_free(obi->raytree); | RE_rayobject_free(obi->raytree); | ||||
| obi->raytree = NULL; | obi->raytree = NULL; | ||||
| } | } | ||||
| } | } | ||||
| #ifdef RE_RAYCOUNTER | #ifdef RE_RAYCOUNTER | ||||
| { | { | ||||
| const int num_threads = re->r.threads; | |||||
| RayCounter sum; | RayCounter sum; | ||||
| memset(&sum, 0, sizeof(sum)); | memset(&sum, 0, sizeof(sum)); | ||||
| int i; | int i; | ||||
| for (i=0; i<BLENDER_MAX_THREADS; i++) | for (i=0; i<num_threads; i++) | ||||
| RE_RC_MERGE(&sum, re_rc_counter+i); | RE_RC_MERGE(&sum, re_rc_counter+i); | ||||
| RE_RC_INFO(&sum); | RE_RC_INFO(&sum); | ||||
| } | } | ||||
| #endif | #endif | ||||
| } | } | ||||
| static bool is_raytraceable_vlr(Render *re, VlakRen *vlr) | static bool is_raytraceable_vlr(Render *re, VlakRen *vlr) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 992 Lines • ▼ Show 20 Lines | static void QMC_sampleHemiCosine(float vec[3], QMCSampler *qsa, int thread, int num) | ||||
| vec[2] = 1.f - s[1]*s[1]; | vec[2] = 1.f - s[1]*s[1]; | ||||
| } | } | ||||
| #endif | #endif | ||||
| /* called from convertBlenderScene.c */ | /* called from convertBlenderScene.c */ | ||||
| void init_render_qmcsampler(Render *re) | void init_render_qmcsampler(Render *re) | ||||
| { | { | ||||
| re->qmcsamplers= MEM_callocN(sizeof(ListBase)*BLENDER_MAX_THREADS, "QMCListBase"); | const int num_threads = re->r.threads; | ||||
| re->qmcsamplers= MEM_callocN(sizeof(ListBase)*num_threads, "QMCListBase"); | |||||
| re->num_qmc_samplers = num_threads; | |||||
| } | } | ||||
| static QMCSampler *get_thread_qmcsampler(Render *re, int thread, int type, int tot) | static QMCSampler *get_thread_qmcsampler(Render *re, int thread, int type, int tot) | ||||
| { | { | ||||
| QMCSampler *qsa; | QMCSampler *qsa; | ||||
| /* create qmc samplers as needed, since recursion makes it hard to | /* create qmc samplers as needed, since recursion makes it hard to | ||||
| * predict how many are needed */ | * predict how many are needed */ | ||||
| Show All 17 Lines | static void release_thread_qmcsampler(Render *UNUSED(re), int UNUSED(thread), QMCSampler *qsa) | ||||
| qsa->used= 0; | qsa->used= 0; | ||||
| } | } | ||||
| void free_render_qmcsampler(Render *re) | void free_render_qmcsampler(Render *re) | ||||
| { | { | ||||
| if (re->qmcsamplers) { | if (re->qmcsamplers) { | ||||
| QMCSampler *qsa, *next; | QMCSampler *qsa, *next; | ||||
| int a; | int a; | ||||
| for (a=0; a<BLENDER_MAX_THREADS; a++) { | for (a = 0; a < re->num_qmc_samplers; a++) { | ||||
| for (qsa=re->qmcsamplers[a].first; qsa; qsa=next) { | for (qsa=re->qmcsamplers[a].first; qsa; qsa=next) { | ||||
| next= qsa->next; | next= qsa->next; | ||||
| QMC_freeSampler(qsa); | QMC_freeSampler(qsa); | ||||
| } | } | ||||
| re->qmcsamplers[a].first= re->qmcsamplers[a].last= NULL; | re->qmcsamplers[a].first= re->qmcsamplers[a].last= NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | static void DS_energy(float *sphere, int tot, float vec[3]) | ||||
| add_v3_v3(vec, res); | add_v3_v3(vec, res); | ||||
| normalize_v3(vec); | normalize_v3(vec); | ||||
| } | } | ||||
| /* called from convertBlenderScene.c */ | /* called from convertBlenderScene.c */ | ||||
| /* creates an equally distributed spherical sample pattern */ | /* creates an equally distributed spherical sample pattern */ | ||||
| /* and allocates threadsafe memory */ | /* and allocates threadsafe memory */ | ||||
| void init_ao_sphere(World *wrld) | void init_ao_sphere(Render *re, World *wrld) | ||||
| { | { | ||||
| /* fixed random */ | /* fixed random */ | ||||
| const int num_threads = re->r.threads; | |||||
| RNG *rng; | RNG *rng; | ||||
| float *fp; | float *fp; | ||||
| int a, tot, iter= 16; | int a, tot, iter= 16; | ||||
| /* we make twice the amount of samples, because only a hemisphere is used */ | /* we make twice the amount of samples, because only a hemisphere is used */ | ||||
| tot= 2*wrld->aosamp*wrld->aosamp; | tot= 2*wrld->aosamp*wrld->aosamp; | ||||
| wrld->aosphere= MEM_mallocN(3*tot*sizeof(float), "AO sphere"); | wrld->aosphere= MEM_mallocN(3*tot*sizeof(float), "AO sphere"); | ||||
| rng = BLI_rng_new_srandom(tot); | rng = BLI_rng_new_srandom(tot); | ||||
| /* init */ | /* init */ | ||||
| fp= wrld->aosphere; | fp= wrld->aosphere; | ||||
| for (a=0; a<tot; a++, fp+= 3) { | for (a=0; a<tot; a++, fp+= 3) { | ||||
| BLI_rng_get_float_unit_v3(rng, fp); | BLI_rng_get_float_unit_v3(rng, fp); | ||||
| } | } | ||||
| while (iter--) { | while (iter--) { | ||||
| for (a=0, fp= wrld->aosphere; a<tot; a++, fp+= 3) { | for (a=0, fp= wrld->aosphere; a<tot; a++, fp+= 3) { | ||||
| DS_energy(wrld->aosphere, tot, fp); | DS_energy(wrld->aosphere, tot, fp); | ||||
| } | } | ||||
| } | } | ||||
| /* tables */ | /* tables */ | ||||
| wrld->aotables= MEM_mallocN(BLENDER_MAX_THREADS*3*tot*sizeof(float), "AO tables"); | wrld->aotables= MEM_mallocN(num_threads*3*tot*sizeof(float), "AO tables"); | ||||
| BLI_rng_free(rng); | BLI_rng_free(rng); | ||||
| } | } | ||||
| /* give per thread a table, we have to compare xs ys because of way OSA works... */ | /* give per thread a table, we have to compare xs ys because of way OSA works... */ | ||||
| static float *threadsafe_table_sphere(int test, int thread, int xs, int ys, int tot) | static float *threadsafe_table_sphere(int test, int thread, int xs, int ys, int tot) | ||||
| { | { | ||||
| static int xso[BLENDER_MAX_THREADS], yso[BLENDER_MAX_THREADS]; | static int xso[BLENDER_MAX_THREADS], yso[BLENDER_MAX_THREADS]; | ||||
| ▲ Show 20 Lines • Show All 767 Lines • Show Last 20 Lines | |||||