Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2014-01-28 18:24:59 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2014-10-02 12:52:13 +0400
commitdd9c53b312a62f1cc87e26cab3fde0c568c14844 (patch)
treef8e18efe9794aadd892386668b303b637e394a18 /source/blender/freestyle/intern
parent6bde5381bb7c275cb9005babaf455bdc8ff62f4e (diff)
Freestyle: View map caching.
New render layer option named "View map cache" is added to reuse a previously computed view map for subsequent rendering. The cache is automatically updated when the mesh geometry of the input 3D scene has been changed. This functionality offers a major performance boost for Freestyle animation rendering when camera-space mesh geometry is static, as well as for repeated still renders with updates of line stylization options. Although the "View map cache" toggle is a render layer option, the cache memory is shared by all render layers and scenes. This means that if Freestyle is used for two or more render layers (possibly in different scenes through the compositor), then the cached view map for one render layer is replaced by a new view map for another render layer and hence no performance gain is expected.
Diffstat (limited to 'source/blender/freestyle/intern')
-rw-r--r--source/blender/freestyle/intern/application/Controller.cpp83
-rw-r--r--source/blender/freestyle/intern/application/Controller.h11
-rw-r--r--source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp15
-rw-r--r--source/blender/freestyle/intern/scene_graph/SceneHash.cpp39
-rw-r--r--source/blender/freestyle/intern/scene_graph/SceneHash.h67
5 files changed, 177 insertions, 38 deletions
diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp
index 176199600ac..a7f936ff171 100644
--- a/source/blender/freestyle/intern/application/Controller.cpp
+++ b/source/blender/freestyle/intern/application/Controller.cpp
@@ -118,6 +118,7 @@ Controller::Controller()
_Canvas = new AppCanvas;
_inter = new PythonInterpreter();
+ _EnableViewMapCache = false;
_EnableQI = true;
_EnableFaceSmoothness = false;
_ComputeRidges = true;
@@ -212,6 +213,19 @@ void Controller::setContext(bContext *C)
py_inter->setContext(C);
}
+bool Controller::hitViewMapCache()
+{
+ if (!_EnableViewMapCache) {
+ return false;
+ }
+ real hashCode = sceneHashFunc.getValue();
+ if (prevSceneHash == hashCode) {
+ return (NULL != _ViewMap);
+ }
+ prevSceneHash = hashCode;
+ return false;
+}
+
int Controller::LoadMesh(Render *re, SceneRenderLayer *srl)
{
BlenderFileLoader loader(re, srl);
@@ -242,6 +256,7 @@ int Controller::LoadMesh(Render *re, SceneRenderLayer *srl)
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "Scene loaded" << endl;
printf("Mesh cleaning : %lf\n", duration);
+ printf("View map cache : %s\n", _EnableViewMapCache ? "enabled" : "disabled");
}
_SceneNumFaces += loader.numFacesRead();
@@ -263,6 +278,22 @@ int Controller::LoadMesh(Render *re, SceneRenderLayer *srl)
if (_pRenderMonitor->testBreak())
return 0;
+ if (_EnableViewMapCache) {
+ sceneHashFunc.reset();
+ blenderScene->accept(sceneHashFunc);
+ if (G.debug & G_DEBUG_FREESTYLE) {
+ printf("Scene hash : %.16e\n", sceneHashFunc.getValue());
+ }
+ if (hitViewMapCache()) {
+ ClearRootNode();
+ return 0;
+ }
+ else {
+ delete _ViewMap;
+ _ViewMap = NULL;
+ }
+ }
+
_Chrono.start();
WXEdgeBuilder wx_builder;
@@ -357,7 +388,7 @@ void Controller::DeleteWingedEdge()
_minEdgeSize = DBL_MAX;
}
-void Controller::DeleteViewMap()
+void Controller::DeleteViewMap(bool freeCache)
{
_pView->DetachSilhouette();
if (NULL != _SilhouetteNode) {
@@ -387,14 +418,15 @@ void Controller::DeleteViewMap()
_pView->DetachDebug();
if (NULL != _DebugNode) {
- int ref = _DebugNode->destroy();
+ int ref = _DebugNode->destroy();
if (0 == ref)
_DebugNode->addRef();
}
- if (NULL != _ViewMap) {
+ if ((freeCache || !_EnableViewMapCache) && NULL != _ViewMap) {
delete _ViewMap;
_ViewMap = NULL;
+ prevSceneHash = -1.0;
}
}
@@ -403,40 +435,7 @@ void Controller::ComputeViewMap()
if (!_ListOfModels.size())
return;
- if (NULL != _ViewMap) {
- delete _ViewMap;
- _ViewMap = NULL;
- }
-
- _pView->DetachDebug();
- if (NULL != _DebugNode) {
- int ref = _DebugNode->destroy();
- if (0 == ref)
- _DebugNode->addRef();
- }
-
- _pView->DetachSilhouette();
- if (NULL != _SilhouetteNode) {
- int ref = _SilhouetteNode->destroy();
- if (0 == ref)
- delete _SilhouetteNode;
- }
-
-#if 0
- if (NULL != _ProjectedSilhouette) {
- int ref = _ProjectedSilhouette->destroy();
- if (0 == ref)
- delete _ProjectedSilhouette;
- }
-
- if (NULL != _VisibleProjectedSilhouette) {
- int ref = _VisibleProjectedSilhouette->destroy();
- if (0 == ref) {
- delete _VisibleProjectedSilhouette;
- _VisibleProjectedSilhouette = NULL;
- }
- }
-#endif
+ DeleteViewMap(true);
// retrieve the 3D viewpoint and transformations information
//----------------------------------------------------------
@@ -763,6 +762,16 @@ int Controller::getVisibilityAlgo()
return FREESTYLE_ALGO_ADAPTIVE_TRADITIONAL;
}
+void Controller::setViewMapCache(bool iBool)
+{
+ _EnableViewMapCache = iBool;
+}
+
+bool Controller::getViewMapCache() const
+{
+ return _EnableViewMapCache;
+}
+
void Controller::setQuantitativeInvisibility(bool iBool)
{
_EnableQI = iBool;
diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h
index f5e50347d0f..84ee3382612 100644
--- a/source/blender/freestyle/intern/application/Controller.h
+++ b/source/blender/freestyle/intern/application/Controller.h
@@ -32,6 +32,7 @@
//#include "ConfigIO.h"
#include "../geometry/FastGrid.h"
+#include "../scene_graph/SceneHash.h"
#include "../system/Interpreter.h"
#include "../system/ProgressBar.h"
#include "../system/Precision.h"
@@ -96,7 +97,7 @@ public:
void Clear();
void ClearRootNode();
void DeleteWingedEdge();
- void DeleteViewMap();
+ void DeleteViewMap(bool freeCache = false);
void toggleLayer(unsigned index, bool iDisplay);
void setModified(unsigned index, bool iMod);
void resetModified(bool iMod=false);
@@ -118,6 +119,8 @@ public:
void setVisibilityAlgo(int algo);
int getVisibilityAlgo();
+ void setViewMapCache(bool iBool);
+ bool getViewMapCache() const;
void setQuantitativeInvisibility(bool iBool); // if true, we compute quantitativeInvisibility
bool getQuantitativeInvisibility() const;
void setFaceSmoothness(bool iBool);
@@ -144,6 +147,8 @@ public:
void setModulesDir(const string& dir);
string getModulesDir() const;
+ bool hitViewMapCache();
+
void resetInterpreter();
public:
@@ -231,6 +236,7 @@ private:
string _help_index;
string _browser_cmd;
+ bool _EnableViewMapCache;
bool _EnableQI;
bool _EnableFaceSmoothness;
bool _ComputeRidges;
@@ -244,6 +250,9 @@ private:
FEdgeXDetector edgeDetector;
+ SceneHash sceneHashFunc;
+ real prevSceneHash = -1.0;
+
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Controller")
#endif
diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
index 32f49d48ee7..7443da77399 100644
--- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
+++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
@@ -474,6 +474,9 @@ static void prepare(Main *bmain, Render *re, SceneRenderLayer *srl)
cout << " Z = " << (z ? "enabled" : "disabled") << endl;
}
+ if (controller->hitViewMapCache())
+ return;
+
// compute view map
re->i.infostr = "Freestyle: View map creation";
re->stats_draw(re->sdh, &re->i);
@@ -589,6 +592,7 @@ Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl, int render)
RenderMonitor monitor(re);
controller->setRenderMonitor(&monitor);
+ controller->setViewMapCache((srl->freestyleConfig.flags & FREESTYLE_VIEW_MAP_CACHE) ? true : false);
if (G.debug & G_DEBUG_FREESTYLE) {
cout << endl;
@@ -647,6 +651,17 @@ void FRS_finish_stroke_rendering(Render *re)
controller->Clear();
}
+void FRS_free_view_map_cache()
+{
+ // free cache
+ controller->DeleteViewMap(true);
+#if 0
+ if (G.debug & G_DEBUG_FREESTYLE) {
+ printf("View map cache freed\n");
+ }
+#endif
+}
+
//=======================================================
// Freestyle Panel Configuration
//=======================================================
diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp
new file mode 100644
index 00000000000..6e8856f1b93
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp
@@ -0,0 +1,39 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/scene_graph/SceneHash.cpp
+ * \ingroup freestyle
+ */
+
+#include "SceneHash.h"
+
+namespace Freestyle {
+
+void SceneHash::visitIndexedFaceSet(IndexedFaceSet& ifs)
+{
+ const real *v = ifs.vertices();
+ const unsigned n = ifs.vsize();
+
+ for (unsigned i = 0; i < n; i++) {
+ _hashcode += v[i];
+ }
+}
+
+} /* namespace Freestyle */
diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.h b/source/blender/freestyle/intern/scene_graph/SceneHash.h
new file mode 100644
index 00000000000..8f5f847eaab
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/SceneHash.h
@@ -0,0 +1,67 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __FREESTYLE_SCENE_HASH_H__
+#define __FREESTYLE_SCENE_HASH_H__
+
+/** \file blender/freestyle/intern/scene_graph/SceneHash.h
+ * \ingroup freestyle
+ */
+
+#include "IndexedFaceSet.h"
+#include "SceneVisitor.h"
+
+#ifdef WITH_CXX_GUARDEDALLOC
+#include "MEM_guardedalloc.h"
+#endif
+
+namespace Freestyle {
+
+class SceneHash : public SceneVisitor
+{
+public:
+ inline SceneHash() : SceneVisitor()
+ {
+ _hashcode = 0.0;
+ }
+
+ virtual ~SceneHash() {}
+
+ VISIT_DECL(IndexedFaceSet)
+
+ inline real getValue() {
+ return _hashcode;
+ }
+
+ inline void reset() {
+ _hashcode = 0.0;
+ }
+
+private:
+ real _hashcode;
+
+#ifdef WITH_CXX_GUARDEDALLOC
+ MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:SceneHash")
+#endif
+};
+
+} /* namespace Freestyle */
+
+#endif // __FREESTYLE_SCENE_HASH_H__