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

Matt Ebb matt at mke3.net
Tue Sep 23 06:26:53 CEST 2008


Revision: 16694
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16694
Author:   broken
Date:     2008-09-23 06:26:52 +0200 (Tue, 23 Sep 2008)

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

- Fixed a shading bug, due to issues in the raytrace engine where it would ignore 
intersections from the starting face (as it should). Disabled this for single 
scattering intersections, thanks to Brecht for a hint there. It still shows a 
little bit of noise, I think due to raytrace inaccuracy, which will have to be 
fixed up later.

before: http://mke3.net/blender/devel/rendering/volumetrics/vol_shaded_old.png
after: http://mke3.net/blender/devel/rendering/volumetrics/vol_shaded_correct.png

Now single scatttering shading works very nicely and is capable of things like this:
http://mke3.net/blender/devel/rendering/volumetrics/vol_shaded_clouds.mov

- Added colour emission. Now as well as the overall 'Emit:' slider to control 
overall emission strength, there's also a colour swatch for the volume to emit 
that colour. This can also be textured, using 'Emit Col' in the map to panel.

This animation was made using a clouds texture, with colour band, mapped to both 
emit colour and emit (strength):
http://mke3.net/blender/devel/rendering/volumetrics/vol_col_emit.mov

- Added 'Local' mapping to 'map input' - it's similar to Orco

- Fixed texture 'map input', wasn't using the offsets or scale values.

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/raytrace.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

Modified: branches/sim_physics/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-23 01:28:42 UTC (rev 16693)
+++ branches/sim_physics/source/blender/makesdna/DNA_material_types.h	2008-09-23 04:26:52 UTC (rev 16694)
@@ -69,6 +69,8 @@
 	float vol_alphathresh;
 	float vol_stepsize, vol_shade_stepsize;
 	float vol_absorption, vol_scattering;
+	float vol_absorption_col[3];
+	float vpad2;
 	short vol_shadeflag;
 	short vpad;
 	
@@ -163,6 +165,7 @@
 /* flag */
 		/* for render */
 #define MA_IS_USED		1
+#define MA_IS_TEXTURED	2
 
 /* material_type */
 #define MA_SOLID		0

Modified: branches/sim_physics/source/blender/render/intern/source/convertblender.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/convertblender.c	2008-09-23 01:28:42 UTC (rev 16693)
+++ branches/sim_physics/source/blender/render/intern/source/convertblender.c	2008-09-23 04:26:52 UTC (rev 16694)
@@ -921,6 +921,28 @@
 	}
 }
 
+static void check_material_is_textured(Material *ma)
+{
+	MTex *mtex;
+	Tex *tex;
+	int tex_nr;
+	
+	for(tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
+		if(ma->septex & (1<<tex_nr))
+			continue;
+		
+		if(ma->mtex[tex_nr]) {
+			mtex= ma->mtex[tex_nr];
+			tex= mtex->tex;
+			if(tex==NULL)
+				continue;
+			else
+				ma->flag |= MA_IS_TEXTURED;
+				return;
+		}
+	}
+}
+
 static Material *give_render_material(Render *re, Object *ob, int nr)
 {
 	extern Material defmaterial;	/* material.c */
@@ -943,6 +965,8 @@
 	
 	if (ma->material_type == MA_VOLUME) re->r.mode |= R_RAYTRACE;
 	
+	check_material_is_textured(ma);
+	
 	return ma;
 }
 

Modified: branches/sim_physics/source/blender/render/intern/source/raytrace.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/raytrace.c	2008-09-23 01:28:42 UTC (rev 16693)
+++ branches/sim_physics/source/blender/render/intern/source/raytrace.c	2008-09-23 04:26:52 UTC (rev 16694)
@@ -931,7 +931,7 @@
 		intersection to be detected in its neighbour face */
 		
 		if(is->facecontr && is->faceisect);	// optimizing, the tests below are not needed
-		else if(is->labda< .1) {
+		else if(is->labda< .1 && is->faceorig) {
 			RayFace *face= is->faceorig;
 			float *origv1, *origv2, *origv3, *origv4;
 			short de= 0;

Modified: branches/sim_physics/source/blender/render/intern/source/texture.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/texture.c	2008-09-23 01:28:42 UTC (rev 16693)
+++ branches/sim_physics/source/blender/render/intern/source/texture.c	2008-09-23 04:26:52 UTC (rev 16694)
@@ -1485,8 +1485,20 @@
 					MTC_Mat4MulVecfl(ob->imat, co);
 				}
 			}
