[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19587] branches/soc-2008-mxcurioni/source /blender: SUMMARY:

Maxime Curioni maxime.curioni at gmail.com
Tue Apr 7 20:38:23 CEST 2009


Revision: 19587
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19587
Author:   mxcurioni
Date:     2009-04-07 20:38:23 +0200 (Tue, 07 Apr 2009)

Log Message:
-----------
SUMMARY:
Freestyle's pipeline is now fully controllable at the layer level. It can be used:
 - in any render layer
 - with as many style modules per layer

DETAILS:
Freestyle usage has not changed:
  - all the configuration happens in the "Freestyle" render panel, after it is enabled in the "Output" panel with the 'Freestyle' toggle.
  - each render layer can choose to render Freestyle strokes by togglingo on 'FrSt' (in the "Render Layers" panel)
  - it is fully compatible with compositor nodes

In the "Freestyle" panel, a render layer is selected via the menu list next to the "Render Layer:" label. The options displayed below are those of the currently selected render layer (and are not global to all render layers, as was previously the case).

Style modules are added by pressing the lower button "Add style module". Once added, the following operations are possible:
- deletion (cross)
- reordering (up/down arrows)
- toggling of display (check)

The order of the style modules follows Freestyle's original convention: the modules in the list from top to bottom are respectively the first to the last composited in the render layer. For example, if the module list is "contour" followed by "cartoon", the "cartoon" strokes are rendered on top of the "contour" strokes.

The "Freestyle" panel is constantly synchronized with the "Render Layers" panel: if render layers are added, deleted or toggled off display, Freestyle will take note of the changes.

The current pipeline works as follows:

----------------------------------------------------------------------------------------------
for every scene that is being rendered
	if Freestyle is enabled globally
	
		Freestyle is initialized
		camera and view settings are transferred from Blender to Freestyle
		
		for every render layer
			if: - layer is enabled 
			    - layer enabled Freestyle
			    - the number of displayed style modules is non-zero
				
				canvas is cleared
				geometry is transferred from Blender to Freestyle
				settings are fixed for current iteration
				view map is calculated
				
				strokes are computed in the canvas (based on view map and style modules)
				strokes are rendered in separate Blender scene
				
				scene is composited in current layer
----------------------------------------------------------------------------------------------

A number of changes were made on the codebase:
- the rendering interface between Freestyle and Blender was simplified. The following naming convention was used: functions that are called from within Blender pipeline are prefixed with 'FRS_', while the variables are prefixed with 'freestyle_'
- Freestyle data structures that were put in Blender's render pipeline were removed
- Freestyle cleans up its data structures on Blender exit and shouldn't leak memory
- to ease the configuration in the "Freestyle" panel, a centralized configuration data structure was used and can be easily extended

LIMITATIONS
Even though the current commit is stable and achieves the intended result, it is not as efficient as it could be:
- the canvas and the style modules are at cleared at each layer-level render
- geometry is reloaded at each frame and is duplicated across render layers

This revision clarifies my understanding of the future role of the view map in the compositor. Unfortunately, contrary to what the original proposal said, it is impossible to provide the view map as a render pass because render passes are defined (RE_pipeline.h) as raw floating-point rects. We will have to determine whether or not to extend the notion of render pass to fully integrate the view map in the compositor.

Modified Paths:
--------------
    branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/FRS_freestyle.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/BlenderFileLoader.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/scene_graph/BlenderFileLoader.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BlenderStrokeRenderer.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/BlenderStrokeRenderer.h
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Canvas.cpp
    branches/soc-2008-mxcurioni/source/blender/freestyle/intern/stroke/Canvas.h
    branches/soc-2008-mxcurioni/source/blender/include/butspace.h
    branches/soc-2008-mxcurioni/source/blender/render/intern/include/render_types.h
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/convertblender.c
    branches/soc-2008-mxcurioni/source/blender/render/intern/source/rendercore.c
    branches/soc-2008-mxcurioni/source/blender/src/buttons_scene.c
    branches/soc-2008-mxcurioni/source/blender/src/usiblender.c

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h	2009-04-07 17:54:56 UTC (rev 19586)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/FRS_freestyle.h	2009-04-07 18:38:23 UTC (rev 19587)
@@ -8,23 +8,44 @@
 extern "C" {
 #endif	
 	
-	extern char style_module[255];
-	extern int freestyle_flags;
-	extern float freestyle_sphere_radius;
-	extern float freestyle_dkr_epsilon;
+	typedef struct StyleModuleConf {
+		struct StyleModuleConf *next, *prev;
+		
+		char module_path[255];
+		short is_displayed;
+	} StyleModuleConf;
 	
+	
+	extern short freestyle_is_initialized;
+	
 	extern float freestyle_fovyradian;
 	extern float freestyle_viewpoint[3];
 	extern float freestyle_mv[4][4];
 	extern float freestyle_proj[4][4];
 	extern int freestyle_viewport[4];
 	
+	extern short freestyle_current_layer_number;
+	extern char* freestyle_current_module_path;
+	extern SceneRenderLayer* freestyle_current_layer;
+	extern ListBase* freestyle_modules;
+	extern int* freestyle_flags;
+	extern float* freestyle_sphere_radius;
+	extern float* freestyle_dkr_epsilon;
+	
+	// Rendering
 	void FRS_initialize();
-	void FRS_prepare(Render* re);
-	void FRS_render_Blender(Render* re);
-	void FRS_composite_result(Render* re, SceneRenderLayer* srl);
 	void FRS_add_Freestyle(Render* re);
+	void FRS_exit();
 	
+	// Panel configuration
+	void FRS_select_layer( SceneRenderLayer* srl );
+	void FRS_delete_layer( SceneRenderLayer* srl, short isDestructor );
+	void FRS_add_module();
+	void FRS_delete_module(void *module_index_ptr, void *unused);
+	void FRS_move_up_module(void *module_index_ptr, void *unused);
+	void FRS_move_down_module(void *module_index_ptr, void *unused);
+	void FRS_set_module_path(void *module_index_ptr, void *unused);
+	
 #ifdef __cplusplus
 }
 #endif

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp	2009-04-07 17:54:56 UTC (rev 19586)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.cpp	2009-04-07 18:38:23 UTC (rev 19587)
@@ -175,10 +175,10 @@
   _Canvas->setViewer(_pView);
 }
 
