BGE 2D Filters: filters run per scene now (fix for [#18152]) - it (slightly) breaks backward compatibility !!!

Originally we had 2DFilters (m_filtermanager) stored in RenderTools. That way filters were stored globally and were being called once per each scene. This was producing two big problems: (1) performance and (2) flexibility of use.

(1) Performance - To run the filters 2X == 2X slower
(2) flexibility of use - Very often we want the filter in the scene but not in the UI for example.

For those reasons I believe that 2DFilters with multiple scenes was very useless or unpredictable. I hope they work fine now.
To make it work as before (2.4) you can simply recreate the 2dfilter actuators across the scenes.

* * * * *

Imagine that we have:
(a) Main Scene
(b) Overlay Scene

in Main Scene the Z Buffer and RGB will be from the main scene.
in Overlay Scene the Z Buffer will be from the Overlay Scene and the RBG buffer is from both [(a + 2D Filter) + b].

So in pseudo code if we have a,b,c,d,e scenes we have: (2DFilterE(2DFilterD(2DFilterC(2DFilterB(2DFilterA(a) + b) + c) + d) + e)
This commit is contained in:
Dalai Felinto
2010-03-03 06:38:47 +00:00
parent c26486f207
commit 0cad3ae24c
19 changed files with 46 additions and 60 deletions

View File

@@ -2246,7 +2246,6 @@ static void SCREEN_OT_region_flip(wmOperatorType *ot)
/* api callbacks */ /* api callbacks */
ot->exec= region_flip_exec; ot->exec= region_flip_exec;
ot->poll= ED_operator_areaactive; ot->poll= ED_operator_areaactive;
ot->flag= 0; ot->flag= 0;
} }

View File

@@ -379,13 +379,3 @@ void KX_BlenderRenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
} }
} }
} }
void KX_BlenderRenderTools::Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)
{
m_filtermanager.EnableFilter(propNames, gameObj, filtermode, pass, text);
}
void KX_BlenderRenderTools::Render2DFilters(RAS_ICanvas* canvas)
{
m_filtermanager.RenderFilters(canvas);
}

View File

@@ -94,10 +94,6 @@ public:
virtual void MotionBlur(RAS_IRasterizer* rasterizer); virtual void MotionBlur(RAS_IRasterizer* rasterizer);
virtual void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
virtual void Render2DFilters(RAS_ICanvas* canvas);
virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj); virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj);

View File

