[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17110] branches/sim_physics/source/ blender: Another WIP commit, nothing to see yet.
Matt Ebb
matt at mke3.net
Sun Oct 19 10:25:10 CEST 2008
Revision: 17110
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17110
Author: broken
Date: 2008-10-19 10:25:10 +0200 (Sun, 19 Oct 2008)
Log Message:
-----------
Another WIP commit, nothing to see yet.
Modified Paths:
--------------
branches/sim_physics/source/blender/makesdna/DNA_material_types.h
branches/sim_physics/source/blender/render/intern/source/convertblender.c
branches/sim_physics/source/blender/render/intern/source/pointdensity.c
branches/sim_physics/source/blender/render/intern/source/volumetric.c
branches/sim_physics/source/blender/src/buttons_shading.c
Modified: branches/sim_physics/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_material_types.h 2008-10-19 06:12:11 UTC (rev 17109)
+++ branches/sim_physics/source/blender/makesdna/DNA_material_types.h 2008-10-19 08:25:10 UTC (rev 17110)
@@ -63,10 +63,11 @@
/* end synced with render_types.h */
short material_type; /* solid, halo, volumetric */
- short pad5[2];
+ short pad5;
/* volumetrics */
short vol_stepsize_type;
+ short vol_precache_resolution;
float vol_stepsize, vol_shade_stepsize;
float vol_density_scale;
float vol_absorption, vol_scattering;
Modified: branches/sim_physics/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/convertblender.c 2008-10-19 06:12:11 UTC (rev 17109)
+++ branches/sim_physics/source/blender/render/intern/source/convertblender.c 2008-10-19 08:25:10 UTC (rev 17110)
@@ -3093,7 +3093,7 @@
if(ma->mode & MA_RADIO)
do_autosmooth= 1;
- if (ma->vol_shadeflag & MA_VOL_PRECACHESHADING) {
+ if ((ma->material_type == MA_VOLUME) && (ma->vol_shadeflag & MA_VOL_PRECACHESHADING)) {
add_vol_precache(re, obr, ma);
}
}
@@ -4429,6 +4429,8 @@
BLI_freelistN(&re->lampren);
BLI_freelistN(&re->lights);
+
+ free_volume_precache(re);
free_renderdata_tables(re);
@@ -4452,7 +4454,6 @@
end_render_materials();
free_pointdensities(re);
- free_volume_precache(re);
if(re->wrld.aosphere) {
MEM_freeN(re->wrld.aosphere);
@@ -4908,9 +4909,6 @@
/* point density texture */
if(!re->test_break())
make_pointdensities(re);
-
- if(!re->test_break())
- volume_precache(re);
}
if(!re->test_break())
@@ -4927,6 +4925,9 @@
if((re->r.mode & R_SSS) && !re->test_break())
if(re->r.renderer==R_INTERN)
make_sss_tree(re);
+
+ if(!re->test_break())
+ volume_precache(re);
}
if(re->test_break())
Modified: branches/sim_physics/source/blender/render/intern/source/pointdensity.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/pointdensity.c 2008-10-19 06:12:11 UTC (rev 17109)
+++ branches/sim_physics/source/blender/render/intern/source/pointdensity.c 2008-10-19 08:25:10 UTC (rev 17110)
@@ -227,6 +227,9 @@
cache_pointdensity(re, tex);
}
}
+
+ re->i.infostr= NULL;
+ re->stats_draw(&re->i);
}
void free_pointdensities(Render *re)
Modified: branches/sim_physics/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/volumetric.c 2008-10-19 06:12:11 UTC (rev 17109)
+++ branches/sim_physics/source/blender/render/intern/source/volumetric.c 2008-10-19 08:25:10 UTC (rev 17110)
@@ -21,7 +21,7 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): Farsthary (Raul FHernandez), Matt Ebb.
+ * Contributor(s): Matt Ebb, Raul Hernandez.
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -38,6 +38,8 @@
#include "BLI_rand.h"
#include "BLI_kdtree.h"
+#include "PIL_time.h"
+
#include "RE_shader_ext.h"
#include "RE_raytrace.h"
@@ -59,6 +61,7 @@
extern struct Render R;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+#define PRECACHE_RES 5
static int vol_backface_intersect_check(Isect *is, int ob, RayFace *face)
{
@@ -365,7 +368,7 @@
}
/* single scattering only for now */
-void vol_get_scattering(ShadeInput *shi, float *scatter, float *co, float stepsize, float density)
+void vol_get_scattering(Render *re, ShadeInput *shi, float *scatter, float *co, float stepsize, float density)
{
GroupObject *go;
ListBase *lights;
@@ -378,13 +381,14 @@
float lacol[3] = {0.f, 0.f, 0.f};
lar= go->lampren;
- if (lar==NULL) continue;
+ if (lar) {
- vol_shade_one_lamp(shi, co, lar, lacol, stepsize, density);
+ vol_shade_one_lamp(shi, co, lar, lacol, stepsize, density);
- VecMulf(lacol, density);
+ VecMulf(lacol, density);
- VecAddf(col, col, lacol);
+ VecAddf(col, col, lacol);
+ }
}
VECCOPY(scatter, col);
@@ -397,7 +401,7 @@
float stepsize = vol_get_stepsize(shi, STEPSIZE_VIEW);
int nsteps;
float vec[3], stepvec[3] = {0.0, 0.0, 0.0};
- float tau[3], step_emit[3], step_scatter[3] = {0.0, 0.0, 0.0};
+ float tau[3], emit_col[3], scatter_col[3] = {0.0, 0.0, 0.0};
int s;
float step_sta[3], step_end[3], step_mid[3];
float alpha;
@@ -425,27 +429,7 @@
/* get radiance from all points along the ray due to participating media */
for (s = 0; s < nsteps; s++) {
- if (shi->mat->vol_shadeflag & MA_VOL_PRECACHESHADING) {
- int res = 10;
- int x,y,z;
-
- step_mid[0] = step_sta[0] + (stepvec[0] * 0.5);
- step_mid[1] = step_sta[1] + (stepvec[1] * 0.5);
- step_mid[2] = step_sta[2] + (stepvec[2] * 0.5);
-
- //CLAMP(step_mid[0], 0.0f, 1.0f);
- //CLAMP(step_mid[1], 0.0f, 1.0f);
- //CLAMP(step_mid[2], 0.0f, 1.0f);
-
- MTC_Mat4MulVecfl(R.viewinv, step_mid);
-
- x = (int)step_mid[0] * res;
- y = (int)step_mid[1] * res;
- z = (int)step_mid[2] * res;
-
- density = shi->obi->volume_precache[x*res + y*res + z*res];
- }
- else if (s > 0) density = vol_get_density(shi, step_sta);
+ if (s > 0) density = vol_get_density(shi, step_sta);
/* there's only any use in shading here
* if there's actually some density to shade! */
@@ -462,10 +446,26 @@
step_mid[2] = step_sta[2] + (stepvec[2] * 0.5);
/* incoming light via emission or scattering (additive) */
- vol_get_emission(shi, step_emit, step_mid, density);
- vol_get_scattering(shi, step_scatter, step_mid, stepsize, density);
+ vol_get_emission(shi, emit_col, step_mid, density);
+ if ((shi->mat->vol_shadeflag & MA_VOL_PRECACHESHADING) && shi->obi->volume_precache) {
+ const int res = shi->mat->vol_precache_resolution;
+ int x,y,z;
+ float bbmin[3], bbmax[3], dim[3];
+
+ VECCOPY(bbmin, shi->obi->obr->boundbox[0]);
+ VECCOPY(bbmax, shi->obi->obr->boundbox[1]);
+ VecSubf(dim, bbmax, bbmin);
+
+ x = (int)(((step_mid[0] - bbmin[0]) / dim[0]) * res);
+ y = (int)(((step_mid[1] - bbmin[1]) / dim[1]) * res);
+ z = (int)(((step_mid[2] - bbmin[2]) / dim[2]) * res);
+
+ scatter_col[0] = scatter_col[1] = scatter_col[2] = shi->obi->volume_precache[x*res*res + y*res + z];
+ }
+ else
+ vol_get_scattering(&R, shi, scatter_col, step_mid, stepsize, density);
- VecAddf(d_radiance, step_emit, step_scatter);
+ VecAddf(d_radiance, emit_col, scatter_col);
/* Lv += Tr * (Lve() + Ld) */
VecMulVecf(d_radiance, tr, d_radiance);
@@ -681,17 +681,23 @@
}
-void vol_precache_objectinstance(Render *re, ObjectInstanceRen *obi, Material *ma)
+void vol_precache_objectinstance(Render *re, ObjectInstanceRen *obi, Material *ma, float *bbmin, float *bbmax)
{
int x, y, z;
- int res = 10;
- float co[3];
+
+ float co[3], voxel[3], scatter_col[3];
ShadeInput shi;
- int foundma=0;
float density;
+ float stepsize;
+
float resf;
- int i;
+ int res_2;
+ float res_3;
+ float i = 1.0f;
+ double lasttime= PIL_check_seconds_timer();
+ const int res = ma->vol_precache_resolution;
+
memset(&shi, 0, sizeof(ShadeInput));
shi.depth= 1;
shi.mask= 1;
@@ -699,28 +705,49 @@
shi.vlr = NULL;
memcpy(&shi.r, &shi.mat->r, 23*sizeof(float)); // note, keep this synced with render_types.h
shi.har= shi.mat->har;
-
shi.obi= obi;
shi.obr= obi->obr;
+
+ stepsize = vol_get_stepsize(&shi, STEPSIZE_VIEW);
resf = (float) res;
+ res_2 = res*res;
+ res_3 = res*res*res;
+ VecSubf(voxel, bbmax, bbmin);
+ VecMulf(voxel, 1.0f/res);
+
obi->volume_precache = MEM_mallocN(sizeof(float)*res*res*res, "volume light cache");
for (x=0; x < res; x++) {
- co[0] = (float)x / resf;
+ co[0] = bbmin[0] + (voxel[0] * x);
for (y=0; y < res; y++) {
- co[1] = (float)y / resf;
+ co[1] = bbmin[1] + (voxel[1] * y);
for (z=0; z < res; z++) {
- co[2] = (float)z / resf;
+ double time= PIL_check_seconds_timer();
+
+ co[2] = bbmin[2] + (voxel[2] * z);
density = vol_get_density(&shi, co);
+ vol_get_scattering(re, &shi, scatter_col, co, stepsize, density);
- obi->volume_precache[x*res + y*res + z*res] = density;
+ obi->volume_precache[x*res_2 + y*res + z] = (scatter_col[0] + scatter_col[1] + scatter_col[2]) / 3.0f;
- printf("vol_light_cache[%d][%d][%d] = %f \n", x, y, z, obi->volume_precache[x*res + y*res + z*res]);
+ /* display progress every second */
+ if(re->test_break())
+ return;
+ if(time-lasttime>1.0f) {
+ char str[64];
+ sprintf(str, "Precaching volume: %d%%", (int)(100.0f * (i / res_3)));
+ re->i.infostr= str;
+ re->stats_draw(&re->i);
+ re->i.infostr= NULL;
+ lasttime= time;
+ }
+
+ i++;
}
}
}
@@ -730,16 +757,21 @@
{
ObjectInstanceRen *obi;
VolPrecache *vp;
+ int i=1;
printf("Precaching %d volumes... \n", BLI_countlist(&re->vol_precache_obs));
for(vp= re->vol_precache_obs.first; vp; vp= vp->next) {
for(obi= re->instancetable.first; obi; obi= obi->next) {
- if (obi->obr == vp->obr)
- printf("precaching object: %s with material: %s \n", vp->obr->ob->id.name+2, vp->ma->id.name+2);
- vol_precache_objectinstance(re, obi, vp->ma);
+ if (obi->obr == vp->obr) {
+ printf("Precaching Object: %s with Material: %s \n", vp->obr->ob->id.name+2, vp->ma->id.name+2);
+ vol_precache_objectinstance(re, obi, vp->ma, obi->obr->boundbox[0], obi->obr->boundbox[1]);
+ }
}
}
+
+ re->i.infostr= NULL;
+ re->stats_draw(&re->i);
}
void free_volume_precache(Render *re)
@@ -747,8 +779,10 @@
ObjectInstanceRen *obi;
for(obi= re->instancetable.first; obi; obi= obi->next) {
- if (obi->volume_precache)
+ if (obi->volume_precache) {
MEM_freeN(obi->volume_precache);
+ printf("freed volume precache of object: %s \n", obi->obr->ob->id.name+2);
+ }
}
BLI_freelistN(&re->vol_precache_obs);
Modified: branches/sim_physics/source/blender/src/buttons_shading.c
===================================================================
--- branches/sim_physics/source/blender/src/buttons_shading.c 2008-10-19 06:12:11 UTC (rev 17109)
+++ branches/sim_physics/source/blender/src/buttons_shading.c 2008-10-19 08:25:10 UTC (rev 17110)
@@ -4377,6 +4377,8 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list