[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16662] branches/sim_physics/source/ blender: * Volume rendering

Matt Ebb matt at mke3.net
Mon Sep 22 03:51:26 CEST 2008


Revision: 16662
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16662
Author:   broken
Date:     2008-09-22 03:51:24 +0200 (Mon, 22 Sep 2008)

Log Message:
-----------
* Volume rendering

This is an initial commit to get it in SVN and make it easier to work on.

Don't expect it to work perfectly, it's still in development and there's
plenty of work still needing to be done. And so no I'm not very interested 
in hearing bug reports or feature requests at this stage :)

There's some info on this, and a todo list at:
http://mke3.net/weblog/volume-rendering/

Right now I'm trying to focus on getting shading working correctly (there's 
currently a problem in which 'surfaces' of the volume facing towards or away
from light sources are getting shaded differently to how they should be),
then I'll work on integration issues, like taking materials behind the volume
into account, blending with alpha, etc. You can do simple testing though,
mapping textures to density or emission on a cube with volume material.

Modified Paths:
--------------
    branches/sim_physics/source/blender/blenkernel/intern/material.c
    branches/sim_physics/source/blender/blenlib/BLI_arithb.h
    branches/sim_physics/source/blender/blenlib/intern/arithb.c
    branches/sim_physics/source/blender/blenloader/intern/readfile.c
    branches/sim_physics/source/blender/makesdna/DNA_material_types.h
    branches/sim_physics/source/blender/render/intern/include/shading.h
    branches/sim_physics/source/blender/render/intern/include/texture.h
    branches/sim_physics/source/blender/render/intern/source/convertblender.c
    branches/sim_physics/source/blender/render/intern/source/shadeinput.c
    branches/sim_physics/source/blender/render/intern/source/shadeoutput.c
    branches/sim_physics/source/blender/render/intern/source/texture.c
    branches/sim_physics/source/blender/src/buttons_shading.c
    branches/sim_physics/source/blender/src/previewrender.c

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

Modified: branches/sim_physics/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/sim_physics/source/blender/blenkernel/intern/material.c	2008-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/blenkernel/intern/material.c	2008-09-22 01:51:24 UTC (rev 16662)
@@ -166,6 +166,11 @@
 	ma->sss_texfac= 0.0f;
 	ma->sss_front= 1.0f;
 	ma->sss_back= 1.0f;
+	
+	ma->vol_stepsize = 0.2f;
+	ma->vol_shade_stepsize = 0.2f;
+	ma->vol_absorption = 1.0f;
+	ma->vol_scattering = 1.0f;
 
 	ma->mode= MA_TRACEBLE|MA_SHADBUF|MA_SHADOW|MA_RADIO|MA_RAYBIAS|MA_TANGENT_STR;
 

Modified: branches/sim_physics/source/blender/blenlib/BLI_arithb.h
===================================================================
--- branches/sim_physics/source/blender/blenlib/BLI_arithb.h	2008-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/blenlib/BLI_arithb.h	2008-09-22 01:51:24 UTC (rev 16662)
@@ -250,6 +250,7 @@
 
 void VecAddf(float *v, float *v1, float *v2);
 void VecSubf(float *v, float *v1, float *v2);
+void VecMulVecf(float *v, float *v1, float *v2);
 void VecLerpf(float *target, float *a, float *b, float t);
 void VecMidf(float *v, float *v1, float *v2);
 

Modified: branches/sim_physics/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/sim_physics/source/blender/blenlib/intern/arithb.c	2008-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/blenlib/intern/arithb.c	2008-09-22 01:51:24 UTC (rev 16662)
@@ -2126,6 +2126,13 @@
 	v[2]= v1[2]- v2[2];
 }
 
+void VecMulVecf(float *v, float *v1, float *v2)
+{
+	v[0] = v1[0] * v2[0];
+	v[1] = v1[1] * v2[1];
+	v[2] = v1[2] * v2[2];
+}
+
 void VecLerpf(float *target, float *a, float *b, float t)
 {
 	float s = 1.0f-t;
@@ -3269,6 +3276,12 @@
 	return d;
 }
 
+float rgb_to_luminance(float r, float g, float b)
+{
+	/* Rec. 709 HDTV */
+	return (0.2126*r + 0.7152*g + 0.0722*b);
+}
+
 void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b)
 {
 	int i;

Modified: branches/sim_physics/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/blenloader/intern/readfile.c	2008-09-22 01:51:24 UTC (rev 16662)
@@ -7681,6 +7681,7 @@
 	if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 11)) {
 		Object *ob;
 		bActionStrip *strip;
+
 		
 		/* nla-strips - scale */		
 		for (ob= main->object.first; ob; ob= ob->id.next) {
@@ -7704,12 +7705,14 @@
 				ob->soft->shearstiff = 1.0f; 
 			}
 		}
+		
 	}
 
 	if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 14)) {
 		Scene *sce= main->scene.first;
 		Sequence *seq;
 		Editing *ed;
+		Material *ma;
 		
 		while(sce) {
 			ed= sce->ed;
@@ -7724,6 +7727,13 @@
 			
 			sce= sce->id.next;
 		}
+		
+		for(ma=main->mat.first; ma; ma= ma->id.next) {
+			if (ma->vol_shade_stepsize < 0.001f) ma->vol_shade_stepsize = 0.2f;
+			if (ma->vol_stepsize < 0.001f) ma->vol_stepsize = 0.2f;
+			if (ma->vol_absorption < 0.001f) ma->vol_absorption = 1.0f;
+			if (ma->vol_scattering < 0.001f) ma->vol_scattering = 1.0f;
+		}
 	}
 	
 	/*fix broken group lengths in id properties*/

