[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17817] branches/sim_physics/source/ blender: * Volume Rendering: Voxel data

Matt Ebb matt at mke3.net
Sat Dec 13 06:41:37 CET 2008


Revision: 17817
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17817
Author:   broken
Date:     2008-12-13 06:41:34 +0100 (Sat, 13 Dec 2008)

Log Message:
-----------
* Volume Rendering: Voxel data

This commit introduces a new texture ('Voxel Data'), used to load up saved voxel 
data sets for rendering, contributed by Rau?\204?\129l 'farsthary' Ferna?\204?\129ndez Herna?\204?\129ndez 
with some additional tweaks. Thanks, Rau?\204?\129l!

The texture works similar to the existing point density texture, currently it 
only provides intensity information, which can then be mapped (for example) to 
density in a volume material. This is an early version, intended to read the 
voxel format saved by Rau?\204?\129l's command line simulators, in future revisions 
there's potential for making a more full-featured 'Blender voxel file format', 
and also for supporting other formats too.

Note: Due to some subtleties in Rau?\204?\129l's existing released simulators, in  order 
to load them correctly the voxel data texture, you'll need to raise the 
'resolution' value by 2. So if you baked out the simulation at resolution 50, 
enter 52 for the resolution in the texture panel. This can possibly be fixed in 
the simulator later on.

Right now, the way the texture is mapped is just in the space 0,0,0 <-> 1,1,1 
and it can appear rotated 90 degrees incorrectly. This will be tackled, for now, 
probably the easiest way to map it is with and empty, using Map Input -> Object.

Smoke test: http://www.vimeo.com/2449270

One more note, trilinear interpolation seems a bit slow at the moment, we'll 
look into this.

For curiosity, while testing/debugging this, I made a script that exports a mesh 
to voxel data. Here's a test of grogan (www.kajimba.com) converted to voxels, 
rendered as a volume: http://www.vimeo.com/2512028

The script is available here: http://mke3.net/projects/bpython/export_object_voxeldata.py

* Another smaller thing, brought back early ray termination (was disabled 
previously for debugging) and made it user configurable. It now appears as a new 
value in the volume material: 'Depth Cutoff'. For some background info on what 
this does, check:
http://farsthary.wordpress.com/2008/12/11/cutting-down-render-times/

* Also some disabled work-in-progess code for light cache

Modified Paths:
--------------
    branches/sim_physics/source/blender/blenkernel/BKE_texture.h
    branches/sim_physics/source/blender/blenkernel/intern/texture.c
    branches/sim_physics/source/blender/blenloader/intern/readfile.c
    branches/sim_physics/source/blender/blenloader/intern/writefile.c
    branches/sim_physics/source/blender/include/butspace.h
    branches/sim_physics/source/blender/makesdna/DNA_material_types.h
    branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
    branches/sim_physics/source/blender/render/intern/include/render_types.h
    branches/sim_physics/source/blender/render/intern/include/volume_precache.h
    branches/sim_physics/source/blender/render/intern/source/convertblender.c
    branches/sim_physics/source/blender/render/intern/source/texture.c
    branches/sim_physics/source/blender/render/intern/source/volume_precache.c
    branches/sim_physics/source/blender/render/intern/source/volumetric.c
    branches/sim_physics/source/blender/src/butspace.c
    branches/sim_physics/source/blender/src/buttons_shading.c

Modified: branches/sim_physics/source/blender/blenkernel/BKE_texture.h
===================================================================
--- branches/sim_physics/source/blender/blenkernel/BKE_texture.h	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/blenkernel/BKE_texture.h	2008-12-13 05:41:34 UTC (rev 17817)
@@ -40,6 +40,7 @@
 struct TexMapping;
 struct EnvMap;
 struct PointDensity;
+struct VoxelData;
 
 /*  in ColorBand struct */
 #define MAXCOLORBAND 32
@@ -80,6 +81,11 @@
 struct PointDensity *BKE_add_pointdensity(void);
 struct PointDensity *BKE_copy_pointdensity(struct PointDensity *pd);
 
+void BKE_free_voxeldatadata(struct VoxelData *vd);
+void BKE_free_voxeldata(struct VoxelData *vd);
+struct VoxelData *BKE_add_voxeldata(void);
+struct VoxelData *BKE_copy_voxeldata(struct VoxelData *vd);
+
 int     BKE_texture_dependsOnTime(const struct Tex *texture);
 
 #endif

Modified: branches/sim_physics/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/sim_physics/source/blender/blenkernel/intern/texture.c	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/blenkernel/intern/texture.c	2008-12-13 05:41:34 UTC (rev 17817)
@@ -420,6 +420,7 @@
 	if(tex->coba) MEM_freeN(tex->coba);
 	if(tex->env) BKE_free_envmap(tex->env);
 	if(tex->pd) BKE_free_pointdensity(tex->pd);
+	if(tex->vd) BKE_free_voxeldata(tex->vd);
 	BKE_previewimg_free(&tex->preview);
 	BKE_icon_delete((struct ID*)tex);
 	tex->id.icon_id = 0;
