[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15424] branches/soc-2008-mxcurioni/source /blender: soc-2008-mxcurioni: foundations for Freestyle as a render layer - new UI buttons and mode flags , Freestyle API refactoring, modified pipeline to incorporate the new render layer.

Maxime Curioni maxime.curioni at gmail.com
Fri Jul 4 10:00:37 CEST 2008


Revision: 15424
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15424
Author:   mxcurioni
Date:     2008-07-04 09:59:19 +0200 (Fri, 04 Jul 2008)

Log Message:
-----------
soc-2008-mxcurioni: foundations for Freestyle as a render layer - new UI buttons and mode flags, Freestyle API refactoring, modified pipeline to incorporate the new render layer. Compared to previously, the layer functionality is available when selecting 'Blender Internal' as the rendering engine. Freestyle's result is not available in the layer yet. I need to integrate OpenGL offscreen rendering properly (with framebuffer objects) to reach that goal.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp
    branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_scene_types.h
    branches/soc-2008-mxcurioni/source/blender/python/api2_2x/sceneRender.c
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/pipeline.c
    branches/soc-2008-mxcurioni/source/blender/src/buttons_scene.c

Added Paths:
-----------
    branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h

Removed Paths:
-------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/FST_freestyle.h

Copied: branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h (from rev 15037, branches/soc-2008-mxcurioni/source/blender/freestyle/FST_freestyle.h)
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h	                        (rev 0)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h	2008-07-04 07:59:19 UTC (rev 15424)
@@ -0,0 +1,15 @@
+#ifndef FRS_FREESTYLE_H
+#define FRS_FREESTYLE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif	
+	
+	void FRS_prepare(Render* re);
+	void FRS_execute(Render* re, int render_in_layer);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

Deleted: branches/soc-2008-mxcurioni/source/blender/freestyle/FST_freestyle.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/FST_freestyle.h	2008-07-04 02:03:03 UTC (rev 15423)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/FST_freestyle.h	2008-07-04 07:59:19 UTC (rev 15424)
@@ -1,14 +0,0 @@
-#ifndef FRS_FREESTYLE_H
-#define FRS_FREESTYLE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif	
-	
-	void FRS_execute(Render* re);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp	2008-07-04 02:03:03 UTC (rev 15423)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/api.cpp	2008-07-04 07:59:19 UTC (rev 15424)
@@ -27,11 +27,16 @@
 extern "C" {
 #endif
 
+	static Config::Path *pathconfig = NULL;
 	static Controller *controller = NULL;
 	static AppGLWidget *view = NULL;
+
 	
 	void FRS_initialize(){
 		
+		if( pathconfig == NULL )
+			pathconfig = new Config::Path;
+		
 		if( controller == NULL )
 			controller = new Controller;
 		
@@ -41,20 +46,14 @@
 		controller->SetView(view);
 	}
 
-	void FRS_execute(Render* re) {
-		
-		// instanciation
-		Config::Path pathconfig;
-		FRS_initialize();
-		
-		// initialize view dimensions
-		unsigned int width = re->winx;
-		unsigned int height = re->winy;
-		view->setWidth(width);
-		view->setHeight(height);
-		view->_camera->setScreenWidthAndHeight(width, height);
-		
-		// initialize camera
+
+	void FRS_init_view(Render* re){
+		view->setWidth( re->winx );
+		view->setHeight( re->winy );
+		view->_camera->setScreenWidthAndHeight( re->winx, re->winy);
+	}
+
+	void FRS_init_camera(Render* re){
 		Object* maincam_obj = re->scene->camera;
 		Camera *cam = (Camera*) maincam_obj->data;
 
@@ -62,22 +61,23 @@
 			view->_camera->setType(AppGLWidget_Camera::PERSPECTIVE);
 			view->_camera->setHorizontalFieldOfView( M_PI / 180.0f * cam->angle );
 		}
-		else if (cam->type == CAM_ORTHO){
-			view->_camera->setType(AppGLWidget_Camera::ORTHOGRAPHIC);
-			// view->_camera->setFocusDistance does not seem to work
-			// integrate cam->ortho_scale parameter
-		}
+		// else if (cam->type == CAM_ORTHO){
+		// 	view->_camera->setType(AppGLWidget_Camera::ORTHOGRAPHIC);
+		// 	// view->_camera->setFocusDistance does not seem to work
+		// 	// integrate cam->ortho_scale parameter
+		// }
 		
 		Vec camPosition(maincam_obj->obmat[3][0], maincam_obj->obmat[3][1], maincam_obj->obmat[3][2]);
 		Vec camUp( re->viewmat[0][1], re->viewmat[1][1], re->viewmat[2][1]);
 		Vec camDirection( -re->viewmat[0][2], -re->viewmat[1][2], -re->viewmat[2][2]);
 		view->_camera->setPosition(camPosition);
 		view->_camera->setUpVector(camUp);	
-		view->_camera->setViewDirection(camDirection);	
+		view->_camera->setViewDirection(camDirection);
+	}
 	
-		
+	void FRS_scene_3ds_export(Render* re) {
 		// export scene to 3ds format
-		string script_3ds_export = 	pathconfig.getProjectDir() + 
+		string script_3ds_export = 	pathconfig->getProjectDir() + 
 									Config::DIR_SEP + "python" + 
 									Config::DIR_SEP + "3ds_export.py";
 		BPY_run_python_script( const_cast<char *>(script_3ds_export.c_str()) );
@@ -94,9 +94,20 @@
 			cout << "Cannot find" << exported_3ds_file << endl;
 			return;
 		}
+	}
+	
+	void FRS_prepare(Render* re) {
+		FRS_initialize();
 		
+		FRS_init_view(re);
+		FRS_init_camera(re);
+		
+		FRS_scene_3ds_export(re);
+	}
+
+	void FRS_render(Render* re) {
 		// add style module
-		string style_module = pathconfig.getProjectDir() + 
+		string style_module = pathconfig->getProjectDir() + 
 								Config::DIR_SEP + "style_modules" + 
 								Config::DIR_SEP + "contour.py";
 		controller->InsertStyleModule( 0, const_cast<char *>(style_module.c_str()) 	 );
@@ -114,12 +125,20 @@
 		// copy result into render window
 		RenderResult rres;
 		RE_GetResultImage(re, &rres);
-		view->readPixels(0,0,width,height,AppGLWidget::RGBA, rres.rectf );		
+		view->readPixels(0, 0, re->winx, re->winy, AppGLWidget::RGBA, rres.rectf );		
 		re->result->renlay = render_get_active_layer(re, re->result);
 		re->display_draw(re->result, NULL);
 		
 		controller->CloseFile();
 	}
