[Bf-committers] DOF patch

Alexander Ewering blender at instinctive.de
Sun Apr 17 22:32:33 CEST 2005


Finally, here it is... instinctive-blender's DOF (Depth of Field) using
strubi's zblur.c plugin, integrated into the render pipeline, with
additional features Autofocus and Focus Lag, and some funky UI.

Will write / provide existing docs shortly.

zblur.c goes into source/blender/render/intern/source/
zblur.h goes into source/blender/render/intern/include/

Didn't know how to make cvs diff accept those...

Ton, please review and commit. Don't forget Unified Renderer :)

| alexander ewering              instinctive mediaworks
| ae[@]instinctive[.]de   http://www[.]instinctive[.]de
-------------- next part --------------
? cscope.out
? dof.patch
? run
? t
? obj/linux-glibc2.3.2-i386
? source/blender/render/intern/include/zblur.h
? source/blender/render/intern/source/zblur.c
Index: source/blender/blenloader/intern/readfile.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/blenloader/intern/readfile.c,v
retrieving revision 1.113
diff -u -r1.113 readfile.c
--- source/blender/blenloader/intern/readfile.c	17 Apr 2005 17:43:06 -0000	1.113
+++ source/blender/blenloader/intern/readfile.c	17 Apr 2005 20:17:39 -0000
@@ -4699,6 +4699,15 @@
 				}
 			}
 		}
+		Camera *ca;
+		
+		for (ca= main->camera.first; ca; ca= ca->id.next) {
+			ca->focus= 0.9;
+			ca->zgamma= 1.0;
+			ca->zblur= 10.0;
+			ca->zmin= 0.8;
+			ca->flag |= CAM_AUTOFOCUS;
+		}		
 	}
 	
 	/* don't forget to set version number in blender.c! */
Index: source/blender/include/butspace.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/include/butspace.h,v
retrieving revision 1.36
diff -u -r1.36 butspace.h
--- source/blender/include/butspace.h	16 Apr 2005 14:01:49 -0000	1.36
+++ source/blender/include/butspace.h	17 Apr 2005 20:17:41 -0000
@@ -398,6 +398,7 @@
 
 /* *********************** */
 #define B_CAMBUTS		2500
+#define B_ZMIN			2401
 
 /* *********************** */
 #define B_MBALLBUTS		2600
Index: source/blender/makesdna/DNA_camera_types.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_camera_types.h,v
retrieving revision 1.10
diff -u -r1.10 DNA_camera_types.h
--- source/blender/makesdna/DNA_camera_types.h	30 Jan 2005 11:25:27 -0000	1.10
+++ source/blender/makesdna/DNA_camera_types.h	17 Apr 2005 20:17:41 -0000
@@ -54,6 +54,11 @@
 	float YF_dofdist, YF_aperture;
 	short YF_bkhtype, YF_bkhbias;
 	float YF_bkhrot;
+
+	/* integrated DOF */
+	float zmin, focus, focusx, focusy, zgamma, zsigma, zblur;
+	float zlag;
+	int oldzfocus, pad;
 	
 	struct Ipo *ipo;
 	
@@ -71,6 +76,10 @@
 #define CAM_SHOWMIST	2
 /* yafray: dof sampling switch */
 #define CAM_YF_NO_QMC	4
+#define CAM_SHOWFOCUS   8
+
+#define CAM_DOF			16
+#define CAM_AUTOFOCUS	32
 
 #ifdef __cplusplus
 }
Index: source/blender/makesdna/DNA_scene_types.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_scene_types.h,v
retrieving revision 1.37
diff -u -r1.37 DNA_scene_types.h
--- source/blender/makesdna/DNA_scene_types.h	17 Mar 2005 21:31:48 -0000	1.37
+++ source/blender/makesdna/DNA_scene_types.h	17 Apr 2005 20:17:42 -0000
@@ -303,6 +303,7 @@
 #define R_GAUSS      	0x20000
 #define R_FBUF			0x40000
 #define R_THREADS		0x80000
+#define R_DOF			0x100000
 
 /* yafray: renderer flag (not only exclusive to yafray) */
 #define R_INTERN	0
