[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16779] branches/sim_physics/source/ blender: * Volumetrics

Matt Ebb matt at mke3.net
Sun Sep 28 10:00:23 CEST 2008


Revision: 16779
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16779
Author:   broken
Date:     2008-09-28 10:00:22 +0200 (Sun, 28 Sep 2008)

Log Message:
-----------
* Volumetrics

Removed all the old particle rendering code and options I had in there 
before, in order to make way for...

A new procedural texture: 'Point Density'

Point Density is a 3d texture that find the density of a group of 'points' 
in space and returns that in the texture as an intensity value. Right now, 
its at an early stage and it's only enabled for particles, but it would be 
cool to extend it later for things like object vertices, or point cache 
files from disk - i.e. to import point cloud data into Blender for 
rendering volumetrically.

Currently there are just options for an Object and its particle system 
number, this is the particle system that will get cached before rendering, 
and then used for the texture's density estimation.

It works totally consistent with as any other procedural texture, so 
previously where I've mapped a clouds texture to volume density to make 
some of those test renders, now I just map a point density texture to 
volume density.

Here's a version of the same particle smoke test file from before, updated 
to use the point density texture instead:
http://mke3.net/blender/devel/rendering/volumetrics/smoke_test02.blend

There are a few cool things about implementing this as a texture:

- The one texture (and cache) can be instanced across many different 
materials:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_instanced.png

This means you can calculate and bake one particle system, but render it 
multiple times across the scene, with different material settings, at no 
extra memory cost.

Right now, the particles are cached in world space, so you have to map it 
globally, and if you want it offset, you have to do it in the material (as 
in the file above). I plan to add an option to bake in local space, so you 
can just map the texture to local and it just works.

- It also works for solid surfaces too, it just gets the density at that 
particular point on the surface, eg:
http://mke3.net/blender/devel/rendering/volumetrics/pointdensity_solid.mov

- You can map it to whatever you want, not only density but the various 
emissions and colours as well. I'd like to investigate using the other 
outputs in the texture too (like the RGB or normal outputs), perhaps with 
options to colour by particle age, generating normals for making particle 
'dents' in a surface, whatever!

Modified Paths:
--------------
    branches/sim_physics/source/blender/blenkernel/BKE_texture.h
    branches/sim_physics/source/blender/blenkernel/intern/material.c
    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/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/renderdatabase.h
    branches/sim_physics/source/blender/render/intern/source/convertblender.c
    branches/sim_physics/source/blender/render/intern/source/renderdatabase.c
    branches/sim_physics/source/blender/render/intern/source/texture.c
    branches/sim_physics/source/blender/render/intern/source/volumetric.c
    branches/sim_physics/source/blender/src/buttons_shading.c

Added Paths:
-----------
    branches/sim_physics/source/blender/render/intern/include/pointdensity.h
    branches/sim_physics/source/blender/render/intern/source/pointdensity.c

Modified: branches/sim_physics/source/blender/blenkernel/BKE_texture.h
===================================================================
--- branches/sim_physics/source/blender/blenkernel/BKE_texture.h	2008-09-28 05:02:39 UTC (rev 16778)
+++ branches/sim_physics/source/blender/blenkernel/BKE_texture.h	2008-09-28 08:00:22 UTC (rev 16779)
@@ -39,6 +39,7 @@
 struct HaloRen;
 struct TexMapping;
 struct EnvMap;
+struct PointDensity;
 
 /*  in ColorBand struct */
 #define MAXCOLORBAND 32
@@ -74,6 +75,11 @@
 struct EnvMap *BKE_add_envmap(void);
 struct EnvMap *BKE_copy_envmap(struct EnvMap *env);
 
+void    BKE_free_pointdensitydata(struct PointDensity *pd);
+void    BKE_free_pointdensity(struct PointDensity *pd);
+struct PointDensity *BKE_add_pointdensity(void);
+struct PointDensity *BKE_copy_pointdensity(struct PointDensity *pd);
+
 int     BKE_texture_dependsOnTime(const struct Tex *texture);
 
 #endif

Modified: branches/sim_physics/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/sim_physics/source/blender/blenkernel/intern/material.c	2008-09-28 05:02:39 UTC (rev 16778)
+++ branches/sim_physics/source/blender/blenkernel/intern/material.c	2008-09-28 08:00:22 UTC (rev 16779)
@@ -173,8 +173,6 @@
 	ma->vol_scattering = 1.0f;
 	ma->vol_absorption_col[0] = ma->vol_absorption_col[1] = ma->vol_absorption_col[2] = 0.0f;
 	ma->vol_raydepth = 15;
