[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43554] trunk/blender/source/blender: Fix #27120: Bake to image used for rendering glitch (bake feedback loop)

Sergey Sharybin sergey.vfx at gmail.com
Fri Jan 20 08:44:03 CET 2012


Revision: 43554
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43554
Author:   nazgul
Date:     2012-01-20 07:43:46 +0000 (Fri, 20 Jan 2012)
Log Message:
-----------
Fix #27120: Bake to image used for rendering glitch (bake feedback loop)

Detect feedback loop and do not bake to images detected in this loop and show
nice warning message in such cases.

It's a way which wouldn't overcomplicate code trying to duplicate images and so
without real benefit.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/object/object_bake.c
    trunk/blender/source/blender/makesdna/DNA_image_types.h
    trunk/blender/source/blender/render/extern/include/RE_shader_ext.h
    trunk/blender/source/blender/render/intern/source/imagetexture.c
    trunk/blender/source/blender/render/intern/source/rendercore.c

Modified: trunk/blender/source/blender/editors/object/object_bake.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_bake.c	2012-01-20 05:11:42 UTC (rev 43553)
+++ trunk/blender/source/blender/editors/object/object_bake.c	2012-01-20 07:43:46 UTC (rev 43554)
@@ -1255,7 +1255,7 @@
 	Main *main;
 	Scene *scene;
 	struct Object *actob;
-	int tot, ready;
+	int result, ready;
 
 	ReportList *reports;
 
@@ -1328,7 +1328,7 @@
 		if(bkr->prev_r_raytrace == 0)
 			bkr->scene->r.mode &= ~R_RAYTRACE;
 
-	if(bkr->tot) {
+	if(bkr->result==BAKE_RESULT_OK) {
 		Image *ima;
 		/* force OpenGL reload and mipmap recalc */
 		for(ima= G.main->image.first; ima; ima= ima->id.next) {
@@ -1355,7 +1355,7 @@
 {
 	BakeRender *bkr= bake_v;
 
-	bkr->tot= RE_bake_shade_all_selected(bkr->re, bkr->scene->r.bake_mode, bkr->actob, NULL, bkr->progress);
+	bkr->result= RE_bake_shade_all_selected(bkr->re, bkr->scene->r.bake_mode, bkr->actob, NULL, bkr->progress);
 	bkr->ready= 1;
 
 	return NULL;
@@ -1377,7 +1377,7 @@
 	RE_Database_Baking(bkr->re, bmain, scene, scene->lay, scene->r.bake_mode, bkr->actob);
 
 	/* baking itself is threaded, cannot use test_break in threads. we also update optional imagewindow */
-	bkr->tot= RE_bake_shade_all_selected(bkr->re, scene->r.bake_mode, bkr->actob, bkr->do_update, bkr->progress);
+	bkr->result= RE_bake_shade_all_selected(bkr->re, scene->r.bake_mode, bkr->actob, bkr->do_update, bkr->progress);
 }
 
 static void bake_update(void *bkv)
@@ -1396,7 +1396,11 @@
 	BakeRender *bkr= bkv;
 	finish_bake_internal(bkr);
 
-	if(bkr->tot==0) BKE_report(bkr->reports, RPT_ERROR, "No objects or images found to bake to");
+	if(bkr->result==BAKE_RESULT_NO_OBJECTS)
+		BKE_report(bkr->reports, RPT_ERROR, "No objects or images found to bake to");
+	else if(bkr->result==BAKE_RESULT_FEEDBACK_LOOP)
+		BKE_report(bkr->reports, RPT_WARNING, "Feedback loop detected");
+
 	MEM_freeN(bkr);
 	G.rendering = 0;
 }
@@ -1513,7 +1517,10 @@
 			}
 			BLI_end_threads(&threads);
 
-			if(bkr.tot==0) BKE_report(op->reports, RPT_ERROR, "No valid images found to bake to");
+			if(bkr.result==BAKE_RESULT_NO_OBJECTS)
+				BKE_report(op->reports, RPT_ERROR, "No valid images found to bake to");
+			else if(bkr.result==BAKE_RESULT_FEEDBACK_LOOP)
+				BKE_report(op->reports, RPT_ERROR, "Feedback loop detected");
 
 			finish_bake_internal(&bkr);
 

Modified: trunk/blender/source/blender/makesdna/DNA_image_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_image_types.h	2012-01-20 05:11:42 UTC (rev 43553)
+++ trunk/blender/source/blender/makesdna/DNA_image_types.h	2012-01-20 07:43:46 UTC (rev 43554)
@@ -120,6 +120,7 @@
 #define IMA_DEPRECATED		64
 #define IMA_OLD_PREMUL		128
 #define IMA_CM_PREDIVIDE	256
+#define IMA_USED_FOR_RENDER	512
 
 /* Image.tpageflag */
 #define IMA_TILES			1

Modified: trunk/blender/source/blender/render/extern/include/RE_shader_ext.h
===================================================================
--- trunk/blender/source/blender/render/extern/include/RE_shader_ext.h	2012-01-20 05:11:42 UTC (rev 43553)
+++ trunk/blender/source/blender/render/extern/include/RE_shader_ext.h	2012-01-20 07:43:46 UTC (rev 43554)
@@ -210,4 +210,8 @@
 struct Image *RE_bake_shade_get_image(void);
 void RE_bake_ibuf_filter(struct ImBuf *ibuf, char *mask, const int filter);
 
+#define BAKE_RESULT_OK			0
+#define BAKE_RESULT_NO_OBJECTS		1
+#define BAKE_RESULT_FEEDBACK_LOOP	2
+
 #endif /* RE_SHADER_EXT_H */

Modified: trunk/blender/source/blender/render/intern/source/imagetexture.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/imagetexture.c	2012-01-20 05:11:42 UTC (rev 43553)
+++ trunk/blender/source/blender/render/intern/source/imagetexture.c	2012-01-20 07:43:46 UTC (rev 43554)
@@ -131,6 +131,8 @@
 			return retval;
 		
 		ibuf= BKE_image_get_ibuf(ima, &tex->iuser);
+
+		ima->flag|= IMA_USED_FOR_RENDER;
 	}
 	if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
 		return retval;