+
+	void FRS_execute(Render* re, bool render_in_layer) {
+		
+		//if(render_in_layer)
+		// set-up offscreen rendering
+		
+		FRS_render(re);
+	}
 	
 #ifdef __cplusplus
 }

Modified: branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_scene_types.h	2008-07-04 02:03:03 UTC (rev 15423)
+++ branches/soc-2008-mxcurioni/source/blender/makesdna/DNA_scene_types.h	2008-07-04 07:59:19 UTC (rev 15424)
@@ -134,6 +134,7 @@
 #define SCE_LAY_EDGE	8
 #define SCE_LAY_SKY		16
 #define SCE_LAY_STRAND	32
+#define SCE_LAY_FRS		64
 	/* flags between 32 and 0x8000 are set to 1 already, for future options */
 
 #define SCE_LAY_ALL_Z		0x8000
@@ -571,6 +572,7 @@
 #define R_ORTHO			0x0008
 #define R_ENVMAP		0x0010
 #define R_EDGE			0x0020
+#define R_EDGE_FRS		0x2000000 // will replace R_EDGE
 #define R_FIELDS		0x0040
 #define R_FIELDSTILL	0x0080
 #define R_RADIO			0x0100

Modified: branches/soc-2008-mxcurioni/source/blender/python/api2_2x/sceneRender.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/python/api2_2x/sceneRender.c	2008-07-04 02:03:03 UTC (rev 15423)
+++ branches/soc-2008-mxcurioni/source/blender/python/api2_2x/sceneRender.c	2008-07-04 07:59:19 UTC (rev 15424)
@@ -3487,6 +3487,10 @@
 	 (getter)RenderLayer_getLayflagBits, (setter)RenderLayer_setLayflagBits,
 	 "Render Edge-enhance in this Layer (only works for Solid faces)",
 	 (void *)SCE_LAY_EDGE},