@@ -490,6 +491,11 @@
 		tex->pd->radius = 0.3f;
 		tex->pd->falloff_type = TEX_PD_FALLOFF_STD;
 	}
+	
+	if (tex->vd) {
+		tex->vd->resolX=50;
+		tex->vd->interp_type=0;
+	}
 
 	pit = tex->plugin;
 	if (pit) {
@@ -588,6 +594,7 @@
 	if(texn->coba) texn->coba= MEM_dupallocN(texn->coba);
 	if(texn->env) texn->env= BKE_copy_envmap(texn->env);
 	if(texn->pd) texn->pd= BKE_copy_pointdensity(texn->pd);
+	if(texn->vd) texn->vd=BKE_copy_voxeldata(texn->vd);
 	
 	if(tex->preview) texn->preview = BKE_previewimg_copy(tex->preview);
 
@@ -945,6 +952,48 @@
 	MEM_freeN(pd);
 }
 
+
+void BKE_free_voxeldatadata(struct VoxelData *vd)
+{
+	if (vd->dataset) {
+		MEM_freeN(vd->dataset);
+		vd->dataset = NULL;
+	}
+
+}
+ 
+void BKE_free_voxeldata(struct VoxelData *vd)
+{
+	BKE_free_voxeldatadata(vd);
+	MEM_freeN(vd);
+}
+ 
+struct VoxelData *BKE_add_voxeldata(void)
+{
+	VoxelData *vd;
+
+	vd= MEM_callocN(sizeof(struct VoxelData), "voxeldata");
+	vd->dataset = NULL;
+	vd->resolX = 1;
+	vd->resolY = 1;
+	vd->resolZ = 1;
+	vd->interp_type= TEX_VD_NEARESTNEIGHBOR;
+	vd->int_multiplier = 1.0;
+	
+	return vd;
+ }
+ 
+struct VoxelData *BKE_copy_voxeldata(struct VoxelData *vd)
+{
+	VoxelData *vdn;
+
+	vdn= MEM_dupallocN(vd);	
+	vdn->dataset = NULL;
+
+	return vdn;
+}
+
+
 /* ------------------------------------------------------------------------- */
 int BKE_texture_dependsOnTime(const struct Tex *texture)
 {

Modified: branches/sim_physics/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-12-13 05:41:34 UTC (rev 17817)
@@ -2535,6 +2535,11 @@
 		tex->pd->coba= newdataadr(fd, tex->pd->coba);
 	}
 	
+	tex->vd= newdataadr(fd, tex->vd);
+	if(tex->vd) {
+		tex->vd->dataset = NULL;
+	}
+	
 	tex->nodetree= newdataadr(fd, tex->nodetree);
 	if(tex->nodetree)
 		direct_link_nodetree(fd, tex->nodetree);
@@ -7939,6 +7944,8 @@
 				ma->vol_density_scale = 1.0f;
 			if (ma->vol_precache_resolution == 0)
 				ma->vol_precache_resolution = 50;
+			if (ma->vol_depth_cutoff < 0.0001)
+				ma->vol_depth_cutoff = 0.05;
 		}
 		
 		for(tex=main->tex.first; tex; tex= tex->id.next) {
@@ -7956,6 +7963,17 @@
 				tex->pd->coba = add_colorband(1);
 				tex->pd->speed_scale = 1.0f;
 			}
+			
+			if (tex->vd == NULL) {
+				tex->vd = BKE_add_voxeldata();
+			} else if (tex->vd->resolX == 0) {
+				tex->vd->dataset = NULL;
+				tex->vd->resolX = 1;
+				tex->vd->resolY = 1;
+				tex->vd->resolZ = 1;
+				tex->vd->interp_type= TEX_VD_NEARESTNEIGHBOR;
+				tex->vd->int_multiplier = 1.0;
+			}
 		}
 		
 	}

Modified: branches/sim_physics/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/sim_physics/source/blender/blenloader/intern/writefile.c	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/blenloader/intern/writefile.c	2008-12-13 05:41:34 UTC (rev 17817)
@@ -1339,6 +1339,7 @@
 				writestruct(wd, DATA, "PointDensity", 1, tex->pd);
 				if(tex->pd->coba) writestruct(wd, DATA, "ColorBand", 1, tex->pd->coba);
 			}
+			if(tex->vd) writestruct(wd, DATA, "VoxelData", 1, tex->vd);
 			
 			/* nodetree is integral part of texture, no libdata */
 			if(tex->nodetree) {

Modified: branches/sim_physics/source/blender/include/butspace.h
===================================================================
--- branches/sim_physics/source/blender/include/butspace.h	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/include/butspace.h	2008-12-13 05:41:34 UTC (rev 17817)
@@ -260,7 +260,9 @@
 #define B_ENV_FREE_ALL	1357
 #define B_TEX_USENODES		1358
 
+#define B_VOXELDATA_LOAD	1359
 
+
 /* **************** animbuts = object buttons ******* */
 #define B_ANIMBUTS		1500
 

Modified: branches/sim_physics/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-12-13 05:41:34 UTC (rev 17817)
@@ -69,6 +69,8 @@
 	short vol_stepsize_type;
 	short vol_precache_resolution;
 	float vol_stepsize, vol_shade_stepsize;
+	float vol_depth_cutoff;
+	float vpad;
 	float vol_density_scale;
 	float vol_absorption, vol_scattering;
 	float vol_absorption_col[3];

Modified: branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-12-13 05:41:34 UTC (rev 17817)
@@ -154,7 +154,7 @@
 	short noise_depth;
 	short noise_influence;
 	short noise_basis;
-	short pdpad3[3];
+    short pdpad3[3];
 	float noise_fac;
 	
 	float speed_scale;
@@ -162,6 +162,18 @@
 	
 } PointDensity;
 