Index: source/blender/render/intern/source/initrender.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/render/intern/source/initrender.c,v
retrieving revision 1.54
diff -u -r1.54 initrender.c
--- source/blender/render/intern/source/initrender.c	11 Apr 2005 17:55:20 -0000	1.54
+++ source/blender/render/intern/source/initrender.c	17 Apr 2005 20:17:47 -0000
@@ -1065,6 +1065,10 @@
 				if(RE_local_test_break()==0) add_halo_flare();
 			}
 
+			if( (R.r.mode & R_DOF)) {
+				if(RE_local_test_break()==0) add_zblur();
+			}
+
 			if(R.r.mode & R_MBLUR) {
 				add_to_blurbuf(blur);
 			}
Index: source/blender/src/butspace.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/butspace.c,v
retrieving revision 1.33
diff -u -r1.33 butspace.c
--- source/blender/src/butspace.c	21 Mar 2005 00:47:21 -0000	1.33
+++ source/blender/src/butspace.c	17 Apr 2005 20:17:48 -0000
@@ -288,7 +288,7 @@
 		do_fontbuts(event);
 	}
 	else if(event<=B_CAMBUTS) {
-		;
+		do_cambuts(event);
 	}
 	else if(event<=B_MBALLBUTS) {
 		do_mballbuts(event);
Index: source/blender/src/buttons_editing.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/buttons_editing.c,v
retrieving revision 1.107
diff -u -r1.107 buttons_editing.c
--- source/blender/src/buttons_editing.c	17 Apr 2005 18:00:32 -0000	1.107
+++ source/blender/src/buttons_editing.c	17 Apr 2005 20:17:54 -0000
@@ -1343,10 +1343,11 @@
 
 	uiDefButF(block, NUM,REDRAWVIEW3D, "DrawSize:", 470,90,160,20, &cam->drawsize, 0.1*grid, 10.0, 10, 0, "Specify the drawsize of the camera");
 
-	uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,49,61,40, &cam->type, 0, 0, 0, 0, "Render orthogonally");
+	uiDefButS(block, TOG, REDRAWVIEW3D, "Ortho", 470,29,61,60, &cam->type, 0, 0, 0, 0, "Render orthogonally");
 	uiBlockBeginAlign(block);
 	uiDefButS(block, TOG|BIT|0,REDRAWVIEW3D, "ShowLimits", 533,69,97,20, &cam->flag, 0, 0, 0, 0, "Draw the field of view");
 	uiDefButS(block, TOG|BIT|1,REDRAWVIEW3D, "Show Mist", 533,49,97,20, &cam->flag, 0, 0, 0, 0, "Draw a line that indicates the mist area");
+	uiDefButS(block, TOG|BIT|3,REDRAWVIEW3D, "ShowFocus", 533,29,97,20, &cam->flag, 0, 0, 0, 0, "Draw a crosshair at the autofocus point in camera view");	
 	uiBlockEndAlign(block);
 }
 
@@ -1378,6 +1379,46 @@
 
 }
 
