[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13040] trunk/blender/source/blender: * Displacement map baking

Matt Ebb matt at mke3.net
Sat Dec 29 06:17:19 CET 2007


Revision: 13040
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13040
Author:   broken
Date:     2007-12-29 06:17:19 +0100 (Sat, 29 Dec 2007)

Log Message:
-----------
* Displacement map baking

This is an extension on the work Brecht already did to implement normal map baking. I've updated the release notes page here with info and pics:

http://www.blender.org/development/current-projects/changes-since-244/render-baking/

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_image.h
    trunk/blender/source/blender/blenkernel/intern/image.c
    trunk/blender/source/blender/imbuf/intern/filter.c
    trunk/blender/source/blender/python/api2_2x/Image.c
    trunk/blender/source/blender/python/api2_2x/bpy_data.c
    trunk/blender/source/blender/render/extern/include/RE_pipeline.h
    trunk/blender/source/blender/render/intern/source/convertblender.c
    trunk/blender/source/blender/render/intern/source/rendercore.c
    trunk/blender/source/blender/src/buttons_scene.c
    trunk/blender/source/blender/src/editsima.c
    trunk/blender/source/blender/src/header_info.c
    trunk/blender/source/blender/src/meshtools.c
    trunk/blender/source/blender/src/verse_object.c

Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h	2007-12-29 05:16:00 UTC (rev 13039)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h	2007-12-29 05:17:19 UTC (rev 13040)
@@ -114,7 +114,7 @@
 struct Image *BKE_add_image_file(const char *name);
 
 /* adds image, adds ibuf, generates color or pattern */
-struct Image *BKE_add_image_size(int width, int height, char *name, short uvtestgrid, float color[4]);
+struct Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short uvtestgrid, float color[4]);
 
 /* for reload, refresh, pack */
 void BKE_image_signal(struct Image *ima, struct ImageUser *iuser, int signal);

Modified: trunk/blender/source/blender/blenkernel/intern/image.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image.c	2007-12-29 05:16:00 UTC (rev 13039)
+++ trunk/blender/source/blender/blenkernel/intern/image.c	2007-12-29 05:17:19 UTC (rev 13040)
@@ -378,20 +378,27 @@
 	return ima;
 }
 