@@ -969,7 +969,7 @@ void BL_ConvertActuators(char* maggiename,
} }
tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag, tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
_2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),rendertools); _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),scene);
if (_2dfilter->text) if (_2dfilter->text)
{ {

View File

@@ -32,6 +32,7 @@ SET(INC
../../../intern/string ../../../intern/string
../../../source/gameengine/Expressions ../../../source/gameengine/Expressions
../../../source/gameengine/SceneGraph ../../../source/gameengine/SceneGraph
../../../source/gameengine/Ketsji
../../../intern/moto/include ../../../intern/moto/include
../../../source/gameengine/Rasterizer ../../../source/gameengine/Rasterizer
) )

View File

@@ -41,6 +41,7 @@ CCFLAGS += $(LEVEL_1_CPP_WARNINGS)
CPPFLAGS += -I../Expressions CPPFLAGS += -I../Expressions
CPPFLAGS += -I../SceneGraph CPPFLAGS += -I../SceneGraph
CPPFLAGS += -I../Rasterizer CPPFLAGS += -I../Rasterizer
CPPFLAGS += -I../Ketsji
CPPFLAGS += -I$(NAN_STRING)/include CPPFLAGS += -I$(NAN_STRING)/include
CPPFLAGS += -I$(NAN_MOTO)/include CPPFLAGS += -I$(NAN_MOTO)/include
CPPFLAGS += -I../../blender/makesdna CPPFLAGS += -I../../blender/makesdna

View File

@@ -42,14 +42,14 @@ SCA_2DFilterActuator::SCA_2DFilterActuator(
float float_arg, float float_arg,
int int_arg, int int_arg,
RAS_IRasterizer* rasterizer, RAS_IRasterizer* rasterizer,
RAS_IRenderTools* rendertools) KX_Scene* scene)
: SCA_IActuator(gameobj, KX_ACT_2DFILTER), : SCA_IActuator(gameobj, KX_ACT_2DFILTER),
m_type(type), m_type(type),
m_disableMotionBlur(flag), m_disableMotionBlur(flag),
m_float_arg(float_arg), m_float_arg(float_arg),
m_int_arg(int_arg), m_int_arg(int_arg),
m_rasterizer(rasterizer), m_rasterizer(rasterizer),
m_rendertools(rendertools) m_scene(scene)
{ {
m_gameObj = NULL; m_gameObj = NULL;
if(gameobj){ if(gameobj){
@@ -87,7 +87,7 @@ bool SCA_2DFilterActuator::Update()
} }
else if(m_type < RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS) else if(m_type < RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS)
{ {
m_rendertools->Update2DFilter(m_propNames, m_gameObj, m_type, m_int_arg, m_shaderText); m_scene->Update2DFilter(m_propNames, m_gameObj, m_type, m_int_arg, m_shaderText);
} }
// once the filter is in place, no need to update it again => disable the actuator // once the filter is in place, no need to update it again => disable the actuator
return false; return false;

View File

@@ -29,8 +29,8 @@
#define __SCA_2DFILETRACTUATOR_H__ #define __SCA_2DFILETRACTUATOR_H__
#include "RAS_IRasterizer.h" #include "RAS_IRasterizer.h"
#include "RAS_IRenderTools.h"
#include "SCA_IActuator.h" #include "SCA_IActuator.h"
#include "KX_Scene.h"
class SCA_2DFilterActuator : public SCA_IActuator class SCA_2DFilterActuator : public SCA_IActuator
{ {
@@ -45,7 +45,7 @@ private:
int m_int_arg; int m_int_arg;
STR_String m_shaderText; STR_String m_shaderText;
RAS_IRasterizer* m_rasterizer; RAS_IRasterizer* m_rasterizer;
RAS_IRenderTools* m_rendertools; KX_Scene* m_scene;
public: public:
@@ -56,7 +56,7 @@ public:
float float_arg, float float_arg,
int int_arg, int int_arg,
RAS_IRasterizer* rasterizer, RAS_IRasterizer* rasterizer,
RAS_IRenderTools* rendertools); KX_Scene* scene);
void SetShaderText(const char *text); void SetShaderText(const char *text);
virtual ~SCA_2DFilterActuator(); virtual ~SCA_2DFilterActuator();

View File

@@ -6,6 +6,7 @@ sources = env.Glob('*.cpp') + env.Glob('Joystick/*.cpp')
incs = '. #/source/kernel/gen_system #/intern/string' incs = '. #/source/kernel/gen_system #/intern/string'
incs += ' #/source/gameengine/Expressions #/intern/moto/include' incs += ' #/source/gameengine/Expressions #/intern/moto/include'
incs += ' #/source/gameengine/Rasterizer #/source/gameengine/SceneGraph' incs += ' #/source/gameengine/Rasterizer #/source/gameengine/SceneGraph'
incs += ' #/source/gameengine/Ketsji'
defs = [] defs = []

View File

@@ -433,13 +433,3 @@ void GPC_RenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
} }
} }
void GPC_RenderTools::Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)
{
m_filtermanager.EnableFilter(propNames, gameObj, filtermode, pass, text);
}
void GPC_RenderTools::Render2DFilters(RAS_ICanvas* canvas)
{
m_filtermanager.RenderFilters(canvas);
}

View File

@@ -94,10 +94,6 @@ public:
virtual void MotionBlur(RAS_IRasterizer* rasterizer); virtual void MotionBlur(RAS_IRasterizer* rasterizer);
virtual void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
virtual void Render2DFilters(RAS_ICanvas* canvas);
virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj); virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj);
}; };

View File

@@ -334,6 +334,11 @@ void KX_KetsjiEngine::RenderDome()
it++; it++;
} }
// Part of PostRenderScene()
m_rendertools->MotionBlur(m_rasterizer);
scene->Render2DFilters(m_canvas);
// no RunDrawingCallBacks
// no FlushDebugLines
} }
m_dome->BindImages(i); m_dome->BindImages(i);
} }
@@ -362,11 +367,7 @@ void KX_KetsjiEngine::RenderDome()
1.0 1.0
); );
} }
m_dome->Draw(); m_dome->Draw();
// run the 2dfilters and motion blur once for all the scenes
PostRenderFrame();
EndFrame(); EndFrame();
} }
@@ -859,6 +860,7 @@ void KX_KetsjiEngine::Render()
it++; it++;
} }
PostRenderScene(scene);
} }
// only one place that checks for stereo // only one place that checks for stereo
@@ -908,6 +910,7 @@ void KX_KetsjiEngine::Render()
it++; it++;
} }
PostRenderScene(scene);
} }
} // if(m_rasterizer->Stereo()) } // if(m_rasterizer->Stereo())
@@ -1313,20 +1316,16 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam)
if (scene->GetPhysicsEnvironment()) if (scene->GetPhysicsEnvironment())
scene->GetPhysicsEnvironment()->debugDrawWorld(); scene->GetPhysicsEnvironment()->debugDrawWorld();
m_rasterizer->FlushDebugLines();
//it's running once for every scene (i.e. overlay scenes have it running twice). That's not the ideal.
PostRenderFrame();
// Run any post-drawing python callbacks
scene->RunDrawingCallbacks(scene->GetPostDrawCB());
} }
/*
void KX_KetsjiEngine::PostRenderFrame() To run once per scene
*/
void KX_KetsjiEngine::PostRenderScene(KX_Scene* scene)
{ {
m_rendertools->Render2DFilters(m_canvas);
m_rendertools->MotionBlur(m_rasterizer); m_rendertools->MotionBlur(m_rasterizer);
scene->Render2DFilters(m_canvas);
scene->RunDrawingCallbacks(scene->GetPostDrawCB());
m_rasterizer->FlushDebugLines();
} }
void KX_KetsjiEngine::StopEngine() void KX_KetsjiEngine::StopEngine()