Modified: branches/sim_physics/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-22 01:51:24 UTC (rev 16662)
@@ -62,6 +62,16 @@
 	float translucency;
 	/* end synced with render_types.h */
 	
+	short material_type; /* solid, halo, volumetric */
+	short pad5[3];
+	
+	/* volumetrics */
+	float vol_alphathresh;
+	float vol_stepsize, vol_shade_stepsize;
+	float vol_absorption, vol_scattering;
+	short vol_shadeflag;
+	short vpad;
+	
 	float fresnel_mir, fresnel_mir_i;
 	float fresnel_tra, fresnel_tra_i;
 	float filter;		/* filter added, for raytrace transparency and transmissivity */
@@ -154,6 +164,12 @@
 		/* for render */
 #define MA_IS_USED		1
 
+/* material_type */
+#define MA_SOLID		0
+#define MA_PTHALO		1
+#define MA_VOLUME		2
+#define MA_VOLUMESOLID	3
+
 /* mode (is int) */
 #define MA_TRACEBLE		1
 #define MA_SHADOW		2
@@ -327,5 +343,10 @@
 /* sss_flag */
 #define MA_DIFF_SSS		1
 
+/* vol_shadeflag */
+#define MA_VOL_SHADED		1
+#define MA_VOL_ATTENUATED	2
+#define MA_VOL_SHADOWED		4
+
 #endif
 

Modified: branches/sim_physics/source/blender/render/intern/include/shading.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/shading.h	2008-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/render/intern/include/shading.h	2008-09-22 01:51:24 UTC (rev 16662)
@@ -52,6 +52,7 @@
 
 	/* also the node shader callback */
 void shade_material_loop(struct ShadeInput *shi, struct ShadeResult *shr);
+void shade_volume_loop(struct ShadeInput *shi, struct ShadeResult *shr);
 
 void shade_input_set_triangle_i(struct ShadeInput *shi, struct ObjectInstanceRen *obi, struct VlakRen *vlr, short i1, short i2, short i3);
 void shade_input_set_triangle(struct ShadeInput *shi, volatile int obi, volatile int facenr, int normal_flip);
@@ -85,6 +86,7 @@
 void ambient_occlusion_to_diffuse(struct ShadeInput *shi, float *diff);
 void ambient_occlusion(struct ShadeInput *shi);
 
+ListBase *get_lights(struct ShadeInput *shi);
 float lamp_get_visibility(struct LampRen *lar, float *co, float *lv, float *dist);
 void lamp_get_shadow(struct LampRen *lar, ShadeInput *shi, float inp, float *shadfac, int do_real);
 

Modified: branches/sim_physics/source/blender/render/intern/include/texture.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/texture.h	2008-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/render/intern/include/texture.h	2008-09-22 01:51:24 UTC (rev 16662)
@@ -56,6 +56,7 @@
 void do_sky_tex(float *rco, float *lo, float *dxyview, float *hor, float *zen, float *blend, int skyflag);
 void do_material_tex(struct ShadeInput *shi);
 void do_lamp_tex(LampRen *la, float *lavec, struct ShadeInput *shi, float *colf);
+void do_volume_tex(ShadeInput *shi, float *xyz, float *col, float *alpha, float *emit);
 
 void init_render_textures(Render *re);
 

Added: branches/sim_physics/source/blender/render/intern/include/volumetric.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/volumetric.h	                        (rev 0)
+++ branches/sim_physics/source/blender/render/intern/include/volumetric.h	2008-09-22 01:51:24 UTC (rev 16662)
@@ -0,0 +1,29 @@
+/**
+ *
+ * ***** 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): Farsthary (Raul FHernandez), Matt Ebb.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr);
\ 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-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/render/intern/source/convertblender.c	2008-09-22 01:51:24 UTC (rev 16662)
@@ -1029,6 +1029,8 @@
 	if(ma->nodetree && ma->use_nodes)
 		flag_render_node_material(re, ma->nodetree);
 	
+	if (ma->material_type == MA_VOLUME) re->r.mode |= R_RAYTRACE;
+	
 	return ma;
 }
 

Modified: branches/sim_physics/source/blender/render/intern/source/shadeinput.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/shadeinput.c	2008-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/render/intern/source/shadeinput.c	2008-09-22 01:51:24 UTC (rev 16662)
@@ -135,7 +135,13 @@
 	}	
 }
 
+/* delivers a fully filled in ShadeResult, for all passes */
+void shade_volume_loop(ShadeInput *shi, ShadeResult *shr)
+{
+	if(R.r.mode & R_RAYTRACE) volume_trace(shi, shr);
+}
 
+
 /* do a shade, finish up some passes, apply mist */
 void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr)
 {
@@ -151,7 +157,8 @@
 		memcpy(&shi->r, &shi->mat->r, 23*sizeof(float));
 		shi->har= shi->mat->har;
 		
-		shade_material_loop(shi, shr);
+		if (shi->mat->material_type == MA_SOLID) shade_material_loop(shi, shr);
+		else if (shi->mat->material_type == MA_VOLUME) shade_volume_loop(shi, shr);
 	}
 	
 	/* copy additional passes */

Modified: branches/sim_physics/source/blender/render/intern/source/shadeoutput.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/shadeoutput.c	2008-09-22 00:32:07 UTC (rev 16661)
+++ branches/sim_physics/source/blender/render/intern/source/shadeoutput.c	2008-09-22 01:51:24 UTC (rev 16662)
@@ -58,7 +58,7 @@
 extern struct Render R;
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 
-static ListBase *get_lights(ShadeInput *shi)
+ListBase *get_lights(ShadeInput *shi)
 {
 	
 	if(shi->light_override)

Modified: branches/sim_physics/source/blender/render/intern/source/texture.c

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list