-	ma->vol_part_maxnearest = 5;
-	ma->vol_part_searchradius = 0.2f;
 	
 	ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RADIO|MA_RAYBIAS|MA_TANGENT_STR;
 

Modified: branches/sim_physics/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/sim_physics/source/blender/blenkernel/intern/texture.c	2008-09-28 05:02:39 UTC (rev 16778)
+++ branches/sim_physics/source/blender/blenkernel/intern/texture.c	2008-09-28 08:00:22 UTC (rev 16779)
@@ -409,6 +409,7 @@
 	free_plugin_tex(tex->plugin);
 	if(tex->coba) MEM_freeN(tex->coba);
 	if(tex->env) BKE_free_envmap(tex->env);
+	if(tex->pd) BKE_free_pointdensity(tex->pd);
 	BKE_previewimg_free(&tex->preview);
 	BKE_icon_delete((struct ID*)tex);
 	tex->id.icon_id = 0;
@@ -470,6 +471,11 @@
 		tex->env->depth=0;
 	}
 
+	if (tex->pd) {
+		tex->pd->radius = 0.3f;
+		tex->pd->nearest = 5;
+	}
+
 	pit = tex->plugin;
 	if (pit) {
 		varstr= pit->varstr;
@@ -566,6 +572,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(tex->preview) texn->preview = BKE_previewimg_copy(tex->preview);
 
@@ -859,6 +866,46 @@
 }
 
 /* ------------------------------------------------------------------------- */
+
+PointDensity *BKE_add_pointdensity(void)
+{
+	PointDensity *pd;
+	
+	pd= MEM_callocN(sizeof(PointDensity), "pointdensity");
+	pd->radius = 0.3f;
+	pd->nearest = 5;
+	pd->type = TEX_PD_PSYS;
+	pd->point_tree = NULL;
+	
+	return pd;
+} 
+
+PointDensity *BKE_copy_pointdensity(PointDensity *pd)
+{
+	PointDensity *pdn;
+	int a;
+	
+	pdn= MEM_dupallocN(pd);
+	pdn->point_tree = NULL;
+	
+	return pd;
+}
+
+void BKE_free_pointdensitydata(PointDensity *pd)
+{
+	if (pd->point_tree) {
+		BLI_kdtree_free(pd->point_tree);
+		pd->point_tree = NULL;
+	}
+}
+
+void BKE_free_pointdensity(PointDensity *pd)
+{
+	BKE_free_pointdensitydata(pd);
+	MEM_freeN(pd);
+}
+
+/* ------------------------------------------------------------------------- */
 int BKE_texture_dependsOnTime(const struct Tex *texture)
 {
 	if(texture->plugin) {

Modified: branches/sim_physics/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-09-28 05:02:39 UTC (rev 16778)
+++ branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-09-28 08:00:22 UTC (rev 16779)
@@ -2475,6 +2475,7 @@
 			tex->ima= newlibadr_us(fd, tex->id.lib, tex->ima);
 			tex->ipo= newlibadr_us(fd, tex->id.lib, tex->ipo);
 			if(tex->env) tex->env->object= newlibadr(fd, tex->id.lib, tex->env->object);
+			if(tex->pd) tex->pd->object= newlibadr(fd, tex->id.lib, tex->pd->object);
 
 			tex->id.flag -= LIB_NEEDLINK;
 		}
@@ -2501,6 +2502,10 @@
 		memset(tex->env->cube, 0, 6*sizeof(void *));
 		tex->env->ok= 0;
 	}
+	tex->pd= newdataadr(fd, tex->pd);
+	if(tex->pd) {
+		tex->pd->point_tree = NULL;
+	}
 	tex->preview = direct_link_preview_image(fd, tex->preview);
 
 	tex->iuser.ok= 1;
@@ -7885,8 +7890,6 @@
 				ma->vol_scattering = 1.0f;
 				ma->vol_absorption_col[0] = ma->vol_absorption_col[1] = ma->vol_absorption_col[2] = 0.0f;
 				if (ma->vol_raydepth == 0) ma->vol_raydepth = 15;
-				if (ma->vol_part_maxnearest == 0) ma->vol_part_maxnearest = 5;
-				if (ma->vol_part_searchradius < 0.001f) ma->vol_part_searchradius = 0.20;
 			}
 		}
 	}

Modified: branches/sim_physics/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/sim_physics/source/blender/blenloader/intern/writefile.c	2008-09-28 05:02:39 UTC (rev 16778)
+++ branches/sim_physics/source/blender/blenloader/intern/writefile.c	2008-09-28 08:00:22 UTC (rev 16779)
@@ -1334,6 +1334,7 @@
 			if(tex->plugin) writestruct(wd, DATA, "PluginTex", 1, tex->plugin);
 			if(tex->coba) writestruct(wd, DATA, "ColorBand", 1, tex->coba);
 			if(tex->env) writestruct(wd, DATA, "EnvMap", 1, tex->env);