View File

@@ -185,7 +185,7 @@ private:
float m_overrideFrameColorB; float m_overrideFrameColorB;
void RenderFrame(KX_Scene* scene, KX_Camera* cam); void RenderFrame(KX_Scene* scene, KX_Camera* cam);
void PostRenderFrame(); void PostRenderScene(KX_Scene* scene);
void RenderDebugProperties(); void RenderDebugProperties();
void RenderShadowBuffers(KX_Scene *scene); void RenderShadowBuffers(KX_Scene *scene);
void SetBackGround(KX_WorldInfo* worldinfo); void SetBackGround(KX_WorldInfo* worldinfo);

View File

@@ -1842,6 +1842,16 @@ bool KX_Scene::MergeScene(KX_Scene *other)
return true; return true;
} }
void KX_Scene::Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)
{
m_filtermanager.EnableFilter(propNames, gameObj, filtermode, pass, text);
}
void KX_Scene::Render2DFilters(RAS_ICanvas* canvas)
{
m_filtermanager.RenderFilters(canvas);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
//Python //Python

View File

@@ -46,6 +46,7 @@
#include "RAS_Rect.h" #include "RAS_Rect.h"
#include "PyObjectPlus.h" #include "PyObjectPlus.h"
#include "RAS_2DFilterManager.h"
/** /**
* @section Forward declarations * @section Forward declarations
@@ -273,6 +274,7 @@ protected:
struct Scene* m_blenderScene; struct Scene* m_blenderScene;
RAS_2DFilterManager m_filtermanager;
public: public:
KX_Scene(class SCA_IInputDevice* keyboarddevice, KX_Scene(class SCA_IInputDevice* keyboarddevice,
class SCA_IInputDevice* mousedevice, class SCA_IInputDevice* mousedevice,
@@ -535,6 +537,12 @@ public:
*/ */
void SetNodeTree(SG_Tree* root); void SetNodeTree(SG_Tree* root);
/**
* 2D Filters
*/
void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
void Render2DFilters(RAS_ICanvas* canvas);
#ifndef DISABLE_PYTHON #ifndef DISABLE_PYTHON
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* Python interface ---------------------------------------------------- */ /* Python interface ---------------------------------------------------- */

View File

@@ -31,6 +31,7 @@ SET(INC
../../../source/kernel/gen_system ../../../source/kernel/gen_system
../../../source/blender/makesdna ../../../source/blender/makesdna
../../../source/gameengine/SceneGraph ../../../source/gameengine/SceneGraph
../../../source/gameengine/Ketsji
../../../intern/string ../../../intern/string
../../../intern/moto/include ../../../intern/moto/include
../../../extern/glew/include ../../../extern/glew/include

View File

@@ -45,6 +45,7 @@ CPPFLAGS += -I../../blender/makesdna
CPPFLAGS += -I../SceneGraph CPPFLAGS += -I../SceneGraph
CPPFLAGS += -I../BlenderRoutines CPPFLAGS += -I../BlenderRoutines
CPPFLAGS += -I../Expressions CPPFLAGS += -I../Expressions
CPPFLAGS += -I../Ketsji
CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION) CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)

View File

@@ -28,6 +28,7 @@
#ifndef __RAS_I2DFILTER #ifndef __RAS_I2DFILTER
#define __RAS_I2DFILTER #define __RAS_I2DFILTER
#include "RAS_ICanvas.h"
#define MAX_RENDER_PASS 100 #define MAX_RENDER_PASS 100
#ifdef WITH_CXX_GUARDEDALLOC #ifdef WITH_CXX_GUARDEDALLOC

View File

@@ -176,14 +176,6 @@ public:
virtual virtual
void void
MotionBlur(RAS_IRasterizer* rasterizer)=0; MotionBlur(RAS_IRasterizer* rasterizer)=0;
virtual
void
Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)=0;
virtual
void
Render2DFilters(RAS_ICanvas* canvas)=0;
#ifdef WITH_CXX_GUARDEDALLOC #ifdef WITH_CXX_GUARDEDALLOC