+static void editing_panel_camera_dof(Object *ob, Camera *cam)
+{
+	uiBlock *block;
+
+	block= uiNewBlock(&curarea->uiblocks, "editing_panel_camera_dof", UI_EMBOSS, UI_HELV, curarea->win);
+	if(uiNewPanel(curarea, block, "Depth of Field", "DOF", 320, 0, 318, 204)==0) return;
+
+	uiDefButS(block, TOG|BIT|4,REDRAWVIEW3D, "DOF", 340,178,110,20, &cam->flag, 0, 0, 0, 0, "Use depth of field");		
+
+	uiDefButF(block, NUM,REDRAWVIEW3D, "Focus:", 340,147,110,20, &cam->focus, cam->zmin, 1.0, 0, 0, "Specify the focus distance");
+	uiDefButF(block, NUM,B_ZMIN, "ZMin:", 340,125,110,20, &cam->zmin, 0.0, 1.0, 0, 0, "Specify the minimum distance that can be focussed");				
+	uiDefButF(block, NUM,REDRAWVIEW3D, "Blur:", 340,103,110,20, &cam->zblur, 1.0, 100.0, 0, 0, "Specify the maximum blur radius");		
+	uiDefButF(block, NUM,REDRAWVIEW3D, "BG Gamma:", 340,81,110,20, &cam->zgamma, 0.05, 2.0, 0, 0, "");
+	uiDefButF(block, NUM,REDRAWVIEW3D, "FG Sigma:", 340,59,110,20, &cam->zsigma, 0.0, 20.0, 0, 0, "");
+
+	uiDefButS(block, TOG|BIT|5,REDRAWVIEW3D, "AutoFocus", 460,178,110,20, &cam->flag, 0, 0, 0, 0, "Use autofocus");				
+
+	uiDefButF(block, NUM,REDRAWVIEW3D, "Focus X:", 460,147,110,20, &cam->focusx, -1.0, 1.0, 0, 0, "Specify the focus point in the field of view");
+	uiDefButF(block, NUM,REDRAWVIEW3D, "Focus Y:", 460,125,110,20, &cam->focusy, -1.0, 1.0, 0, 0, "Specify the focus point in the field of view");
+	uiDefButF(block, NUM,REDRAWVIEW3D, "Focus Lag:", 460,103,110,20, &cam->zlag, 0.0, 50.0, 0, 0, "Number of frames focus motor lags behind");			
+}
+
+/* **************************** CAMERA *************************** */
+
+void do_cambuts(unsigned short event)
+{
+	Object *ob;
+	Camera *cam;
+	
+	ob= OBACT;
+	if (ob==0) return;
+	cam= ob->data;
+
+	switch(event) {
+	case B_ZMIN:
+		if (cam->focus < cam->zmin) cam->focus= cam->zmin;
+		allqueue(REDRAWBUTSEDIT, 0);
+		break;
+	}
+}
 
 /* *************************** MBALL ******************************** */
 
@@ -2786,6 +2827,7 @@
 		cam= ob->data;
 		editing_panel_links(ob); // no editmode!
 		editing_panel_camera_type(ob, cam);
+		editing_panel_camera_dof(ob, cam);				
 		/* yafray: extra panel for dof parameters */
 		if (G.scene->r.renderer==R_YAFRAY) editing_panel_camera_yafraydof(ob, cam);
 		break;