+			if(tex->pd) writestruct(wd, DATA, "PointDensity", 1, tex->pd);
 			
 			write_previews(wd, tex->preview);
 		}

Modified: branches/sim_physics/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-28 05:02:39 UTC (rev 16778)
+++ branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-28 08:00:22 UTC (rev 16779)
@@ -70,13 +70,10 @@
 	float vol_stepsize, vol_shade_stepsize;
 	float vol_absorption, vol_scattering;
 	float vol_absorption_col[3];
-	float vol_part_searchradius;
 	short vol_raydepth;
-	short vol_part_maxnearest;
 	short vol_shadeflag;
-	short vol_pad[3];
-	
-	
+	int volpad;
+		
 	float fresnel_mir, fresnel_mir_i;
 	float fresnel_tra, fresnel_tra_i;
 	float filter;		/* filter added, for raytrace transparency and transmissivity */
@@ -354,7 +351,6 @@
 #define MA_VOL_SHADED		1
 #define MA_VOL_ATTENUATED	2
 #define MA_VOL_SHADOWED		4
-#define MA_VOL_PARTICLES	8
 
 #endif
 

Modified: branches/sim_physics/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-09-28 05:02:39 UTC (rev 16778)
+++ branches/sim_physics/source/blender/makesdna/DNA_texture_types.h	2008-09-28 08:00:22 UTC (rev 16779)
@@ -127,6 +127,22 @@
 	short recalc, lastsize;
 } EnvMap;
 
+typedef struct PointDensity {
+	short flag;
+
+	short nearest;
+	float radius;
+
+	short type;
+	short pdpad[3];
+
+	struct Object *object;	/* for 'Particle system' type - source object */
+	short psysindex;		/* and object's psys number */
+	short pdpad2[3];
+	
+	void *point_tree;		/* the kd-tree containing points */
+} PointDensity;
+
 typedef struct Tex {
 	ID id;
 	
@@ -172,6 +188,7 @@
 	struct ColorBand *coba;
 	struct EnvMap *env;
 	struct PreviewImage * preview;
+	struct PointDensity *pd;
 	
 } Tex;
 
@@ -208,6 +225,8 @@
 #define TEX_MUSGRAVE	11
 #define TEX_VORONOI		12
 #define TEX_DISTNOISE	13
+/* predicting ocean texture for 14 */
+#define TEX_POINTDENSITY	15
 
 /* musgrave stype */
 #define TEX_MFRACTAL		0
@@ -385,5 +404,16 @@
 #define ENV_NORMAL	1
 #define ENV_OSA		2
 
+/* **************** PointDensity ********************* */
+
+/* type */
+#define TEX_PD_PSYS			0
+#define TEX_PD_OBJECT		1
+#define TEX_PD_FILE			2
+
+/* psys_space */
+#define TEX_PD_PSYS_WORLDSPACE	0
+#define TEX_PD_PSYS_OBJECTSPACE	1
+
 #endif
 

Added: branches/sim_physics/source/blender/render/intern/include/pointdensity.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/pointdensity.h	                        (rev 0)
+++ branches/sim_physics/source/blender/render/intern/include/pointdensity.h	2008-09-28 08:00:22 UTC (rev 16779)
@@ -0,0 +1,43 @@
+/*
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Matt Ebb
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef POINTDENSITY_H
+#define POINTDENSITY_H 
+
+/**
+ * Make point density kd-trees for all point density textures in the scene
+ */
+
+struct Render;
+struct TexResult;
+
+void make_pointdensities(struct Render *re);
+int pointdensitytex(struct Tex *tex, float *texvec, struct TexResult *texres);
+
+#endif /* POINTDENSITY_H */
+

Modified: branches/sim_physics/source/blender/render/intern/include/render_types.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/render_types.h	2008-09-28 05:02:39 UTC (rev 16778)
+++ branches/sim_physics/source/blender/render/intern/include/render_types.h	2008-09-28 08:00:22 UTC (rev 16779)
@@ -198,8 +198,6 @@
 	ListBase *sss_points;
 	struct Material *sss_mat;
 
-	struct KDTree *particles_tree;
-
 	ListBase customdata_names;
 
 	struct Object *excludeob;
@@ -347,16 +345,7 @@
     struct Material *mat;
 } HaloRen;
 
-/* ------------------------------------------------------------------------- */
 
-typedef struct ParticleRen
-{
-	struct ParticleRen *next, *prev;
-	float co[3];	// location
-	// float col[3]; // colour

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list