-static ImBuf *add_ibuf_size(int width, int height, char *name, short uvtestgrid, float color[4])
+static ImBuf *add_ibuf_size(int width, int height, char *name, int floatbuf, short uvtestgrid, float color[4])
 {
 	ImBuf *ibuf;
 	float h=0.0, hoffs=0.0, hue=0.0, s=0.9, v=0.9, r, g, b;
 	unsigned char *rect;
+	float *rect_float;
 	int x, y;
 	int checkerwidth=21, dark=1;
 	
-	ibuf= IMB_allocImBuf(width, height, 24, IB_rect, 0);
+	if (floatbuf) {
+		ibuf= IMB_allocImBuf(width, height, 24, IB_rectfloat, 0);
+		rect_float= (float*)ibuf->rect_float;
+	}
+	else {
+		ibuf= IMB_allocImBuf(width, height, 24, IB_rect, 0);
+		rect= (unsigned char*)ibuf->rect;
+	}
+	
 	strcpy(ibuf->name, "Untitled");
 	ibuf->userflags |= IB_BITMAPDIRTY;
 	
-	rect= (unsigned char*)ibuf->rect;
-	
 	if (uvtestgrid) {
 		/* these two passes could be combined into one, but it's more readable and 
 		* easy to tweak like this, speed isn't really that much of an issue in this situation... */
@@ -400,26 +407,40 @@
 		for(y=0; y<ibuf->y; y++) {
 			dark = pow(-1, floor(y / checkerwidth));
 			
-			for(x=0; x<ibuf->x; x++, rect+=4) {
+			for(x=0; x<ibuf->x; x++) {
 				if (x % checkerwidth == 0) dark *= -1;
 				
-				if (dark > 0) {
-					rect[0] = rect[1] = rect[2] = 64;
-					rect[3] = 255;
-				} else {
-					rect[0] = rect[1] = rect[2] = 150;
-					rect[3] = 255;
+				if (floatbuf) {
+					if (dark > 0) {
+						rect_float[0] = rect_float[1] = rect_float[2] = 0.25;
+						rect_float[3] = 1.0;
+					} else {
+						rect_float[0] = rect_float[1] = rect_float[2] = 0.58;
+						rect_float[3] = 1.0;
+					}
+					rect_float+=4;
 				}
+				else {
+					if (dark > 0) {
+						rect[0] = rect[1] = rect[2] = 64;
+						rect[3] = 255;
+					} else {
+						rect[0] = rect[1] = rect[2] = 150;
+						rect[3] = 255;
+					}
+					rect += 4;
+				}
 			}
 		}
 		
 		/* 2nd pass, colored + */
-		rect= (unsigned char*)ibuf->rect;
+		if (floatbuf) rect_float= (float*)ibuf->rect_float;
+		else rect= (unsigned char*)ibuf->rect;
 		
 		for(y=0; y<ibuf->y; y++) {
 			hoffs = 0.125 * floor(y / checkerwidth);
 			
-			for(x=0; x<ibuf->x; x++, rect+=4) {
+			for(x=0; x<ibuf->x; x++) {
 				h = 0.125 * floor(x / checkerwidth);
 				
 				if ((fabs((x % checkerwidth) - (checkerwidth / 2)) < 4) &&
@@ -431,10 +452,20 @@
 						hue = fmod(fabs(h-hoffs), 1.0);
 						hsv_to_rgb(hue, s, v, &r, &g, &b);
 						
-						rect[0]= (char)(r * 255.0);
-						rect[1]= (char)(g * 255.0);
-						rect[2]= (char)(b * 255.0);
-						rect[3]= 255;
+						if (floatbuf) {
+							rect_float[0]= r;
+							rect_float[1]= g;
+							rect_float[2]= b;
+							rect_float[3]= 1.0;
+							rect_float+=4;
+						}
+						else {
+							rect[0]= (char)(r * 255.0);
+							rect[1]= (char)(g * 255.0);
+							rect[2]= (char)(b * 255.0);
+							rect[3]= 255;
+							rect+=4;
+						}
 					}
 				}
 				
@@ -442,11 +473,21 @@
 		}
 	} else {	/* blank image */
 		for(y=0; y<ibuf->y; y++) {
-			for(x=0; x<ibuf->x; x++, rect+=4) {
-				rect[0]= (char)(color[0] * 255.0);
-				rect[1]= (char)(color[1] * 255.0);
-				rect[2]= (char)(color[2] * 255.0);
-				rect[3]= (char)(color[3] * 255.0);
+			for(x=0; x<ibuf->x; x++) {
+				if (floatbuf) {
+					rect_float[0]= color[0];
+					rect_float[1]= color[1];
+					rect_float[2]= color[2];
+					rect_float[3]= color[3];
+					rect_float+=4;
+				}
+				else {
+					rect[0]= (char)(color[0] * 255.0);
+					rect[1]= (char)(color[1] * 255.0);
+					rect[2]= (char)(color[2] * 255.0);
+					rect[3]= (char)(color[3] * 255.0);
+					rect+=4;
+				}
 			}
 		}
 	}
@@ -454,7 +495,7 @@
 }
 
 /* adds new image block, creates ImBuf and initializes color */
-Image *BKE_add_image_size(int width, int height, char *name, short uvtestgrid, float color[4])
+Image *BKE_add_image_size(int width, int height, char *name, int floatbuf, short uvtestgrid, float color[4])
 {
 	Image *ima;
 	
@@ -469,7 +510,7 @@
 		ima->gen_y= height;
 		ima->gen_type= uvtestgrid;
 		
-		ibuf= add_ibuf_size(width, height, name, uvtestgrid, color);
+		ibuf= add_ibuf_size(width, height, name, floatbuf, uvtestgrid, color);
 		image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
 		
 		ima->ok= IMA_OK_LOADED;
@@ -1678,6 +1719,7 @@
 {
 	ImBuf *ibuf= NULL;
 	float color[] = {0, 0, 0, 1};
+	int floatbuf;
 
 	/* quick reject tests */
 	if(ima==NULL) 
@@ -1755,7 +1797,7 @@
 				/* UV testgrid or black or solid etc */
 				if(ima->gen_x==0) ima->gen_x= 256;
 				if(ima->gen_y==0) ima->gen_y= 256;
-				ibuf= add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, ima->gen_type, color);
+				ibuf= add_ibuf_size(ima->gen_x, ima->gen_y, ima->name, floatbuf, ima->gen_type, color);
 				image_assign_ibuf(ima, ibuf, IMA_NO_INDEX, 0);
 				ima->ok= IMA_OK_LOADED;
 			}

Modified: trunk/blender/source/blender/imbuf/intern/filter.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/filter.c	2007-12-29 05:16:00 UTC (rev 13039)
+++ trunk/blender/source/blender/imbuf/intern/filter.c	2007-12-29 05:17:19 UTC (rev 13040)
@@ -242,7 +242,7 @@
 
 #define EXTEND_PIXEL(a, w)	if((a)[3]) {r+= w*(a)[0]; g+= w*(a)[1]; b+= w*(a)[2]; tot+=w;}
 
-/* if alpha is zero, it checks surrounding pixels and averages color. sets new alphas to 255 */
+/* if alpha is zero, it checks surrounding pixels and averages color. sets new alphas to 1.0 */
 void IMB_filter_extend(struct ImBuf *ibuf)
 {
 	register char *row1, *row2, *row3;
@@ -251,7 +251,57 @@
 	
 	rowlen= ibuf->x;
 	
-	if(ibuf->rect) {
+	
+	if (ibuf->rect_float) {
+		float *temprect;
+		float *row1f, *row2f, *row3f;
+		float *fp;
+		int pixlen = 4;
+		temprect= MEM_dupallocN(ibuf->rect_float);
+		
+		for(y=1; y<=ibuf->y; y++) {
+			/* setup rows */
+			row1f= (float *)(temprect + (y-2)*rowlen*4);
+			row2f= row1f + 4*rowlen;
+			row3f= row2f + 4*rowlen;
+			if(y==1)
+				row1f= row2f;
+			else if(y==ibuf->y)
+				row3f= row2f;
+			
+			fp= (float *)(ibuf->rect_float + (y-1)*rowlen*4);
+			
+			for(x=0; x<rowlen; x++) {
+				if(fp[3]==0.0f) {
+					int tot= 0;
+					float r=0.0f, g=0.0f, b=0.0f;
+					
+					EXTEND_PIXEL(row1f, 1);
+					EXTEND_PIXEL(row2f, 2);
+					EXTEND_PIXEL(row3f, 1);
+					EXTEND_PIXEL(row1f+4, 2);
+					EXTEND_PIXEL(row3f+4, 2);
+					if(x!=rowlen-1) {
+						EXTEND_PIXEL(row1f+8, 1);
+						EXTEND_PIXEL(row2f+8, 2);
+						EXTEND_PIXEL(row3f+8, 1);
+					}					
+					if(tot) {
+						fp[0]= r/tot;
+						fp[1]= g/tot;
+						fp[2]= b/tot;
+						fp[3]= 1.0;
+					}
+				}
+				fp+=4; 
+				
+				if(x!=0) {
+					row1f+=4; row2f+=4; row3f+=4;
+				}
+			}
+		}
+	}
+	else if(ibuf->rect) {
 		int *temprect;
 		
 		/* make a copy, to prevent flooding */

Modified: trunk/blender/source/blender/python/api2_2x/Image.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Image.c	2007-12-29 05:16:00 UTC (rev 13039)
+++ trunk/blender/source/blender/python/api2_2x/Image.c	2007-12-29 05:17:19 UTC (rev 13040)
@@ -1,5 +1,5 @@
 /* 
- * $Id: Image.c 11241 2007-07-12 11:51:21Z campbellbarton $
+ * $Id$
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
@@ -243,7 +243,7 @@
 	if (width > 5000 || height > 5000 || width < 1 || height < 1)
 		return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 					"Image width and height must be between 1 and 5000" ) );
-	image = BKE_add_image_size(width, height, name, 0, color);
+	image = BKE_add_image_size(width, height, name, 0, 0, color);
 	if( !image )
 		return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 						"couldn't create PyObject Image_Type" ) );

Modified: trunk/blender/source/blender/python/api2_2x/bpy_data.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/bpy_data.c	2007-12-29 05:16:00 UTC (rev 13039)
+++ trunk/blender/source/blender/python/api2_2x/bpy_data.c	2007-12-29 05:17:19 UTC (rev 13040)
@@ -1,5 +1,5 @@
 /* 
- * $Id: bpy_data.c 12056 2007-09-17 06:11:06Z aligorith $
+ * $Id$
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
@@ -538,7 +538,7 @@
 		break;
 	case ID_IM: 
 	{
-		id = (ID *)BKE_add_image_size(img_width, img_height, name?name:"Image", 0, color);
+		id = (ID *)BKE_add_image_size(img_width, img_height, name?name:"Image", 0, 0, color);
 		if( !id )
 			return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 				"couldn't create PyObject Image_Type" ) );

Modified: trunk/blender/source/blender/render/extern/include/RE_pipeline.h
===================================================================
--- trunk/blender/source/blender/render/extern/include/RE_pipeline.h	2007-12-29 05:16:00 UTC (rev 13039)
+++ trunk/blender/source/blender/render/extern/include/RE_pipeline.h	2007-12-29 05:17:19 UTC (rev 13040)
@@ -206,11 +206,12 @@
 void RE_zbuf_accumulate_vecblur(struct NodeBlurData *nbd, int xsize, int ysize, float *newrect, float *imgrect, float *vecbufrect, float *zbufrect);
 
 /* shaded view or baking options */
-#define RE_BAKE_LIGHT	0
-#define RE_BAKE_ALL		1
-#define RE_BAKE_AO		2
-#define RE_BAKE_NORMALS	3
-#define RE_BAKE_TEXTURE	4
+#define RE_BAKE_LIGHT			0
+#define RE_BAKE_ALL				1
+#define RE_BAKE_AO				2
+#define RE_BAKE_NORMALS			3
+#define RE_BAKE_TEXTURE			4
+#define RE_BAKE_DISPLACEMENT	5
 void RE_Database_Baking(struct Render *re, struct Scene *scene, int type, struct Object *actob);
 
 void RE_DataBase_GetView(struct Render *re, float mat[][4]);


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list