+			/* not really orco, but 'local' */
+			else if(mtex->texco==TEXCO_ORCO) {
+				
+				if(mtex->texflag & MTEX_DUPLI_MAPTO) {
+					VECCOPY(co, shi->duplilo);
+				}
+				else {
+					Object *ob= shi->obi->ob;
+					VECCOPY(co, xyz);
+					MTC_Mat4MulVecfl(ob->imat, co);
+				}
+			}
 			else if(mtex->texco==TEXCO_GLOB) {							
-			   VECCOPY(co, xyz);		
+			   VECCOPY(co, xyz);
 			}
 			else continue;	// can happen when texco defines disappear and it renders old files
 
@@ -1508,7 +1520,7 @@
 			}
 			
 
-			rgbnor= multitex(tex, co, NULL, NULL, 0, &texres);	/* NULL = dxt/dyt, 0 = shi->osatex - not supported */
+			rgbnor= multitex(tex, texvec, NULL, NULL, 0, &texres);	/* NULL = dxt/dyt, 0 = shi->osatex - not supported */
 			
 			/* texture output */
 

Modified: branches/sim_physics/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-09-23 01:28:42 UTC (rev 16693)
+++ branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-09-23 04:26:52 UTC (rev 16694)
@@ -42,8 +42,11 @@
 #include "DNA_group_types.h"
 #include "DNA_lamp_types.h"
 
+#include "BKE_global.h"
+
 #include "render_types.h"
 #include "shading.h"
+#include "texture.h"
 
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 /* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
@@ -51,6 +54,7 @@
 extern struct Render R;
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
 
+#if 0
 static int vol_backface_intersect_check(Isect *is, int ob, RayFace *face)
 {
 	VlakRen *vlr = (VlakRen *)face;
@@ -59,11 +63,16 @@
 	 * of foward facing geometry don't cause the ray to stop */
 	return (INPR(is->vec, vlr->n) < 0.0f);
 }
+#endif
 
 #define VOL_IS_SAMEOBJECT		1
 #define VOL_IS_SAMEMATERIAL		2
 
-int vol_get_bounds(ShadeInput *shi, float *co, float *vec, float *hitco)
+
+#define VOL_BOUNDS_DEPTH	0
+#define VOL_BOUNDS_SS		1
+
+int vol_get_bounds(ShadeInput *shi, float *co, float *vec, float *hitco, int intersect_type)
 {
 	/* TODO: Box or sphere intersection types could speed things up */
 
@@ -77,8 +86,10 @@
 	isect.end[1] = co[1] + vec[1] * maxsize;
 	isect.end[2] = co[2] + vec[2] * maxsize;
 	
+	if (intersect_type == VOL_BOUNDS_DEPTH) isect.faceorig= (RayFace*)shi->vlr;
+	else if (intersect_type == VOL_BOUNDS_SS) isect.faceorig= NULL;
+	
 	isect.mode= RE_RAY_MIRROR;
-	isect.faceorig= (RayFace*)shi->vlr;
 	isect.oborig= RAY_OBJECT_SET(&R, shi->obi);
 	isect.face_last= NULL;
 	isect.ob_last= 0;
@@ -106,24 +117,27 @@
 	float col[3] = {0.0, 0.0, 0.0};
 	
 	/* do any density gain stuff here */
+	if (shi->mat->flag & MA_IS_TEXTURED)
+		do_volume_tex(shi, co, col, &density, &emit_fac);
 	
-	do_volume_tex(shi, co, col, &density, &emit_fac);
-	
 	return density;
 }
 
 
 /* compute emission component, amount of radiance to add per segment
  * can be textured with 'emit' */
-void vol_get_emission(ShadeInput *shi, float *em, float *co, float *endco, float density)
+void vol_get_emission(ShadeInput *shi, float *em, float *co, float density)
 {
 	float emission = shi->mat->emit;
-	float col[3] = {0.0, 0.0, 0.0};
+	float col[3];
 	float dens_dummy = 1.0f;
 	
+	VECCOPY(col, &shi->mat->r);
+	
 	do_volume_tex(shi, co, col, &dens_dummy, &emission);
 	
 	em[0] = em[1] = em[2] = emission;
+	VecMulVecf(em, em, col);
 }
 
 
@@ -133,7 +147,6 @@
 void vol_get_attenuation(ShadeInput *shi, float *tau, float *co, float *endco, float density, float stepsize)
 {
 	/* input density = density at co */
-
 	float dist;
 	float absorption = shi->mat->vol_absorption;
 	int s, nsteps;
@@ -194,29 +207,29 @@
 	
 	if(lar->mode & LA_TEXTURE) {
 		shi->osatex= 0;
-		do_lamp_tex(lar, lv, shi, lacol);
+		do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE);
 	}
 	
 	VecMulf(lacol, visifac*lar->energy);
 
