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 *****
34 #include "MEM_guardedalloc.h"
36 #include "BLI_blenlib.h"
38 #include "BLI_threads.h"
39 #include "BLI_voxel.h"
43 #include "RE_shader_ext.h"
44 #include "RE_raytrace.h"
46 #include "DNA_material_types.h"
48 #include "render_types.h"
49 #include "rendercore.h"
50 #include "renderdatabase.h"
51 #include "volumetric.h"
52 #include "volume_precache.h"
54 #if defined( _MSC_VER ) && !defined( __cplusplus )
55 # define inline __inline
56 #endif // defined( _MSC_VER ) && !defined( __cplusplus )
58 #include "BKE_global.h"
60 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
61 /* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
62 /* only to be used here in this file, it's for speed */
63 extern struct Render R;
64 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
66 /* *** utility code to set up an individual raytree for objectinstance, for checking inside/outside *** */
68 /* Recursive test for intersections, from a point inside the mesh, to outside
69 * Number of intersections (depth) determine if a point is inside or outside the mesh */
70 int intersect_outside_volume(RayObject *tree, Isect *isect, float *offset, int limit, int depth)
72 if (limit == 0) return depth;
74 if (RE_rayobject_raycast(tree, isect)) {
76 isect->start[0] = isect->start[0] + isect->labda*isect->vec[0];
77 isect->start[1] = isect->start[1] + isect->labda*isect->vec[1];
78 isect->start[2] = isect->start[2] + isect->labda*isect->vec[2];
80 isect->labda = FLT_MAX;
81 isect->skip = RE_SKIP_VLR_NEIGHBOUR;
82 isect->orig.face= isect->hit.face;
83 isect->orig.ob= isect->hit.ob;
85 return intersect_outside_volume(tree, isect, offset, limit-1, depth+1);
91 /* Uses ray tracing to check if a point is inside or outside an ObjectInstanceRen */
92 int point_inside_obi(RayObject *tree, ObjectInstanceRen *obi, float *co)
95 float vec[3] = {0.0f,0.0f,1.0f};
96 int final_depth=0, depth=0, limit=20;
98 /* set up the isect */
99 memset(&isect, 0, sizeof(isect));
100 VECCOPY(isect.start, co);
101 VECCOPY(isect.vec, vec);
102 isect.mode= RE_RAY_MIRROR;
103 isect.last_hit= NULL;
106 isect.labda = FLT_MAX;
107 isect.orig.face= NULL;
108 isect.orig.ob = NULL;
110 final_depth = intersect_outside_volume(tree, &isect, vec, limit, depth);
112 /* even number of intersections: point is outside
113 * odd number: point is inside */
114 if (final_depth % 2 == 0) return 0;
118 /* find the bounding box of an objectinstance in global space */
119 void global_bounds_obi(Render *re, ObjectInstanceRen *obi, float *bbmin, float *bbmax)
121 ObjectRen *obr = obi->obr;
122 VolumePrecache *vp = obi->volume_precache;
127 if (vp->bbmin != NULL && vp->bbmax != NULL) {
128 copy_v3_v3(bbmin, vp->bbmin);
129 copy_v3_v3(bbmax, vp->bbmax);
133 vp->bbmin = MEM_callocN(sizeof(float)*3, "volume precache min boundbox corner");
134 vp->bbmax = MEM_callocN(sizeof(float)*3, "volume precache max boundbox corner");
136 INIT_MINMAX(bbmin, bbmax);
138 for(a=0; a<obr->totvert; a++) {
139 if((a & 255)==0) ver= obr->vertnodes[a>>8].vert;
142 copy_v3_v3(co, ver->co);
144 /* transformed object instance in camera space */
145 if(obi->flag & R_TRANSFORMED)
146 mul_m4_v3(obi->mat, co);
148 /* convert to global space */
149 mul_m4_v3(re->viewinv, co);
151 DO_MINMAX(co, vp->bbmin, vp->bbmax);
154 copy_v3_v3(bbmin, vp->bbmin);
155 copy_v3_v3(bbmax, vp->bbmax);
159 /* *** light cache filtering *** */
161 static float get_avg_surrounds(float *cache, int *res, int xx, int yy, int zz)
163 int x, y, z, x_, y_, z_;
167 for (z=-1; z <= 1; z++) {
169 if (z_ >= 0 && z_ <= res[2]-1) {
171 for (y=-1; y <= 1; y++) {
173 if (y_ >= 0 && y_ <= res[1]-1) {
175 for (x=-1; x <= 1; x++) {
177 if (x_ >= 0 && x_ <= res[0]-1) {
178 const int i= V_I(x_, y_, z_, res);
180 if (cache[i] > 0.0f) {
192 if (added > 0) tot /= added;
197 /* function to filter the edges of the light cache, where there was no volume originally.
198 * For each voxel which was originally external to the mesh, it finds the average values of
199 * the surrounding internal voxels and sets the original external voxel to that average amount.
200 * Works almost a bit like a 'dilate' filter */
201 static void lightcache_filter(VolumePrecache *vp)
205 for (z=0; z < vp->res[2]; z++) {
206 for (y=0; y < vp->res[1]; y++) {
207 for (x=0; x < vp->res[0]; x++) {
208 /* trigger for outside mesh */
209 const int i= V_I(x, y, z, vp->res);
211 if (vp->data_r[i] < -0.f)
212 vp->data_r[i] = get_avg_surrounds(vp->data_r, vp->res, x, y, z);
213 if (vp->data_g[i] < -0.f)
214 vp->data_g[i] = get_avg_surrounds(vp->data_g, vp->res, x, y, z);
215 if (vp->data_b[i] < -0.f)
216 vp->data_b[i] = get_avg_surrounds(vp->data_b, vp->res, x, y, z);
223 static void lightcache_filter2(VolumePrecache *vp)
226 float *new_r, *new_g, *new_b;
227 int field_size = vp->res[0]*vp->res[1]*vp->res[2]*sizeof(float);
229 new_r = MEM_mallocN(field_size, "temp buffer for light cache filter r channel");
230 new_g = MEM_mallocN(field_size, "temp buffer for light cache filter g channel");
231 new_b = MEM_mallocN(field_size, "temp buffer for light cache filter b channel");
233 memcpy(new_r, vp->data_r, field_size);
234 memcpy(new_g, vp->data_g, field_size);
235 memcpy(new_b, vp->data_b, field_size);
237 for (z=0; z < vp->res[2]; z++) {
238 for (y=0; y < vp->res[1]; y++) {
239 for (x=0; x < vp->res[0]; x++) {
240 /* trigger for outside mesh */
241 const int i= V_I(x, y, z, vp->res);
242 if (vp->data_r[i] < -0.f)
243 new_r[i] = get_avg_surrounds(vp->data_r, vp->res, x, y, z);
244 if (vp->data_g[i] < -0.f)
245 new_g[i] = get_avg_surrounds(vp->data_g, vp->res, x, y, z);
246 if (vp->data_b[i] < -0.f)
247 new_b[i] = get_avg_surrounds(vp->data_b, vp->res, x, y, z);
252 SWAP(float *, vp->data_r, new_r);
253 SWAP(float *, vp->data_g, new_g);
254 SWAP(float *, vp->data_b, new_b);
256 if (new_r) { MEM_freeN(new_r); new_r=NULL; }
257 if (new_g) { MEM_freeN(new_g); new_g=NULL; }
258 if (new_b) { MEM_freeN(new_b); new_b=NULL; }
262 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
264 /* different ordering to light cache */
265 return x*(n[1]+2)*(n[2]+2) + y*(n[2]+2) + z;
268 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
270 /* same ordering to light cache, with padding */
271 return z*(n[1]+2)*(n[0]+2) + y*(n[0]+2) + x;
274 static inline int lc_to_ms_I(int x, int y, int z, int *n)
276 /* converting light cache index to multiple scattering index */
277 return (x-1)*(n[1]*n[2]) + (y-1)*(n[2]) + z-1;
280 /* *** multiple scattering approximation *** */
282 /* get the total amount of light energy in the light cache. used to normalise after multiple scattering */
283 static float total_ss_energy(VolumePrecache *vp)
289 for (z=0; z < res[2]; z++) {
290 for (y=0; y < res[1]; y++) {
291 for (x=0; x < res[0]; x++) {
292 const int i=V_I(x, y, z, res);
294 if (vp->data_r[i] > 0.f) energy += vp->data_r[i];
295 if (vp->data_g[i] > 0.f) energy += vp->data_g[i];
296 if (vp->data_b[i] > 0.f) energy += vp->data_b[i];
304 static float total_ms_energy(float *sr, float *sg, float *sb, int *res)
309 for (z=1;z<=res[2];z++) {
310 for (y=1;y<=res[1];y++) {
311 for (x=1;x<=res[0];x++) {
312 const int i = ms_I(x,y,z,res);
314 if (sr[i] > 0.f) energy += sr[i];
315 if (sg[i] > 0.f) energy += sg[i];
316 if (sb[i] > 0.f) energy += sb[i];
324 static void ms_diffuse(float *x0, float *x, float diff, int *n) //n is the unpadded resolution
327 const float dt = VOL_MS_TIMESTEP;
328 const float a = dt*diff*n[0]*n[1]*n[2];
332 for (k=1; k<=n[2]; k++)
334 for (j=1; j<=n[1]; j++)
336 for (i=1; i<=n[0]; i++)
338 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)]+
339 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)]
347 void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Material *ma)
349 const float diff = ma->vol.ms_diff * 0.001f; /* compensate for scaling for a nicer UI range */
350 const int simframes = (int)(ma->vol.ms_spread * (float)MAX3(vp->res[0], vp->res[1], vp->res[2]));
351 const int shade_type = ma->vol.shade_type;
352 float fac = ma->vol.ms_intensity;
356 const int size = (n[0]+2)*(n[1]+2)*(n[2]+2);
357 double time, lasttime= PIL_check_seconds_timer();
360 float origf; /* factor for blending in original light cache */
361 float energy_ss, energy_ms;
363 float *sr0=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
364 float *sr=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
365 float *sg0=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
366 float *sg=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
367 float *sb0=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
368 float *sb=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
370 total = (float)(n[0]*n[1]*n[2]*simframes);
372 energy_ss = total_ss_energy(vp);
374 /* Scattering as diffusion pass */
375 for (m=0; m<simframes; m++)
378 for (z=1; z<=n[2]; z++)
380 for (y=1; y<=n[1]; y++)
382 for (x=1; x<=n[0]; x++)
384 const int i = lc_to_ms_I(x, y ,z, n); //lc index
385 const int j = ms_I(x, y, z, n); //ms index
387 time= PIL_check_seconds_timer();
389 if (vp->data_r[i] > 0.0f)
390 sr[j] += vp->data_r[i];
391 if (vp->data_g[i] > 0.0f)
392 sg[j] += vp->data_g[i];
393 if (vp->data_b[i] > 0.0f)
394 sb[j] += vp->data_b[i];
396 /* Displays progress every second */
397 if(time-lasttime>1.0f) {
399 sprintf(str, "Simulating multiple scattering: %d%%", (int)(100.0f * (c / total)));
401 re->stats_draw(re->sdh, &re->i);
408 SWAP(float *,sr,sr0);
409 SWAP(float *,sg,sg0);
410 SWAP(float *,sb,sb0);
412 /* main diffusion simulation */
413 ms_diffuse(sr0, sr, diff, n);
414 ms_diffuse(sg0, sg, diff, n);
415 ms_diffuse(sb0, sb, diff, n);
417 if (re->test_break(re->tbh)) break;
420 /* normalisation factor to conserve energy */
421 energy_ms = total_ms_energy(sr, sg, sb, n);
422 fac *= (energy_ss / energy_ms);
424 /* blend multiple scattering back in the light cache */
425 if (shade_type == MA_VOL_SHADE_SHADEDPLUSMULTIPLE) {
426 /* conserve energy - half single, half multiple */
433 for (z=1;z<=n[2];z++)
435 for (y=1;y<=n[1];y++)
437 for (x=1;x<=n[0];x++)
439 const int i = lc_to_ms_I(x, y ,z, n); //lc index
440 const int j = ms_I(x, y, z, n); //ms index
442 vp->data_r[i] = origf * vp->data_r[i] + fac * sr[j];
443 vp->data_g[i] = origf * vp->data_g[i] + fac * sg[j];
444 vp->data_b[i] = origf * vp->data_b[i] + fac * sb[j];
460 static void *vol_precache_part_test(void *data)
462 VolPrecachePart *pa = data;
464 printf("part number: %d \n", pa->num);
465 printf("done: %d \n", pa->done);
466 printf("x min: %d x max: %d \n", pa->minx, pa->maxx);
467 printf("y min: %d y max: %d \n", pa->miny, pa->maxy);
468 printf("z min: %d z max: %d \n", pa->minz, pa->maxz);
474 /* Iterate over the 3d voxel grid, and fill the voxels with scattering information
476 * It's stored in memory as 3 big float grids next to each other, one for each RGB channel.
477 * I'm guessing the memory alignment may work out better this way for the purposes
478 * of doing linear interpolation, but I haven't actually tested this theory! :)
480 static void *vol_precache_part(void *data)
482 VolPrecachePart *pa = (VolPrecachePart *)data;
483 ObjectInstanceRen *obi = pa->obi;
484 RayObject *tree = pa->tree;
485 ShadeInput *shi = pa->shi;
486 float scatter_col[3] = {0.f, 0.f, 0.f};
489 const int res[3]= {pa->res[0], pa->res[1], pa->res[2]};
491 for (z= pa->minz; z < pa->maxz; z++) {
492 co[2] = pa->bbmin[2] + (pa->voxel[2] * (z + 0.5f));
494 for (y= pa->miny; y < pa->maxy; y++) {
495 co[1] = pa->bbmin[1] + (pa->voxel[1] * (y + 0.5f));
497 for (x=pa->minx; x < pa->maxx; x++) {
498 co[0] = pa->bbmin[0] + (pa->voxel[0] * (x + 0.5f));
500 /* convert from world->camera space for shading */
501 mul_v3_m4v3(cco, pa->viewmat, co);
503 i= V_I(x, y, z, res);
505 // don't bother if the point is not inside the volume mesh
506 if (!point_inside_obi(tree, obi, cco)) {
507 obi->volume_precache->data_r[i] = -1.0f;
508 obi->volume_precache->data_g[i] = -1.0f;
509 obi->volume_precache->data_b[i] = -1.0f;
513 /* this view coordinate is very wrong! */
514 copy_v3_v3(shi->view, cco);
515 normalize_v3(shi->view);
516 vol_get_scattering(shi, scatter_col, cco);
518 obi->volume_precache->data_r[i] = scatter_col[0];
519 obi->volume_precache->data_g[i] = scatter_col[1];
520 obi->volume_precache->data_b[i] = scatter_col[2];
532 static void precache_setup_shadeinput(Render *re, ObjectInstanceRen *obi, Material *ma, ShadeInput *shi)
534 memset(shi, 0, sizeof(ShadeInput));
539 memcpy(&shi->r, &shi->mat->r, 23*sizeof(float)); // note, keep this synced with render_types.h
540 shi->har= shi->mat->har;
546 static void precache_init_parts(Render *re, RayObject *tree, ShadeInput *shi, ObjectInstanceRen *obi, int totthread, int *parts)
548 VolumePrecache *vp = obi->volume_precache;
551 int sizex, sizey, sizez;
552 float bbmin[3], bbmax[3];
560 BLI_freelistN(&re->volume_precache_parts);
562 /* currently we just subdivide the box, number of threads per side */
563 parts[0] = parts[1] = parts[2] = totthread;
566 /* using boundbox in worldspace */
567 global_bounds_obi(re, obi, bbmin, bbmax);
568 sub_v3_v3v3(voxel, bbmax, bbmin);
570 voxel[0] /= (float)res[0];
571 voxel[1] /= (float)res[1];
572 voxel[2] /= (float)res[2];
574 for (x=0; x < parts[0]; x++) {
575 sizex = ceil(res[0] / (float)parts[0]);
578 maxx = (maxx>res[0])?res[0]:maxx;
580 for (y=0; y < parts[1]; y++) {
581 sizey = ceil(res[1] / (float)parts[1]);
584 maxy = (maxy>res[1])?res[1]:maxy;
586 for (z=0; z < parts[2]; z++) {
587 VolPrecachePart *pa= MEM_callocN(sizeof(VolPrecachePart), "new precache part");
589 sizez = ceil(res[2] / (float)parts[2]);
592 maxz = (maxz>res[2])?res[2]:maxz;
601 copy_m4_m4(pa->viewmat, re->viewmat);
603 copy_v3_v3(pa->bbmin, bbmin);
604 copy_v3_v3(pa->voxel, voxel);
605 VECCOPY(pa->res, res);
607 pa->minx = minx; pa->maxx = maxx;
608 pa->miny = miny; pa->maxy = maxy;
609 pa->minz = minz; pa->maxz = maxz;
612 BLI_addtail(&re->volume_precache_parts, pa);
620 static VolPrecachePart *precache_get_new_part(Render *re)
622 VolPrecachePart *pa, *nextpa=NULL;
624 for (pa = re->volume_precache_parts.first; pa; pa=pa->next)
626 if (pa->done==0 && pa->working==0) {
635 /* calculate resolution from bounding box in world space */
636 static int precache_resolution(Render *re, VolumePrecache *vp, ObjectInstanceRen *obi, int res)
639 float bbmin[3], bbmax[3];
641 /* bound box in global space */
642 global_bounds_obi(re, obi, bbmin, bbmax);
643 sub_v3_v3v3(dim, bbmax, bbmin);
645 div = MAX3(dim[0], dim[1], dim[2]);
650 vp->res[0] = ceil(dim[0] * res);
651 vp->res[1] = ceil(dim[1] * res);
652 vp->res[2] = ceil(dim[2] * res);
654 if ((vp->res[0] < 1) || (vp->res[1] < 1) || (vp->res[2] < 1))
660 /* Precache a volume into a 3D voxel grid.
661 * The voxel grid is stored in the ObjectInstanceRen,
662 * in camera space, aligned with the ObjectRen's bounding box.
663 * Resolution is defined by the user.
665 void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *obi, Material *ma)
668 VolPrecachePart *nextpa, *pa;
672 int parts[3] = {1, 1, 1}, totparts;
674 int caching=1, counter=0;
675 int totthread = re->r.threads;
677 double time, lasttime= PIL_check_seconds_timer();
681 /* create a raytree with just the faces of the instanced ObjectRen,
682 * used for checking if the cached point is inside or outside. */
683 tree = makeraytree_object(&R, obi);
686 vp = MEM_callocN(sizeof(VolumePrecache), "volume light cache");
687 obi->volume_precache = vp;
689 if (!precache_resolution(re, vp, obi, ma->vol.precache_resolution)) {
695 vp->data_r = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data red channel");
696 vp->data_g = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data green channel");
697 vp->data_b = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data blue channel");
698 if (vp->data_r==0 || vp->data_g==0 || vp->data_b==0) {
703 //obi->volume_precache = vp;
705 /* Need a shadeinput to calculate scattering */
706 precache_setup_shadeinput(re, obi, ma, &shi);
708 precache_init_parts(re, tree, &shi, obi, totthread, parts);
709 totparts = parts[0] * parts[1] * parts[2];
711 BLI_init_threads(&threads, vol_precache_part, totthread);
715 if(BLI_available_threads(&threads) && !(re->test_break(re->tbh))) {
716 nextpa = precache_get_new_part(re);
719 BLI_insert_thread(&threads, nextpa);
722 else PIL_sleep_ms(50);
726 for(pa= re->volume_precache_parts.first; pa; pa= pa->next) {
730 BLI_remove_thread(&threads, pa);
735 if (re->test_break(re->tbh) && BLI_available_threads(&threads)==totthread)
738 time= PIL_check_seconds_timer();
739 if(time-lasttime>1.0f) {
741 sprintf(str, "Precaching volume: %d%%", (int)(100.0f * ((float)counter / (float)totparts)));
743 re->stats_draw(re->sdh, &re->i);
749 BLI_end_threads(&threads);
750 BLI_freelistN(&re->volume_precache_parts);
753 //TODO: makeraytree_object creates a tree and saves it on OBI, if we free this tree we should also clear other pointers to it
754 //RE_rayobject_free(tree);
758 if (ELEM(ma->vol.shade_type, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE))
760 /* this should be before the filtering */
761 multiple_scattering_diffusion(re, obi->volume_precache, ma);
764 lightcache_filter(obi->volume_precache);
767 static int using_lightcache(Material *ma)
769 return (((ma->vol.shadeflag & MA_VOL_PRECACHESHADING) && (ma->vol.shade_type == MA_VOL_SHADE_SHADED))
770 || (ELEM(ma->vol.shade_type, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE)));
773 /* loop through all objects (and their associated materials)
774 * marked for pre-caching in convertblender.c, and pre-cache them */
775 void volume_precache(Render *re)
777 ObjectInstanceRen *obi;
780 for(vo= re->volumes.first; vo; vo= vo->next) {
781 if (using_lightcache(vo->ma)) {
782 for(obi= re->instancetable.first; obi; obi= obi->next) {
783 if (obi->obr == vo->obr) {
784 vol_precache_objectinstance_threads(re, obi, vo->ma);
791 re->stats_draw(re->sdh, &re->i);
794 void free_volume_precache(Render *re)
796 ObjectInstanceRen *obi;
798 for(obi= re->instancetable.first; obi; obi= obi->next) {
799 if (obi->volume_precache != NULL) {
800 MEM_freeN(obi->volume_precache->data_r);
801 MEM_freeN(obi->volume_precache->data_g);
802 MEM_freeN(obi->volume_precache->data_b);
803 MEM_freeN(obi->volume_precache->bbmin);
804 MEM_freeN(obi->volume_precache->bbmax);
805 MEM_freeN(obi->volume_precache);
806 obi->volume_precache = NULL;
810 BLI_freelistN(&re->volumes);
813 int point_inside_volume_objectinstance(Render *re, ObjectInstanceRen *obi, float *co)
818 tree = makeraytree_object(re, obi);
821 inside = point_inside_obi(tree, obi, co);
823 //TODO: makeraytree_object creates a tree and saves it on OBI, if we free this tree we should also clear other pointers to it
824 //RE_rayobject_free(tree);