3 * ***** BEGIN GPL LICENSE BLOCK *****
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): Matt Ebb, Ra˙l Fern·ndez Hern·ndez (Farsthary).
26 * ***** END GPL LICENSE BLOCK *****
29 /** \file blender/render/intern/source/volume_precache.c
39 #include "MEM_guardedalloc.h"
41 #include "BLI_blenlib.h"
43 #include "BLI_threads.h"
44 #include "BLI_voxel.h"
45 #include "BLI_utildefines.h"
49 #include "RE_shader_ext.h"
51 #include "DNA_material_types.h"
53 #include "rayintersection.h"
54 #include "rayobject.h"
55 #include "render_types.h"
56 #include "rendercore.h"
57 #include "renderdatabase.h"
58 #include "volumetric.h"
59 #include "volume_precache.h"
61 #if defined( _MSC_VER ) && !defined( __cplusplus )
62 # define inline __inline
63 #endif // defined( _MSC_VER ) && !defined( __cplusplus )
65 #include "BKE_global.h"
67 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
68 /* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
69 /* only to be used here in this file, it's for speed */
70 extern struct Render R;
71 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
73 /* *** utility code to set up an individual raytree for objectinstance, for checking inside/outside *** */
75 /* Recursive test for intersections, from a point inside the mesh, to outside
76 * Number of intersections (depth) determine if a point is inside or outside the mesh */
77 static int intersect_outside_volume(RayObject *tree, Isect *isect, float *offset, int limit, int depth)
79 if (limit == 0) return depth;
81 if (RE_rayobject_raycast(tree, isect)) {
83 isect->start[0] = isect->start[0] + isect->dist*isect->dir[0];
84 isect->start[1] = isect->start[1] + isect->dist*isect->dir[1];
85 isect->start[2] = isect->start[2] + isect->dist*isect->dir[2];
87 isect->dist = FLT_MAX;
88 isect->skip = RE_SKIP_VLR_NEIGHBOUR;
89 isect->orig.face= isect->hit.face;
90 isect->orig.ob= isect->hit.ob;
92 return intersect_outside_volume(tree, isect, offset, limit-1, depth+1);
98 /* Uses ray tracing to check if a point is inside or outside an ObjectInstanceRen */
99 static int point_inside_obi(RayObject *tree, ObjectInstanceRen *UNUSED(obi), float *co)
102 float dir[3] = {0.0f,0.0f,1.0f};
103 int final_depth=0, depth=0, limit=20;
105 /* set up the isect */
106 VECCOPY(isect.start, co);
107 VECCOPY(isect.dir, dir);
108 isect.mode= RE_RAY_MIRROR;
109 isect.last_hit= NULL;
112 isect.dist = FLT_MAX;
113 isect.orig.face= NULL;
114 isect.orig.ob = NULL;
116 final_depth = intersect_outside_volume(tree, &isect, dir, limit, depth);
118 /* even number of intersections: point is outside
119 * odd number: point is inside */
120 if (final_depth % 2 == 0) return 0;
124 /* find the bounding box of an objectinstance in global space */
125 void global_bounds_obi(Render *re, ObjectInstanceRen *obi, float *bbmin, float *bbmax)
127 ObjectRen *obr = obi->obr;
128 VolumePrecache *vp = obi->volume_precache;
133 if (vp->bbmin != NULL && vp->bbmax != NULL) {
134 copy_v3_v3(bbmin, vp->bbmin);
135 copy_v3_v3(bbmax, vp->bbmax);
139 vp->bbmin = MEM_callocN(sizeof(float)*3, "volume precache min boundbox corner");
140 vp->bbmax = MEM_callocN(sizeof(float)*3, "volume precache max boundbox corner");
142 INIT_MINMAX(bbmin, bbmax);
144 for(a=0; a<obr->totvert; a++) {
145 if((a & 255)==0) ver= obr->vertnodes[a>>8].vert;
148 copy_v3_v3(co, ver->co);
150 /* transformed object instance in camera space */
151 if(obi->flag & R_TRANSFORMED)
152 mul_m4_v3(obi->mat, co);
154 /* convert to global space */
155 mul_m4_v3(re->viewinv, co);
157 DO_MINMAX(co, vp->bbmin, vp->bbmax);
160 copy_v3_v3(bbmin, vp->bbmin);
161 copy_v3_v3(bbmax, vp->bbmax);
165 /* *** light cache filtering *** */
167 static float get_avg_surrounds(float *cache, int *res, int xx, int yy, int zz)
169 int x, y, z, x_, y_, z_;
173 for (z=-1; z <= 1; z++) {
175 if (z_ >= 0 && z_ <= res[2]-1) {
177 for (y=-1; y <= 1; y++) {
179 if (y_ >= 0 && y_ <= res[1]-1) {
181 for (x=-1; x <= 1; x++) {
183 if (x_ >= 0 && x_ <= res[0]-1) {
184 const int i= V_I(x_, y_, z_, res);
186 if (cache[i] > 0.0f) {
198 if (added > 0) tot /= added;
203 /* function to filter the edges of the light cache, where there was no volume originally.
204 * For each voxel which was originally external to the mesh, it finds the average values of
205 * the surrounding internal voxels and sets the original external voxel to that average amount.
206 * Works almost a bit like a 'dilate' filter */
207 static void lightcache_filter(VolumePrecache *vp)
211 for (z=0; z < vp->res[2]; z++) {
212 for (y=0; y < vp->res[1]; y++) {
213 for (x=0; x < vp->res[0]; x++) {
214 /* trigger for outside mesh */
215 const int i= V_I(x, y, z, vp->res);
217 if (vp->data_r[i] < -0.f)
218 vp->data_r[i] = get_avg_surrounds(vp->data_r, vp->res, x, y, z);
219 if (vp->data_g[i] < -0.f)
220 vp->data_g[i] = get_avg_surrounds(vp->data_g, vp->res, x, y, z);
221 if (vp->data_b[i] < -0.f)
222 vp->data_b[i] = get_avg_surrounds(vp->data_b, vp->res, x, y, z);
229 static void lightcache_filter2(VolumePrecache *vp)
232 float *new_r, *new_g, *new_b;
233 int field_size = vp->res[0]*vp->res[1]*vp->res[2]*sizeof(float);
235 new_r = MEM_mallocN(field_size, "temp buffer for light cache filter r channel");
236 new_g = MEM_mallocN(field_size, "temp buffer for light cache filter g channel");
237 new_b = MEM_mallocN(field_size, "temp buffer for light cache filter b channel");
239 memcpy(new_r, vp->data_r, field_size);
240 memcpy(new_g, vp->data_g, field_size);
241 memcpy(new_b, vp->data_b, field_size);
243 for (z=0; z < vp->res[2]; z++) {
244 for (y=0; y < vp->res[1]; y++) {
245 for (x=0; x < vp->res[0]; x++) {
246 /* trigger for outside mesh */
247 const int i= V_I(x, y, z, vp->res);
248 if (vp->data_r[i] < -0.f)
249 new_r[i] = get_avg_surrounds(vp->data_r, vp->res, x, y, z);
250 if (vp->data_g[i] < -0.f)
251 new_g[i] = get_avg_surrounds(vp->data_g, vp->res, x, y, z);
252 if (vp->data_b[i] < -0.f)
253 new_b[i] = get_avg_surrounds(vp->data_b, vp->res, x, y, z);
258 SWAP(float *, vp->data_r, new_r);
259 SWAP(float *, vp->data_g, new_g);
260 SWAP(float *, vp->data_b, new_b);
262 if (new_r) { MEM_freeN(new_r); new_r=NULL; }
263 if (new_g) { MEM_freeN(new_g); new_g=NULL; }
264 if (new_b) { MEM_freeN(new_b); new_b=NULL; }
268 static inline int ms_I(int x, int y, int z, int *n) //has a pad of 1 voxel surrounding the core for boundary simulation
270 /* different ordering to light cache */
271 return x*(n[1]+2)*(n[2]+2) + y*(n[2]+2) + z;
274 static inline int v_I_pad(int x, int y, int z, int *n) //has a pad of 1 voxel surrounding the core for boundary simulation
276 /* same ordering to light cache, with padding */
277 return z*(n[1]+2)*(n[0]+2) + y*(n[0]+2) + x;
280 static inline int lc_to_ms_I(int x, int y, int z, int *n)
282 /* converting light cache index to multiple scattering index */
283 return (x-1)*(n[1]*n[2]) + (y-1)*(n[2]) + z-1;
286 /* *** multiple scattering approximation *** */
288 /* get the total amount of light energy in the light cache. used to normalise after multiple scattering */
289 static float total_ss_energy(VolumePrecache *vp)
295 for (z=0; z < res[2]; z++) {
296 for (y=0; y < res[1]; y++) {
297 for (x=0; x < res[0]; x++) {
298 const int i=V_I(x, y, z, res);
300 if (vp->data_r[i] > 0.f) energy += vp->data_r[i];
301 if (vp->data_g[i] > 0.f) energy += vp->data_g[i];
302 if (vp->data_b[i] > 0.f) energy += vp->data_b[i];
310 static float total_ms_energy(float *sr, float *sg, float *sb, int *res)
315 for (z=1;z<=res[2];z++) {
316 for (y=1;y<=res[1];y++) {
317 for (x=1;x<=res[0];x++) {
318 const int i = ms_I(x,y,z,res);
320 if (sr[i] > 0.f) energy += sr[i];
321 if (sg[i] > 0.f) energy += sg[i];
322 if (sb[i] > 0.f) energy += sb[i];
330 static void ms_diffuse(float *x0, float *x, float diff, int *n) //n is the unpadded resolution
333 const float dt = VOL_MS_TIMESTEP;
334 const float a = dt*diff*n[0]*n[1]*n[2];
338 for (k=1; k<=n[2]; k++)
340 for (j=1; j<=n[1]; j++)
342 for (i=1; i<=n[0]; i++)
344 x[v_I_pad(i,j,k,n)] = (x0[v_I_pad(i,j,k,n)]) + a*( x0[v_I_pad(i-1,j,k,n)]+ x0[v_I_pad(i+1,j,k,n)]+ x0[v_I_pad(i,j-1,k,n)]+
345 x0[v_I_pad(i,j+1,k,n)]+ x0[v_I_pad(i,j,k-1,n)]+x0[v_I_pad(i,j,k+1,n)]
353 static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Material *ma)
355 const float diff = ma->vol.ms_diff * 0.001f; /* compensate for scaling for a nicer UI range */
356 const int simframes = (int)(ma->vol.ms_spread * (float)MAX3(vp->res[0], vp->res[1], vp->res[2]));
357 const int shade_type = ma->vol.shade_type;
358 float fac = ma->vol.ms_intensity;
362 const int size = (n[0]+2)*(n[1]+2)*(n[2]+2);
363 double time, lasttime= PIL_check_seconds_timer();
366 float origf; /* factor for blending in original light cache */
367 float energy_ss, energy_ms;
369 float *sr0=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
370 float *sr=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
371 float *sg0=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
372 float *sg=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
373 float *sb0=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
374 float *sb=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
376 total = (float)(n[0]*n[1]*n[2]*simframes);
378 energy_ss = total_ss_energy(vp);
380 /* Scattering as diffusion pass */
381 for (m=0; m<simframes; m++)
384 for (z=1; z<=n[2]; z++)
386 for (y=1; y<=n[1]; y++)
388 for (x=1; x<=n[0]; x++)
390 const int i = lc_to_ms_I(x, y ,z, n); //lc index
391 const int j = ms_I(x, y, z, n); //ms index
393 time= PIL_check_seconds_timer();
395 if (vp->data_r[i] > 0.0f)
396 sr[j] += vp->data_r[i];
397 if (vp->data_g[i] > 0.0f)
398 sg[j] += vp->data_g[i];
399 if (vp->data_b[i] > 0.0f)
400 sb[j] += vp->data_b[i];
402 /* Displays progress every second */
403 if(time-lasttime>1.0) {
405 BLI_snprintf(str, sizeof(str), "Simulating multiple scattering: %d%%", (int)(100.0f * (c / total)));
407 re->stats_draw(re->sdh, &re->i);
414 SWAP(float *,sr,sr0);
415 SWAP(float *,sg,sg0);
416 SWAP(float *,sb,sb0);
418 /* main diffusion simulation */
419 ms_diffuse(sr0, sr, diff, n);
420 ms_diffuse(sg0, sg, diff, n);
421 ms_diffuse(sb0, sb, diff, n);
423 if (re->test_break(re->tbh)) break;
426 /* normalisation factor to conserve energy */
427 energy_ms = total_ms_energy(sr, sg, sb, n);
428 fac *= (energy_ss / energy_ms);
430 /* blend multiple scattering back in the light cache */
431 if (shade_type == MA_VOL_SHADE_SHADEDPLUSMULTIPLE) {
432 /* conserve energy - half single, half multiple */
439 for (z=1;z<=n[2];z++)
441 for (y=1;y<=n[1];y++)
443 for (x=1;x<=n[0];x++)
445 const int i = lc_to_ms_I(x, y ,z, n); //lc index
446 const int j = ms_I(x, y, z, n); //ms index
448 vp->data_r[i] = origf * vp->data_r[i] + fac * sr[j];
449 vp->data_g[i] = origf * vp->data_g[i] + fac * sg[j];
450 vp->data_b[i] = origf * vp->data_b[i] + fac * sb[j];
466 static void *vol_precache_part_test(void *data)
468 VolPrecachePart *pa = data;
470 printf("part number: %d \n", pa->num);
471 printf("done: %d \n", pa->done);
472 printf("x min: %d x max: %d \n", pa->minx, pa->maxx);
473 printf("y min: %d y max: %d \n", pa->miny, pa->maxy);
474 printf("z min: %d z max: %d \n", pa->minz, pa->maxz);
480 typedef struct VolPrecacheQueue {
485 /* Iterate over the 3d voxel grid, and fill the voxels with scattering information
487 * It's stored in memory as 3 big float grids next to each other, one for each RGB channel.
488 * I'm guessing the memory alignment may work out better this way for the purposes
489 * of doing linear interpolation, but I haven't actually tested this theory! :)
491 static void *vol_precache_part(void *data)
493 VolPrecacheQueue *queue = (VolPrecacheQueue*)data;
496 while ((pa = BLI_thread_queue_pop(queue->work))) {
497 ObjectInstanceRen *obi = pa->obi;
498 RayObject *tree = pa->tree;
499 ShadeInput *shi = pa->shi;
500 float scatter_col[3] = {0.f, 0.f, 0.f};
501 float co[3], cco[3], view[3];
505 if (pa->re->test_break && pa->re->test_break(pa->re->tbh))
512 for (z= pa->minz; z < pa->maxz; z++) {
513 co[2] = pa->bbmin[2] + (pa->voxel[2] * (z + 0.5f));
515 for (y= pa->miny; y < pa->maxy; y++) {
516 co[1] = pa->bbmin[1] + (pa->voxel[1] * (y + 0.5f));
518 for (x=pa->minx; x < pa->maxx; x++) {
519 co[0] = pa->bbmin[0] + (pa->voxel[0] * (x + 0.5f));
521 if (pa->re->test_break && pa->re->test_break(pa->re->tbh))
524 /* convert from world->camera space for shading */
525 mul_v3_m4v3(cco, pa->viewmat, co);
527 i= V_I(x, y, z, res);
529 // don't bother if the point is not inside the volume mesh
530 if (!point_inside_obi(tree, obi, cco)) {
531 obi->volume_precache->data_r[i] = -1.0f;
532 obi->volume_precache->data_g[i] = -1.0f;
533 obi->volume_precache->data_b[i] = -1.0f;
537 copy_v3_v3(view, cco);
539 vol_get_scattering(shi, scatter_col, cco, view);
541 obi->volume_precache->data_r[i] = scatter_col[0];
542 obi->volume_precache->data_g[i] = scatter_col[1];
543 obi->volume_precache->data_b[i] = scatter_col[2];
549 BLI_thread_queue_push(queue->done, pa);
556 static void precache_setup_shadeinput(Render *re, ObjectInstanceRen *obi, Material *ma, ShadeInput *shi)
558 memset(shi, 0, sizeof(ShadeInput));
563 memcpy(&shi->r, &shi->mat->r, 23*sizeof(float)); // note, keep this synced with render_types.h
564 shi->har= shi->mat->har;
570 static void precache_init_parts(Render *re, RayObject *tree, ShadeInput *shi, ObjectInstanceRen *obi, int totthread, int *parts)
572 VolumePrecache *vp = obi->volume_precache;
575 int sizex, sizey, sizez;
576 float bbmin[3], bbmax[3];
584 BLI_freelistN(&re->volume_precache_parts);
586 /* currently we just subdivide the box, number of threads per side */
587 parts[0] = parts[1] = parts[2] = totthread;
590 /* using boundbox in worldspace */
591 global_bounds_obi(re, obi, bbmin, bbmax);
592 sub_v3_v3v3(voxel, bbmax, bbmin);
594 voxel[0] /= (float)res[0];
595 voxel[1] /= (float)res[1];
596 voxel[2] /= (float)res[2];
598 for (x=0; x < parts[0]; x++) {
599 sizex = ceil(res[0] / (float)parts[0]);
602 maxx = (maxx>res[0])?res[0]:maxx;
604 for (y=0; y < parts[1]; y++) {
605 sizey = ceil(res[1] / (float)parts[1]);
608 maxy = (maxy>res[1])?res[1]:maxy;
610 for (z=0; z < parts[2]; z++) {
611 VolPrecachePart *pa= MEM_callocN(sizeof(VolPrecachePart), "new precache part");
613 sizez = ceil(res[2] / (float)parts[2]);
616 maxz = (maxz>res[2])?res[2]:maxz;
623 copy_m4_m4(pa->viewmat, re->viewmat);
625 copy_v3_v3(pa->bbmin, bbmin);
626 copy_v3_v3(pa->voxel, voxel);
627 VECCOPY(pa->res, res);
629 pa->minx = minx; pa->maxx = maxx;
630 pa->miny = miny; pa->maxy = maxy;
631 pa->minz = minz; pa->maxz = maxz;
634 BLI_addtail(&re->volume_precache_parts, pa);
642 /* calculate resolution from bounding box in world space */
643 static int precache_resolution(Render *re, VolumePrecache *vp, ObjectInstanceRen *obi, int res)
646 float bbmin[3], bbmax[3];
648 /* bound box in global space */
649 global_bounds_obi(re, obi, bbmin, bbmax);
650 sub_v3_v3v3(dim, bbmax, bbmin);
652 div = MAX3(dim[0], dim[1], dim[2]);
657 vp->res[0] = ceil(dim[0] * res);
658 vp->res[1] = ceil(dim[1] * res);
659 vp->res[2] = ceil(dim[2] * res);
661 if ((vp->res[0] < 1) || (vp->res[1] < 1) || (vp->res[2] < 1))
667 /* Precache a volume into a 3D voxel grid.
668 * The voxel grid is stored in the ObjectInstanceRen,
669 * in camera space, aligned with the ObjectRen's bounding box.
670 * Resolution is defined by the user.
672 static void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *obi, Material *ma)
679 VolPrecacheQueue queue;
680 int parts[3] = {1, 1, 1}, totparts;
683 int totthread = re->r.threads, thread;
685 double time, lasttime= PIL_check_seconds_timer();
689 /* create a raytree with just the faces of the instanced ObjectRen,
690 * used for checking if the cached point is inside or outside. */
691 tree = makeraytree_object(&R, obi);
694 vp = MEM_callocN(sizeof(VolumePrecache), "volume light cache");
695 obi->volume_precache = vp;
697 if (!precache_resolution(re, vp, obi, ma->vol.precache_resolution)) {
703 vp->data_r = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data red channel");
704 vp->data_g = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data green channel");
705 vp->data_b = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data blue channel");
706 if (vp->data_r==NULL || vp->data_g==NULL || vp->data_b==NULL) {
711 /* Need a shadeinput to calculate scattering */
712 precache_setup_shadeinput(re, obi, ma, &shi);
714 precache_init_parts(re, tree, &shi, obi, totthread, parts);
715 totparts = parts[0] * parts[1] * parts[2];
717 /* setup work and done queues */
718 queue.work = BLI_thread_queue_init();
719 queue.done = BLI_thread_queue_init();
720 BLI_thread_queue_nowait(queue.work);
722 for(pa= re->volume_precache_parts.first; pa; pa= pa->next)
723 BLI_thread_queue_push(queue.work, pa);
726 BLI_init_threads(&threads, vol_precache_part, totthread);
728 for(thread= 0; thread<totthread; thread++)
729 BLI_insert_thread(&threads, &queue);
731 /* loop waiting for work to be done */
732 while(counter < totparts) {
733 if(re->test_break && re->test_break(re->tbh))
736 if(BLI_thread_queue_pop_timeout(queue.done, 50))
739 time= PIL_check_seconds_timer();
740 if(time-lasttime>1.0) {
742 BLI_snprintf(str, sizeof(str), "Precaching volume: %d%%", (int)(100.0f * ((float)counter / (float)totparts)));
744 re->stats_draw(re->sdh, &re->i);
751 BLI_end_threads(&threads);
752 BLI_thread_queue_free(queue.work);
753 BLI_thread_queue_free(queue.done);
754 BLI_freelistN(&re->volume_precache_parts);
757 //TODO: makeraytree_object creates a tree and saves it on OBI, if we free this tree we should also clear other pointers to it
758 //RE_rayobject_free(tree);
762 if (ELEM(ma->vol.shade_type, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE))
764 /* this should be before the filtering */
765 multiple_scattering_diffusion(re, obi->volume_precache, ma);
768 lightcache_filter(obi->volume_precache);
771 static int using_lightcache(Material *ma)
773 return (((ma->vol.shadeflag & MA_VOL_PRECACHESHADING) && (ma->vol.shade_type == MA_VOL_SHADE_SHADED))
774 || (ELEM(ma->vol.shade_type, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE)));
777 /* loop through all objects (and their associated materials)
778 * marked for pre-caching in convertblender.c, and pre-cache them */
779 void volume_precache(Render *re)
781 ObjectInstanceRen *obi;
784 re->i.infostr= "Volume preprocessing";
785 re->stats_draw(re->sdh, &re->i);
787 for(vo= re->volumes.first; vo; vo= vo->next) {
788 if (using_lightcache(vo->ma)) {
789 for(obi= re->instancetable.first; obi; obi= obi->next) {
790 if (obi->obr == vo->obr) {
791 vol_precache_objectinstance_threads(re, obi, vo->ma);
793 if(re->test_break && re->test_break(re->tbh))
798 if(re->test_break && re->test_break(re->tbh))
804 re->stats_draw(re->sdh, &re->i);
807 void free_volume_precache(Render *re)
809 ObjectInstanceRen *obi;
811 for(obi= re->instancetable.first; obi; obi= obi->next) {
812 if (obi->volume_precache != NULL) {
813 MEM_freeN(obi->volume_precache->data_r);
814 MEM_freeN(obi->volume_precache->data_g);
815 MEM_freeN(obi->volume_precache->data_b);
816 MEM_freeN(obi->volume_precache->bbmin);
817 MEM_freeN(obi->volume_precache->bbmax);
818 MEM_freeN(obi->volume_precache);
819 obi->volume_precache = NULL;
823 BLI_freelistN(&re->volumes);
826 int point_inside_volume_objectinstance(Render *re, ObjectInstanceRen *obi, float *co)
831 tree = makeraytree_object(re, obi);
834 inside = point_inside_obi(tree, obi, co);
836 //TODO: makeraytree_object creates a tree and saves it on OBI, if we free this tree we should also clear other pointers to it
837 //RE_rayobject_free(tree);