[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16698] branches/sim_physics/source/ blender/render/intern: * Refactored the volume texture code.

Matt Ebb matt at mke3.net
Tue Sep 23 09:44:25 CEST 2008


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

Log Message:
-----------
* Refactored the volume texture code. Seems to go ok so far, stress 
tests and all my old files render fine, but anyone feel free to let me 
know if you find a bug in this :)

Should be a bit faster too, this file renders in about 60% of the time 
it did before 
(http://mke3.net/blender/devel/rendering/volumetrics/vol_col_emit.mov)

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

Modified: branches/sim_physics/source/blender/render/intern/include/texture.h
===================================================================
--- branches/sim_physics/source/blender/render/intern/include/texture.h	2008-09-23 07:05:06 UTC (rev 16697)
+++ branches/sim_physics/source/blender/render/intern/include/texture.h	2008-09-23 07:44:25 UTC (rev 16698)
@@ -56,7 +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, int effect);
-void do_volume_tex(ShadeInput *shi, float *xyz, float *col, float *absorb_col, float *alpha, float *emit);
+void do_volume_tex(ShadeInput *shi, float *xyz, int mapto_flag, float *col, float *val);
 
 void init_render_textures(Render *re);
 

Modified: branches/sim_physics/source/blender/render/intern/source/texture.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/texture.c	2008-09-23 07:05:06 UTC (rev 16697)
+++ branches/sim_physics/source/blender/render/intern/source/texture.c	2008-09-23 07:44:25 UTC (rev 16698)
@@ -1451,7 +1451,7 @@
 	return in;
 }
 
-void do_volume_tex(ShadeInput *shi, float *xyz, float *col, float *absorb_col, float *alpha, float *emit)
+void do_volume_tex(ShadeInput *shi, float *xyz, int mapto_flag, float *col, float *val)
 {
 	MTex *mtex;
 	Tex *tex;
@@ -1472,6 +1472,10 @@
 			tex= mtex->tex;
 			if(tex==0) continue;
 			
+			/* only process if this texture is mapped 
+			 * to one that we're interested in */
+			if (!(mtex->mapto & mapto_flag)) continue;
+			
 			/* which coords */
 			if(mtex->texco==TEXCO_OBJECT) { 
 				Object *ob= mtex->object;
@@ -1550,7 +1554,7 @@
 			}
 			
 			
-			if(mtex->mapto & (MAP_COL+MAP_COLMIR)) {
+			if((mapto_flag & (MAP_COL+MAP_COLMIR)) && (mtex->mapto & (MAP_COL+MAP_COLMIR))) {
 				float tcol[3], colfac;
 				
 				/* stencil maps on the texture control slider, not texture intensity value */
@@ -1568,17 +1572,17 @@
 				}
 				else texres.tin= texres.ta;
 				
-				if(mtex->mapto & MAP_COL) {
+				if((mapto_flag & MAP_COL) && (mtex->mapto & MAP_COL)) {
 					texture_rgb_blend(col, tcol, col, texres.tin, colfac, mtex->blendtype);
 				}
 				
 				/* MAP_COLMIR is abused for absorption colour at the moment */
-				if(mtex->mapto & MAP_COLMIR) {
-					texture_rgb_blend(absorb_col, tcol, absorb_col, texres.tin, colfac, mtex->blendtype);
+				if((mapto_flag & MAP_COLMIR) && (mtex->mapto & MAP_COLMIR)) {
+					texture_rgb_blend(col, tcol, col, texres.tin, colfac, mtex->blendtype);
 				}
 			}
 			
-			if(mtex->mapto & MAP_VARS) {
+			if((mapto_flag & MAP_VARS) && (mtex->mapto & MAP_VARS)) {
 				/* stencil maps on the texture control slider, not texture intensity value */
 				float varfac= mtex->varfac*stencilTin;
 				
@@ -1587,17 +1591,17 @@
 					else texres.tin= (0.35*texres.tr+0.45*texres.tg+0.2*texres.tb);
 				}
 				
-				if(mtex->mapto & MAP_EMIT) {
+				if((mapto_flag & MAP_EMIT) && (mtex->mapto & MAP_EMIT)) {
 					int flip= mtex->maptoneg & MAP_EMIT;
 
-					*emit = texture_value_blend(mtex->def_var, *emit, texres.tin, varfac, mtex->blendtype, flip);
-					if(*emit<0.0) *emit= 0.0;
+					*val = texture_value_blend(mtex->def_var, *val, texres.tin, varfac, mtex->blendtype, flip);
+					if(*val<0.0) *val= 0.0;
 				}
-				if(mtex->mapto & MAP_ALPHA) {
+				if((mapto_flag & MAP_ALPHA) && (mtex->mapto & MAP_ALPHA)) {
 					int flip= mtex->maptoneg & MAP_ALPHA;
 
-					*alpha = texture_value_blend(mtex->def_var, *alpha, texres.tin, varfac, mtex->blendtype, flip);
-					CLAMP(*alpha, 0.0, 1.0);
+					*val = texture_value_blend(mtex->def_var, *val, texres.tin, varfac, mtex->blendtype, flip);
+					CLAMP(*val, 0.0, 1.0);
 				}
 			}
 		}

Modified: branches/sim_physics/source/blender/render/intern/source/volumetric.c
===================================================================
--- branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-09-23 07:05:06 UTC (rev 16697)
+++ branches/sim_physics/source/blender/render/intern/source/volumetric.c	2008-09-23 07:44:25 UTC (rev 16698)
@@ -113,13 +113,11 @@
 float vol_get_density(struct ShadeInput *shi, float *co)
 {
 	float density = shi->mat->alpha;
-	float emit_fac=0.0f;
 	float col[3] = {0.0, 0.0, 0.0};
-	float absorb_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, absorb_col, &density, &emit_fac);
+		do_volume_tex(shi, co, MAP_ALPHA, col, &density);
 	
 	return density;
 }
@@ -130,13 +128,11 @@
 void vol_get_emission(ShadeInput *shi, float *em, float *co, float density)
 {
 	float emission = shi->mat->emit;
-	float col[3];
-	float dens_dummy = 1.0f;
-	float absorb_col[3] = {0.0, 0.0, 0.0};
+	float col[3] = {0.0, 0.0, 0.0};
 	
 	VECCOPY(col, &shi->mat->r);
 	
-	do_volume_tex(shi, co, col, absorb_col, &dens_dummy, &emission);
+	do_volume_tex(shi, co, MAP_EMIT+MAP_COL, col, &emission);
 	
 	em[0] = em[1] = em[2] = emission;
 	VecMulVecf(em, em, col);
@@ -144,15 +140,13 @@
 
 void vol_get_absorption(ShadeInput *shi, float *absorb_col, float *co)
 {
-	float col[3];
 	float dummy = 1.0f;
-	float vec_one[3] = {1.0f, 1.0f, 1.0f};
 	float absorption = shi->mat->vol_absorption;
 	
 	VECCOPY(absorb_col, shi->mat->vol_absorption_col);
 	
 	if (shi->mat->flag & MA_IS_TEXTURED)
-		do_volume_tex(shi, co, col, absorb_col, &dummy, &dummy);
+		do_volume_tex(shi, co, MAP_COLMIR, absorb_col, &dummy);
 	
 	absorb_col[0] = (1.0f - absorb_col[0]) * absorption;
 	absorb_col[1] = (1.0f - absorb_col[1]) * absorption;





More information about the Bf-blender-cvs mailing list