+typedef struct VoxelData {
+	int resolX, resolY, resolZ;
+	int interp_type;
+
+	float int_multiplier;
+	float vxpad;
+	
+	char source_path[240];
+	float *dataset;
+ 
+} VoxelData;
+
 typedef struct Tex {
 	ID id;
 	
@@ -209,6 +221,7 @@
 	struct EnvMap *env;
 	struct PreviewImage * preview;
 	struct PointDensity *pd;
+	struct VoxelData *vd;
 	
 	char use_nodes;
 	char pad[7];
@@ -250,6 +263,7 @@
 #define TEX_DISTNOISE	13
 /* predicting ocean texture for 14 */
 #define TEX_POINTDENSITY	15
+#define TEX_VOXELDATA		16
 
 /* musgrave stype */
 #define TEX_MFRACTAL		0
@@ -465,5 +479,13 @@
 #define POINT_DATA_VEL		1
 #define POINT_DATA_LIFE		2
 
+/******************** Voxel Data *****************************/ 
+#define TEX_VD_CUBIC              0
+#define TEX_VD_PARALLELOGRAM      1
+ 
+#define TEX_VD_NEARESTNEIGHBOR		0
+#define TEX_VD_LINEAR			1
+#define TEX_VD_TRICUBIC				2
+
 #endif
 

Modified: branches/sim_physics/source/blender/render/intern/include/render_types.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/render_types.h	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/render/intern/include/render_types.h	2008-12-13 05:41:34 UTC (rev 17817)
@@ -203,6 +203,8 @@
 	struct Object *excludeob;
 	
 	ListBase vol_precache_obs;
+	ListBase render_volumes_inside;
+	ListBase volumes;
 
 	/* arena for allocating data for use during render, for
 		* example dynamic TFaces to go in the VlakRen structure.
@@ -409,6 +411,18 @@
 	struct ObjectRen *obr;
 } VolPrecache;
 
+typedef struct VolumeOb
+{
+	struct VolumeOb *next, *prev;
+	struct Material *ma;
+	struct ObjectRen *obr;
+} VolumeOb;
+
+typedef struct MatInside {
+	struct MatInside *next, *prev;
+	struct Material *ma;
+} MatInside;
+
 /* ------------------------------------------------------------------------- */
 
 struct LampRen;

Modified: branches/sim_physics/source/blender/render/intern/include/volume_precache.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/volume_precache.h	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/render/intern/include/volume_precache.h	2008-12-13 05:41:34 UTC (rev 17817)
@@ -27,4 +27,5 @@
  */
  
 void volume_precache(Render *re);
-void free_volume_precache(Render *re);
\ No newline at end of file
+void free_volume_precache(Render *re);
+int point_inside_volume_objectinstance(ObjectInstanceRen *obi, float *co);
\ No newline at end of file

Modified: branches/sim_physics/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/convertblender.c	2008-12-12 23:30:23 UTC (rev 17816)
+++ branches/sim_physics/source/blender/render/intern/source/convertblender.c	2008-12-13 05:41:34 UTC (rev 17817)
@@ -104,6 +104,7 @@
 #include "multires.h"
 #include "occlusion.h"
 #include "pointdensity.h"
+#include "voxeldata.h"
 #include "render_types.h"
 #include "rendercore.h"
 #include "renderdatabase.h"
@@ -3028,16 +3029,51 @@
 	}
 }
 
-static void add_vol_precache(Render *re, ObjectRen *obr, Material *ma)
+static void free_camera_inside_volumes(Render *re)
 {
-	struct VolPrecache *vp;
+	BLI_freelistN(&re->render_volumes_inside);
+}
+
+static void init_camera_inside_volumes(Render *re)
+{
+	ObjectInstanceRen *obi;
+	VolumeOb *vo;
+	float co[3] = {0.f, 0.f, 0.f};
+
+	for(vo= re->volumes.first; vo; vo= vo->next) {
+		for(obi= re->instancetable.first; obi; obi= obi->next) {
+			if (obi->obr == vo->obr) {
+				if (point_inside_volume_objectinstance(obi, co)) {
+					MatInside *mi;
+					
+					mi = MEM_mallocN(sizeof(MatInside), "camera inside material");
+					mi->ma = vo->ma;
+					
+					BLI_addtail(&(re->render_volumes_inside), mi);
+				}
+			}
+		}
+	}
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list