-int Controller::LoadMesh(Render *re)
+int Controller::LoadMesh(Render *re, SceneRenderLayer* srl)
 {
   
-  BlenderFileLoader loader(re);
+  BlenderFileLoader loader(re, srl);
   
   _Chrono.start();
   
@@ -640,11 +640,12 @@
   resetModified();
 }
 
-void Controller::RenderBlender(Render *re) {
+Render* Controller::RenderStrokes(Render *re) {
 	BlenderStrokeRenderer* blenderRenderer = new BlenderStrokeRenderer;
   	_Canvas->Render( blenderRenderer );
-	blenderRenderer->RenderScene(re);
+	Render* freestyle_render = blenderRenderer->RenderScene(re);
 	blenderRenderer->Close();
+	return freestyle_render;
 }
 
 void Controller::InsertStyleModule(unsigned index, const char *iFileName)

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.h
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.h	2009-04-07 17:54:56 UTC (rev 19586)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/Controller.h	2009-04-07 18:38:23 UTC (rev 19587)
@@ -57,6 +57,7 @@
 #endif
 
 	#include "render_types.h"
+	#include "DNA_scene_types.h"
 
 #ifdef __cplusplus
 }
@@ -73,15 +74,15 @@
   //soc
 	void init_options();
 
-	int  LoadMesh( Render *re );
+  int  LoadMesh( Render *re, SceneRenderLayer* srl );
   int  Load3DSFile(const char *iFileName);
   void CloseFile();
   void ComputeViewMap();
   void ComputeSteerableViewMap();
   void saveSteerableViewMapImages();
   void toggleEdgeTesselationNature(Nature::EdgeNature iNature);
-  void RenderBlender(Render *re);
-	void DrawStrokes();
+  void DrawStrokes();
+  Render* RenderStrokes(Render *re);
   void SwapStyleModules(unsigned i1, unsigned i2);
   void InsertStyleModule(unsigned index, const char *iFileName);
   void AddStyleModule(const char *iFileName);

Modified: branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/FRS_freestyle.cpp
===================================================================
--- branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/FRS_freestyle.cpp	2009-04-07 17:54:56 UTC (rev 19586)
+++ branches/soc-2008-mxcurioni/source/blender/freestyle/intern/app_blender/FRS_freestyle.cpp	2009-04-07 18:38:23 UTC (rev 19587)
@@ -4,70 +4,108 @@
 #include "AppCanvas.h"
 
 #include <iostream>
+#include <map>
+#include <set>
+using namespace std;
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include "../../FRS_freestyle.h"
+#include "MEM_guardedalloc.h"
 
 #include "DNA_camera_types.h"
+#include "DNA_listBase.h"
 #include "DNA_scene_types.h"
 
-#include "render_types.h"
-#include "renderpipeline.h"
-#include "pixelblending.h"
-
+#include "BKE_global.h"
 #include "BLI_blenlib.h"
 #include "BIF_renderwin.h"
 #include "BPY_extern.h"
 
-#ifdef __cplusplus
-}
-#endif
+#include "render_types.h"
+#include "renderpipeline.h"
+#include "pixelblending.h"
 
-using namespace std;
+#include "../../FRS_freestyle.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
+	// Freestyle configuration
+	short freestyle_is_initialized = 0;
 	static Config::Path *pathconfig = NULL;
 	static Controller *controller = NULL;
 	static AppView *view = NULL;
 
-	char style_module[255] = "";
-	int freestyle_flags;
-	float freestyle_sphere_radius = 1.0;
-	float freestyle_dkr_epsilon = 0.001;
-	
+	// camera information
 	float freestyle_viewpoint[3];
 	float freestyle_mv[4][4];
 	float freestyle_proj[4][4];
 	int freestyle_viewport[4];
+	
+	// Panel configuration
+	short freestyle_current_layer_number = 0;
+	char* freestyle_current_module_path = NULL;
+	SceneRenderLayer* freestyle_current_layer = NULL;
 