@@ -1441,6 +1443,8 @@
 			return retval;
 		
 		ibuf= BKE_image_get_ibuf(ima, &tex->iuser); 
+
+		ima->flag|= IMA_USED_FOR_RENDER;
 	}
 	if(ibuf==NULL || (ibuf->rect==NULL && ibuf->rect_float==NULL))
 		return retval;
@@ -1812,6 +1816,8 @@
 	
 	if( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
 		ibuf->rect-= (ibuf->x*ibuf->y);
+
+	ima->flag|= IMA_USED_FOR_RENDER;
 }
 
 void ibuf_sample(ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result)

Modified: trunk/blender/source/blender/render/intern/source/rendercore.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/rendercore.c	2012-01-20 05:11:42 UTC (rev 43553)
+++ trunk/blender/source/blender/render/intern/source/rendercore.c	2012-01-20 07:43:46 UTC (rev 43554)
@@ -2440,6 +2440,11 @@
 					if(ibuf->rect_float && !(ibuf->channels==0 || ibuf->channels==4))
 						continue;
 					
+					if(ima->flag & IMA_USED_FOR_RENDER) {
+						ima->id.flag &= ~LIB_DOIT;
+						continue;
+					}
+					
 					/* find the image for the first time? */
 					if(ima->id.flag & LIB_DOIT) {
 						ima->id.flag &= ~LIB_DOIT;
@@ -2584,7 +2589,7 @@
 	BakeShade *handles;
 	ListBase threads;
 	Image *ima;
-	int a, vdone=0, usemask=0;
+	int a, vdone=0, usemask=0, result=BAKE_RESULT_OK;
 	
 	/* initialize render global */
 	R= *re;
@@ -2601,6 +2606,7 @@
 	for(ima= G.main->image.first; ima; ima= ima->id.next) {
 		ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
 		ima->id.flag |= LIB_DOIT;
+		ima->flag&= ~IMA_USED_FOR_RENDER;
 		if(ibuf) {
 			ibuf->userdata = NULL; /* use for masking if needed */
 			if(ibuf->rect_float)
@@ -2659,6 +2665,9 @@
 		if((ima->id.flag & LIB_DOIT)==0) {
 			ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
 
+			if(ima->flag & IMA_USED_FOR_RENDER)
+				result= BAKE_RESULT_FEEDBACK_LOOP;
+
 			if(!ibuf)
 				continue;
 
@@ -2679,7 +2688,10 @@
 	
 	BLI_end_threads(&threads);
 
-	return vdone;
+	if(vdone==0)
+		result= BAKE_RESULT_NO_OBJECTS;
+
+	return result;
 }
 
 struct Image *RE_bake_shade_get_image(void)



More information about the Bf-blender-cvs mailing list