Index: source/blender/src/buttons_scene.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/buttons_scene.c,v
retrieving revision 1.79
diff -u -r1.79 buttons_scene.c
--- source/blender/src/buttons_scene.c	31 Mar 2005 18:49:52 -0000	1.79
+++ source/blender/src/buttons_scene.c	17 Apr 2005 20:17:57 -0000
@@ -1093,6 +1093,8 @@
 	uiDefButS(block, ROW,800,"Premul",	405,13,50,20,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
 	uiDefButS(block, ROW,800,"Key",		456,13,35,20,&G.scene->r.alphamode,3.0,2.0, 0, 0, "Alpha and colour values remain unchanged");
 	uiBlockEndAlign(block);
+
+	uiDefButI(block, TOG|BIT|20,800,"DOF",		500,13,35,20,&G.scene->r.mode,0,0, 0, 0, "Apply Depth of Field (Ton, move elsewhere!)");
 	
 	if(G.scene->r.mode & R_RAYTRACE)
 		uiDefButS(block, MENU, B_DIFF,"Octree resolution %t|64 %x64|128 %x128|256 %x256|512 %x512",	496,13,64,20,&G.scene->r.ocres,0.0,0.0, 0, 0, "Octree resolution for ray tracing");
Index: source/blender/src/drawview.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/drawview.c,v
retrieving revision 1.124
diff -u -r1.124 drawview.c
--- source/blender/src/drawview.c	11 Apr 2005 17:55:20 -0000	1.124
+++ source/blender/src/drawview.c	17 Apr 2005 20:18:02 -0000
@@ -56,6 +56,7 @@
 
 #include "DNA_action_types.h"
 #include "DNA_armature_types.h"
+#include "DNA_camera_types.h"
 #include "DNA_constraint_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_group_types.h"
@@ -842,12 +843,37 @@
 	float x1, x2, y1, y2;
 	float x3, y3, x4, y4;
 	rcti viewborder;
+	Camera *cam;
+	float fx, fy;
 	
 	calc_viewborder(G.vd, &viewborder);
 	x1= viewborder.xmin;
 	y1= viewborder.ymin;
 	x2= viewborder.xmax;
 	y2= viewborder.ymax;
+
+	if (G.scene->camera) {
+		cam= G.scene->camera->data;	
+		if ((cam->flag & CAM_SHOWFOCUS) && (cam->flag & CAM_DOF) && (cam->flag & CAM_AUTOFOCUS)) {
+			setlinestyle(0);
+			cpack(0xFFFFFF);
+			fx= (x2+x1)/2.0 + cam->focusx*((x2-x1)/2.0);
+			fy= (y2+y1)/2.0 + cam->focusy*((y2-y1)/2.0);
+			glBegin(GL_LINES);
+			glVertex2f(fx-2, fy);
+			glVertex2f(fx-5, fy);
+			
+			glVertex2f(fx+2, fy);
+			glVertex2f(fx+5, fy);
+			
+			glVertex2f(fx, fy-2);
+			glVertex2f(fx, fy-5);		
+			
+			glVertex2f(fx, fy+2);
+			glVertex2f(fx, fy+5);		
+			glEnd();
+		}
+	}
 
 	/* passepartout, in color of backdrop minus 50 */
 	if(G.scene->r.scemode & R_PASSEPARTOUT) {
Index: source/blender/src/editview.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/editview.c,v
retrieving revision 1.58
diff -u -r1.58 editview.c
--- source/blender/src/editview.c	11 Apr 2005 19:31:05 -0000	1.58
+++ source/blender/src/editview.c	17 Apr 2005 20:18:04 -0000
@@ -46,6 +46,7 @@
 #include "DNA_armature_types.h"
 #include "DNA_meta_types.h"
 #include "DNA_mesh_types.h"
+#include "DNA_camera_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_object_types.h"
@@ -772,6 +773,24 @@
 		VECCOPY(fp, oldcurs);
 	}
 	
+}
+
+void set_autofocus(Camera *cam)
+{
+	rcti viewborder;
+	short mval[2];
+	
+	calc_viewborder(G.vd, &viewborder);
+	getmouseco_areawin(mval);	
+	
+	cam->focusx= (-1.0+(((float)mval[0]-(float)viewborder.xmin)/((float)viewborder.xmax-(float)viewborder.xmin))*2);
+	cam->focusy= (-1.0+(((float)mval[1]-(float)viewborder.ymin)/((float)viewborder.ymax-(float)viewborder.ymin))*2);	
+	
+	CLAMP(cam->focusx, -1.0, 1.0);
+	CLAMP(cam->focusy, -1.0, 1.0);	
+	
+	allqueue(REDRAWBUTSEDIT, 0);
+	allqueue(REDRAWVIEW3D, 0);
 }
 
 void deselectall(void)	/* is toggle */
Index: source/blender/src/space.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/space.c,v
retrieving revision 1.247
diff -u -r1.247 space.c
--- source/blender/src/space.c	17 Apr 2005 15:50:52 -0000	1.247
+++ source/blender/src/space.c	17 Apr 2005 20:18:13 -0000
@@ -1211,9 +1211,11 @@
 				else if((G.qual==LR_SHIFTKEY))
 					fly();
 				else {
-						set_faceselect();
-					}
-				
+					if ( (G.vd->persp==2) &&
+					     OBACT && (OBACT == G.vd->camera) ) {
+						set_autofocus(G.vd->camera->data);
+					} else set_faceselect();
+				}				
 				break;
 			case GKEY:
 				/* RMGRP if(G.qual & LR_CTRLKEY) add_selected_to_group();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zblur.c
Type: text/x-csrc
Size: 18331 bytes
Desc: 
Url : http://projects.blender.org/pipermail/bf-committers/attachments/20050417/9f2c762b/zblur-0001.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zblur.h
Type: text/x-chdr
Size: 1625 bytes
Desc: 
Url : http://projects.blender.org/pipermail/bf-committers/attachments/20050417/9f2c762b/zblur-0001.h


More information about the Bf-committers mailing list