+	ListBase* freestyle_modules;
+	int* freestyle_flags;
+	float* freestyle_sphere_radius;
+	float* freestyle_dkr_epsilon;
+	
+	class FreestylePanelConfigurationData {
+	public:
+		set<SceneRenderLayer*> layers;
+		map<SceneRenderLayer*, ListBase*> modules;
+		map<SceneRenderLayer*, int*> flags;
+		map<SceneRenderLayer*, float*> sphere_radius;
+		map<SceneRenderLayer*, float*> dkr_epsilon;
+		
+		FreestylePanelConfigurationData() {}
+		~FreestylePanelConfigurationData() {
+			set<SceneRenderLayer*>::iterator it;
+			
+			for( it=layers.begin(); it!=layers.end(); it++)
+				FRS_delete_layer( *it, 1 );
+		}
+	};
+	static FreestylePanelConfigurationData* panelConfig;
+	
+	string default_module_path;
+
+	//=======================================================
+	//   Initialization 
+	//=======================================================
+
 	void FRS_initialize(){
 		
-		if( pathconfig == NULL )
+		if( !freestyle_is_initialized ) {
+
 			pathconfig = new Config::Path;
-		
-		if( controller == NULL )
 			controller = new Controller;
-		
-		if( view == NULL ) {
 			view = new AppView;
 			controller->setView(view);
+			
+			panelConfig = new FreestylePanelConfigurationData;
+			
+			default_module_path = pathconfig->getProjectDir() + Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py";
+			FRS_select_layer( (SceneRenderLayer*) BLI_findlink(&G.scene->r.layers, G.scene->r.actlay) );
+			
+			freestyle_is_initialized = 1;
 		}
 		
-		if( strlen(style_module) == 0 ){
-			string path( pathconfig->getProjectDir() +  Config::DIR_SEP + "style_modules" + Config::DIR_SEP + "contour.py" );
-			strcpy( style_module, path.c_str() );
-		}
-		
 	}
+	
+	void FRS_exit() {
+		delete pathconfig;
+		delete controller;
+		delete view;
+		delete panelConfig;
+	}
 
+	//=======================================================
+	//   Rendering 
+	//=======================================================
 
-	void FRS_init_view(Render* re){
+	void init_view(Render* re){
 		int width = re->scene->r.xsch;
 		int height = re->scene->r.ysch;
 		
@@ -79,7 +117,7 @@
 		view->setHeight( height );
 	}
 
-	void FRS_init_camera(Render* re){
+	void init_camera(Render* re){
 		Object* maincam_obj = re->scene->camera;
 		Camera *cam = (Camera*) maincam_obj->data;
 
@@ -115,29 +153,34 @@
 	}
 
 	
-	void FRS_prepare(Render* re) {
+	void prepare(Render* re, SceneRenderLayer* srl ) {
 		
-		// init
-		FRS_initialize();
-		FRS_init_view(re);
-		FRS_init_camera(re);
+		// clear canvas
 		controller->Clear();
 
 		// load mesh
-		if( controller->LoadMesh(re) ) // returns if scene cannot be loaded or if empty
+		if( controller->LoadMesh(re, srl) ) // returns if scene cannot be loaded or if empty
 			return;
 		
-		// add style module
-			cout << "\n===  Rendering options  ===" << endl;
-		cout << "Module: " << style_module << endl;
-		controller->InsertStyleModule( 0, style_module );
-		controller->toggleLayer(0, true);
+		// add style modules
+		cout << "\n===  Rendering options  ===" << endl;
+		cout << "Modules :"<< endl;
+		int layer_count = 0;
+		for( StyleModuleConf* module_conf = (StyleModuleConf *)panelConfig->modules[srl]->first; module_conf; module_conf = module_conf->next ) {
+			if( module_conf->is_displayed ) {
+				cout << "  " << layer_count+1 << ": " << module_conf->module_path << endl;
+				controller->InsertStyleModule( layer_count, module_conf->module_path );
+				controller->toggleLayer(layer_count, true);
+				layer_count++;
+			}
+		}	
+		cout << endl;
 		
 		// set parameters
-		controller->setSphereRadius(freestyle_sphere_radius);
-		controller->setComputeRidgesAndValleysFlag((freestyle_flags & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false);
-		controller->setComputeSuggestiveContoursFlag((freestyle_flags & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false);
-		controller->setSuggestiveContourKrDerivativeEpsilon(freestyle_dkr_epsilon);
+		controller->setSphereRadius(*panelConfig->sphere_radius[srl]);
+		controller->setComputeRidgesAndValleysFlag((*panelConfig->flags[srl] & FREESTYLE_RIDGES_AND_VALLEYS_FLAG) ? true : false);
+		controller->setComputeSuggestiveContoursFlag((*panelConfig->flags[srl] & FREESTYLE_SUGGESTIVE_CONTOURS_FLAG) ? true : false);
+		controller->setSuggestiveContourKrDerivativeEpsilon(*panelConfig->dkr_epsilon[srl]);
 
 		cout << "Sphere radius : " << controller->getSphereRadius() << endl;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list