+	{"enableFreestyle",
+	 (getter)RenderLayer_getLayflagBits, (setter)RenderLayer_setLayflagBits,
+	 "Render Freestyle in this Layer",
+	 (void *)SCE_LAY_FRS},
 	{"enableSky",
 	 (getter)RenderLayer_getLayflagBits, (setter)RenderLayer_setLayflagBits,
 	 "Render Sky or backbuffer in this Layer",

Modified: branches/soc-2008-mxcurioni/source/blender/render/intern/source/pipeline.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/render/intern/source/pipeline.c	2008-07-04 02:03:03 UTC (rev 15423)
+++ branches/soc-2008-mxcurioni/source/blender/render/intern/source/pipeline.c	2008-07-04 07:59:19 UTC (rev 15424)
@@ -70,7 +70,7 @@
 
 #endif /* disable yafray */
 
-#include "FST_freestyle.h"
+#include "FRS_freestyle.h"
 
 
 /* internal */
@@ -1621,7 +1621,7 @@
 
 static void do_render_3d(Render *re)
 {
-	
+	RenderLayer *rl;
 //	re->cfra= cfra;	/* <- unused! */
 	
 	/* make render verts/faces/halos/lamps */
@@ -1632,6 +1632,17 @@
 	
 	threaded_tile_processor(re);
 	
+	/* Freestyle */
+	if( re->r.mode & R_EDGE_FRS ) {
+		for(rl = re->result->layers.first; rl; rl= rl->next) {
+			if(rl->layflag & SCE_LAY_FRS) {
+				printf("Freestyle as a render layer\n");
+				FRS_prepare(re);
+				FRS_execute(re,1);
+			}
+		}
+	}
+	
 	/* do left-over 3d post effects (flares) */
 	if(re->flag & R_HALO)
 		if(!re->test_break())
@@ -2208,9 +2219,12 @@
 	Mat4Invert(mat, re->scene->camera->obmat);
 	RE_SetView(re, mat);
 	
+	// Freestyle initialization
+	FRS_prepare(re);
+	
 	// run Freestyle
 	re->i.starttime = PIL_check_seconds_timer();
-	FRS_execute(re);
+	FRS_execute(re, 0);
 	re->i.lastframetime = PIL_check_seconds_timer()- re->i.starttime;
 	re->stats_draw(&re->i);
 	

Modified: branches/soc-2008-mxcurioni/source/blender/src/buttons_scene.c
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/src/buttons_scene.c	2008-07-04 02:03:03 UTC (rev 15423)
+++ branches/soc-2008-mxcurioni/source/blender/src/buttons_scene.c	2008-07-04 07:59:19 UTC (rev 15424)
@@ -2108,7 +2108,8 @@
 	/* Toon shading buttons */
 	uiBlockBeginAlign(block);
 	uiDefButBitI(block, TOG, R_EDGE, B_NOP,"Edge",   115, 89, 60, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon Edge-enhance");
-	uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings", 175, 89, 135, 20, "Display Edge settings");
+	uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings", 175, 89, 75, 20, "Display Edge settings");
+	uiDefButBitI(block, TOG, R_EDGE_FRS, B_NOP,"Freestyle",   250, 89, 60, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Freestyle");
 	uiBlockEndAlign(block);
 	
 	uiBlockBeginAlign(block);
@@ -3384,9 +3385,11 @@
 	uiDefButBitI(block, TOG, SCE_LAY_HALO, B_NOP,"Halo",	95,  85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Render Halos in this Layer (on top of Solid)");	
 	uiDefButBitI(block, TOG, SCE_LAY_ZTRA, B_NOP,"Ztra",	135, 85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Render Z-Transparent faces in this Layer (On top of Solid and Halos)");	
 	uiDefButBitI(block, TOG, SCE_LAY_SKY, B_NOP,"Sky",		175, 85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Render Sky or backbuffer in this Layer");	
-	uiDefButBitI(block, TOG, SCE_LAY_EDGE, B_NOP,"Edge",	215, 85, 45, 20, &srl->layflag, 0, 0, 0, 0, "Render Edge-enhance in this Layer (only works for Solid faces)");	
-	uiDefButBitI(block, TOG, SCE_LAY_STRAND, B_NOP,"Strand",260, 85, 50, 20, &srl->layflag, 0, 0, 0, 0, "Render Strands in this Layer");	
+	uiDefButBitI(block, TOG, SCE_LAY_EDGE, B_NOP,"Edge",	215, 85, 25, 20, &srl->layflag, 0, 0, 0, 0, "Render Edge-enhance in this Layer (only works for Solid faces)");
+	uiDefButBitI(block, TOG, SCE_LAY_FRS, B_NOP,"FrSt",	240, 85, 30, 20, &srl->layflag, 0, 0, 0, 0, "Render Freestyle in this Layer");	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list