+
 	if (shi->mat->vol_shadeflag & MA_VOL_ATTENUATED) {
-		/* find minimum of volume bounds, or lamp coord */
 		
 		if (ELEM(lar->type, LA_SUN, LA_HEMI))
 			VECCOPY(lv, lar->vec);
-		
 		VecMulf(lv, -1.0f);
 		
-		if (vol_get_bounds(shi, co, lv, hitco)) {
+		/* find minimum of volume bounds, or lamp coord */
+		if (vol_get_bounds(shi, co, lv, hitco, VOL_BOUNDS_SS)) {
+			float dist = VecLenf(co, hitco);
+			
 			if (ELEM(lar->type, LA_SUN, LA_HEMI))
 				atten_co = hitco;
-			else if ( lampdist < VecLenf(co, hitco) )
+			else if ( lampdist < dist ) {
 				atten_co = lar->co;
-			else
+			} else
 				atten_co = hitco;
 
-			atten_co = lar->co;
-
 			vol_get_attenuation(shi, tau, co, atten_co, density, shi->mat->vol_shade_stepsize);
 			tr[0] = exp(-tau[0]);
 			tr[1] = exp(-tau[1]);
@@ -232,7 +245,7 @@
 	}
 	
 	VecAddf(col, col, lacol);
-}		
+}
 
 /* shadows -> trace a ray to find blocker geometry
    - if blocker is outside the volume, use standard shadow functions
@@ -242,7 +255,7 @@
 */
 
 /* single scattering only for now */
-void vol_get_scattering(ShadeInput *shi, float *scatter, float *co, float *endco, float stepsize, float density)
+void vol_get_scattering(ShadeInput *shi, float *scatter, float *co, float stepsize, float density)
 {
 	GroupObject *go;
 	ListBase *lights;
@@ -267,8 +280,6 @@
 		VecAddf(col, col, lacol);
 	}
 	
-	
-		
 	VECCOPY(scatter, col);
 }
 
@@ -276,8 +287,6 @@
 
 static void volumeintegrate(struct ShadeInput *shi, float *col, float *co, float *endco)
 {
-	float total_tau;
-	float total_tr[3];
 	float tr[3] = {1.f, 1.f, 1.f};			/* total transmittance */
 	float radiance[3] = {0.f, 0.f, 0.f}, d_radiance[3] = {0.f, 0.f, 0.f};
 	float stepsize = shi->mat->vol_stepsize;
@@ -285,8 +294,7 @@
 	float vec[3], stepvec[3] = {0.0, 0.0, 0.0};
 	float step_tau[3], step_emit[3], step_scatter[3] = {0.0, 0.0, 0.0};
 	int s;
-	float step_sta[3], step_end[3], step_offs[3] = {0.0, 0.0, 0.0};
-	float alpha_fac, emit_fac=0.0f, tex_col[3];
+	float step_sta[3], step_end[3];
 	
 	/* multiply col_behind with beam transmittance over entire distance */
 /*
@@ -314,7 +322,7 @@
 	/* get radiance from all points along the ray due to participating media */
 	for (s = 0; s < nsteps; s++) {
 		float density = vol_get_density(shi, step_sta);
-		
+	
 		/* *** transmittance and emission *** */
 		
 		/* transmittance component (alpha) */
@@ -327,8 +335,8 @@
 		//if (rgb_to_luminance(tr[0], tr[1], tr[2]) < 1e-3) break;
 		
 		/* incoming light via emission or scattering (additive) */
-		vol_get_emission(shi, step_emit, step_sta, step_end, density);
-		vol_get_scattering(shi, step_scatter, step_end, step_end, stepsize, density);
+		vol_get_emission(shi, step_emit, step_sta, density);
+		vol_get_scattering(shi, step_scatter, step_end, stepsize, density);
 		
 		VecAddf(d_radiance, step_emit, step_scatter);
 		
@@ -336,10 +344,8 @@
 		VecMulVecf(d_radiance, tr, d_radiance);
 		VecAddf(radiance, radiance, d_radiance);	
 
-		if (s < nsteps-1) {
-			VECCOPY(step_sta, step_end);
-			VecAddf(step_end, step_end, stepvec);
-		}
+		VECCOPY(step_sta, step_end);
+		VecAddf(step_end, step_end, stepvec);
 	}
 	
 	VecMulf(radiance, stepsize);
@@ -373,12 +379,11 @@
 
 void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr)
 {
-	Isect isect;
 	float hitco[3], col[3];
 
 	memset(shr, 0, sizeof(ShadeResult));
 
-	if (vol_get_bounds(shi, shi->co, shi->view, hitco)) {
+	if (vol_get_bounds(shi, shi->co, shi->view, hitco, VOL_BOUNDS_DEPTH)) {
 		
 		volumeintegrate(shi, col, shi->co, hitco);
 		
@@ -397,4 +402,4 @@
 		shr->combined[2] = 0.0f;
 		shr->combined[3] = shr->alpha =  0.0f;
 	}
-}
\ No newline at end of file
+}

Modified: branches/sim_physics/source/blender/src/buttons_shading.c

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list