2d-Filters feature and actuators.
authorHamed Zaghaghi <hamed.zaghaghi@gmail.com>
Mon, 22 Oct 2007 20:24:26 +0000 (20:24 +0000)
committerHamed Zaghaghi <hamed.zaghaghi@gmail.com>
Mon, 22 Oct 2007 20:24:26 +0000 (20:24 +0000)
30 files changed:
source/blender/blenkernel/intern/sca.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/include/blendef.h
source/blender/makesdna/DNA_actuator_types.h
source/blender/src/buttons_logic.c
source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/GameLogic/CMakeLists.txt
source/gameengine/GameLogic/SCA_2DFilterActuator.cpp [new file with mode: 0644]
source/gameengine/GameLogic/SCA_2DFilterActuator.h [new file with mode: 0644]
source/gameengine/GameLogic/SConscript
source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
source/gameengine/GamePlayer/common/GPC_RenderTools.h
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.h
source/gameengine/Rasterizer/RAS_2DFilterManager.cpp [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_2DFilterManager.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_IRenderTools.h
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h [new file with mode: 0644]
source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h [new file with mode: 0644]

index e772a3bcdb49f10ae7ab88ef5b8dddcf9069b0a6..88afa8d5e61ef7fa0210cad0bbd290a89d3b8221 100644 (file)
@@ -461,6 +461,9 @@ void init_actuator(bActuator *act)
        case ACT_VISIBILITY:
                act->data= MEM_callocN(sizeof(bVisibilityActuator), "visibility act");
                break;
+    case ACT_2DFILTER:
+        act->data = MEM_callocN(sizeof( bTwoDFilterActuator ), "2d filter act");
+        break;
        default:
                ; /* this is very severe... I cannot make any memory for this        */
                /* logic brick...                                                    */
index a58593114702ea169079b9fc00c2b4ac73f2f22b..b5cad26417730b5988ee4457c742cd5293c0374d 100644 (file)
@@ -2819,6 +2819,9 @@ static void lib_link_object(FileData *fd, Main *main)
                                        bMessageActuator *ma= act->data;
                                        ma->toObject= newlibadr(fd, ob->id.lib, ma->toObject);
                                }
+                               else if(act->type==ACT_2DFILTER){
+                                       /* bTwoDFilterActuator *_2dfa = act->data; */
+                               }
                                act= act->next;
                        }
 
index 4f09f51bc877dd8c51c2c9c85f854f7ff64e827b..17860039f6fb50fcdafea4eb6c70e96d00dcd2c4 100644 (file)
@@ -672,6 +672,9 @@ static void write_actuators(WriteData *wd, ListBase *lb)
                case ACT_VISIBILITY:
                        writestruct(wd, DATA, "bVisibilityActuator", 1, act->data);
                        break;
+               case ACT_2DFILTER:
+                       writestruct(wd, DATA, "bTwoDFilterActuator", 1, act->data);
+                       break;
                default:
                        ; /* error: don't know how to write this file */
                }
index 5db45b6571ff0001c437af30707963c8f2bb63f5..036b67301e4cc0b4faff9a111085494a5aa5a074 100644 (file)
 /* Error messages */
 #define ERROR_LIBDATA_MESSAGE "Can't edit external libdata"
 
+#define MAX_RENDER_PASS        100
 
 #endif
index 0531e70bb976a7f363878786a9d7a0bb68edbbff..bc847958fdfaf5bbba6da66c73ce1e71c4786b90 100644 (file)
@@ -191,6 +191,17 @@ typedef struct bVisibilityActuator {
        int flag;
 } bVisibilityActuator;
 
+typedef struct bTwoDFilterActuator{
+       /* Tells what type of 2D Filter*/
+       short type;
+       /* (flag == 0) means 2D filter is activate and
+          (flag != 0) means 2D filter is inactive*/
+       short flag;
+       /* a float argument */
+       float float_arg;
+       int   int_arg;
+}bTwoDFilterActuator;
+
 typedef struct bActuator {
        struct bActuator *next, *prev, *mynew;
        short type;
@@ -259,6 +270,7 @@ typedef struct FreeCamera {
 #define ACT_CD                 16
 #define ACT_GAME               17
 #define ACT_VISIBILITY          18
+#define ACT_2DFILTER   19
 
 /* actuator flag */
 #define ACT_SHOW               1
@@ -391,5 +403,20 @@ typedef struct FreeCamera {
 /* Set means the object will become invisible */
 #define ACT_VISIBILITY_INVISIBLE       (1 << 0)
 
+/* twodfilter->type */
+#define ACT_2DFILTER_NOFILTER                  -1
+#define ACT_2DFILTER_MOTIONBLUR                        0
+#define ACT_2DFILTER_BLUR                              1
+#define ACT_2DFILTER_SHARPEN                   2
+#define ACT_2DFILTER_DILATION                  3
+#define ACT_2DFILTER_EROSION                   4
+#define ACT_2DFILTER_LAPLACIAN                 5
+#define ACT_2DFILTER_SOBEL                             6
+#define ACT_2DFILTER_PREWITT                   7
+#define ACT_2DFILTER_GRAYSCALE                 8
+#define ACT_2DFILTER_SEPIA                             9
+#define ACT_2DFILTER_INVERT                            10
+#define ACT_2DFILTER_NUMBER_OF_FILTERS 11
 #endif
 
+
index 77922f041d8d40d817ce172988041d9d4046907c..e457e44bd63b88233d541b3b6c33b975e7f635f6 100644 (file)
@@ -712,6 +712,8 @@ static char *actuator_name(int type)
                return "Game";
        case ACT_VISIBILITY:
                return "Visibility";
+       case ACT_2DFILTER:
+               return "2D Filter";
        }
        return "unknown";
 }
@@ -727,13 +729,13 @@ static char *actuator_pup(Object *owner)
                return "Actuators  %t|Action %x15|Motion %x0|Constraint %x9|Ipo %x1"
                        "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
                        "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
-                       "|Visibility %x18";
+                       "|Visibility %x18|2D Filter %x19";
                break;
        default:
                return "Actuators  %t|Motion %x0|Constraint %x9|Ipo %x1"
                        "|Camera %x3|Sound %x5|Property %x6|Edit Object %x10"
                        "|Scene %x11|Random %x13|Message %x14|CD %x16|Game %x17"
-                       "|Visibility %x18";
+                       "|Visibility %x18|2D Filter %x19";
        }
 }
 
@@ -1476,6 +1478,7 @@ static short draw_actuatorbuttons(bActuator *act, uiBlock *block, short xco, sho
        bActionActuator     *aa      = NULL;
        bGameActuator       *gma     = NULL;
        bVisibilityActuator *visAct  = NULL;
+       bTwoDFilterActuator     *tdfa    = NULL;
        
        float *fp;
        short ysize = 0, wval;
@@ -2172,6 +2175,47 @@ static short draw_actuatorbuttons(bActuator *act, uiBlock *block, short xco, sho
                
                yco -= ysize;
                break;
+       case ACT_2DFILTER:
+               tdfa = act->data;
+
+               ysize= 50;
+        glRects( xco, yco-ysize, xco+width, yco ); 
+               uiEmboss( (float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1 );
+
+               switch(tdfa->type)
+               {
+                       case ACT_2DFILTER_MOTIONBLUR:
+                               if(!tdfa->flag)
+                               {
+                                       uiDefButS(block, TOG, B_REDR, "D",      xco+30,yco-44,19, 19, &tdfa->flag, 0.0, 0.0, 0.0, 0.0, "Disable Motion Blur");
+                                       uiDefButF(block, NUM, B_REDR, "Value:", xco+52,yco-44,width-82,19,&tdfa->float_arg,0.0,1.0,0.0,0.0,"Set motion blur value");
+                               }
+                               else
+                               {
+                                       uiDefButS(block, TOG, B_REDR, "Disabled",       xco+30,yco-44,width-60, 19, &tdfa->flag, 0.0, 0.0, 0.0, 0.0, "Enable Motion Blur");
+                               }
+                               break;
+                       case ACT_2DFILTER_BLUR:
+                       case ACT_2DFILTER_SHARPEN:
+                       case ACT_2DFILTER_DILATION:
+                       case ACT_2DFILTER_EROSION:
+                       case ACT_2DFILTER_LAPLACIAN:
+                       case ACT_2DFILTER_SOBEL:
+                       case ACT_2DFILTER_PREWITT:
+                       case ACT_2DFILTER_GRAYSCALE:
+                       case ACT_2DFILTER_SEPIA:
+                       case ACT_2DFILTER_INVERT:
+                       case ACT_2DFILTER_NOFILTER:
+                               uiDefButI(block, NUM, B_REDR, "Pass Number:", xco+30,yco-44,width-60,19,&tdfa->int_arg,-1.0,MAX_RENDER_PASS-1,0.0,0.0,"Set motion blur value");
+                               break;
+               }
+               
+               str= "2D Filter   %t|Motion Blur   %x0|Blur %x1|Sharpen %x2|Dilation %x3|Erosion %x4|"
+                               "Laplacian %x5|Sobel %x6|Prewitt %x7|Gray Scale %x8|Sepia %x9|Invert %x10|No Filter %x-1|";
+               uiDefButS(block, MENU, B_REDR, str,     xco+30,yco-24,width-60, 19, &tdfa->type, 0.0, 0.0, 0.0, 0.0, "2D filter type");
+               
+               yco -= ysize;
+        break;
        default:
                ysize= 4;
 
@@ -2812,3 +2856,4 @@ void logic_buts(void)
        if(idar) MEM_freeN(idar);
 }
 
+
index 463f06869d6c64dfd84d4c8b6f15c498d1545544..06d869a939640c9ba5cf7c008a8d9bc78ecc7c54 100644 (file)
@@ -475,4 +475,14 @@ void KX_BlenderRenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
        }
 }
 
+void KX_BlenderRenderTools::Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass)
+{
+       m_filtermanager.EnableFilter(filtermode, pass);
+}
+
+void KX_BlenderRenderTools::Render2DFilters(RAS_ICanvas* canvas)
+{
+       m_filtermanager.RenderFilters(canvas);
+}
+
 unsigned int KX_BlenderRenderTools::m_numgllights;
index a79302a283eeda82b0e982fceabcb8ed26c2a282..b67b7c8161fc9e09afe564054677d6b50e1cea97 100644 (file)
@@ -55,6 +55,7 @@ class KX_BlenderRenderTools  : public RAS_IRenderTools
        bool    m_lastlighting;
        static unsigned int m_numgllights;
        
+       
 public:
        
                                                KX_BlenderRenderTools();
@@ -102,8 +103,14 @@ public:
        bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
 
        virtual void MotionBlur(RAS_IRasterizer* rasterizer);
+
+       virtual void Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass);
+
+       virtual void Render2DFilters(RAS_ICanvas* canvas);
+
 };
 
 #endif //__KX_BLENDERRENDERTOOLS
 
 
+
index a6baa04b0457fe7b1a266b3b75163199812a78b6..e29a1729fc37e99d26b910934a7c8c406187bbe2 100644 (file)
@@ -45,6 +45,7 @@
 #include "SCA_PropertyActuator.h"
 #include "SCA_LogicManager.h"
 #include "SCA_RandomActuator.h"
+#include "SCA_2DFilterActuator.h"
 
 
 // Ketsji specific logicbricks
@@ -836,7 +837,63 @@ void BL_ConvertActuators(char* maggiename,
                        baseact = tmp_vis_act;
                }
                break;
+               
+               case ACT_2DFILTER:
+               {
+                       bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
+            SCA_2DFilterActuator *tmp = NULL;
 
+                       RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
+                       switch(_2dfilter->type)
+                       {
+                               case ACT_2DFILTER_MOTIONBLUR:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
+                                       break;
+                               case ACT_2DFILTER_BLUR:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
+                                       break;
+                               case ACT_2DFILTER_SHARPEN:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
+                                       break;
+                               case ACT_2DFILTER_DILATION:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
+                                       break;
+                               case ACT_2DFILTER_EROSION:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
+                                       break;
+                               case ACT_2DFILTER_LAPLACIAN:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
+                                       break;
+                               case ACT_2DFILTER_SOBEL:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
+                                       break;
+                               case ACT_2DFILTER_PREWITT:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
+                                       break;
+                               case ACT_2DFILTER_GRAYSCALE:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
+                                       break;
+                               case ACT_2DFILTER_SEPIA:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
+                                       break;
+                               case ACT_2DFILTER_INVERT:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
+                                       break;
+                               case ACT_2DFILTER_NOFILTER:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
+                                       break;
+                               default:
+                                       filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
+                                       break;
+                       }
+            
+                       tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
+                               _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),rendertools);
+
+            baseact = tmp;
+                       
+               }
+               break;
                default:
                        ; /* generate some error */
                }
@@ -860,3 +917,4 @@ void BL_ConvertActuators(char* maggiename,
        }
 }
 
+
index 127edfc151d8705c14a072d482c2f09f327f4203..4f40fa22b9e09bae5ddeadc01aceca69bcf60249 100644 (file)
@@ -35,6 +35,7 @@ SET(INC
   ../../../intern/string
   ../../../source/gameengine/Expressions 
   ../../../intern/moto/include
+  ../../../source/gameengine/Rasterizer
   ${PYTHON_INC}
   ${SDL_INC}
 )
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
new file mode 100644 (file)
index 0000000..7033ae3
--- /dev/null
@@ -0,0 +1,115 @@
+#include "SCA_IActuator.h"
+
+#include "SCA_2DFilterActuator.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <iostream>
+
+
+
+SCA_2DFilterActuator::SCA_2DFilterActuator(
+        SCA_IObject *gameobj, 
+        RAS_2DFilterManager::RAS_2DFILTER_MODE type,
+               short flag,
+               float float_arg,
+               int int_arg,
+               RAS_IRasterizer* rasterizer,
+               RAS_IRenderTools* rendertools,
+        PyTypeObject* T)
+    : SCA_IActuator(gameobj, T),
+     m_type(type),
+        m_flag(flag),
+        m_int_arg(int_arg),
+        m_float_arg(float_arg),
+        m_rasterizer(rasterizer),
+        m_rendertools(rendertools)
+{
+}
+
+
+SCA_2DFilterActuator::~SCA_2DFilterActuator()
+{
+
+}
+
+
+CValue* SCA_2DFilterActuator::GetReplica()
+{
+    SCA_2DFilterActuator* replica = new SCA_2DFilterActuator(*this);
+    replica->ProcessReplica();
+    CValue::AddDataToReplica(replica);
+
+    return replica;
+}
+
+
+bool SCA_2DFilterActuator::Update()
+{
+       bool result = false;
+
+       bool bNegativeEvent = IsNegativeEvent();
+       RemoveAllEvents();
+
+
+       if (bNegativeEvent)
+               return false; // do nothing on negative events
+
+       if( m_type == RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR )
+       {
+               if(!m_flag)
+               {
+                       m_rasterizer->EnableMotionBlur(m_float_arg);
+               }
+               else
+               {
+                       m_rasterizer->DisableMotionBlur();
+               }
+       }
+       else if(m_type < RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS)
+       {
+               m_rendertools->Update2DFilter(m_type, m_int_arg);
+       }
+    return true;
+}
+
+
+PyTypeObject SCA_2DFilterActuator::Type = {
+        PyObject_HEAD_INIT(&PyType_Type)
+        0,
+        "SCA_2DFilterActuator",
+        sizeof(SCA_2DFilterActuator),
+        0,
+        PyDestructor,
+        0,
+        __getattr,
+        __setattr,
+        0, 
+         __repr,
+        0,
+        0,
+        0,
+        0,
+        0
+};
+
+
+PyParentObject SCA_2DFilterActuator::Parents[] = {
+        &SCA_2DFilterActuator::Type,
+        &SCA_IActuator::Type,
+        &SCA_ILogicBrick::Type,
+        &CValue::Type,
+        NULL
+};
+
+
+PyMethodDef SCA_2DFilterActuator::Methods[] = {
+    /* add python functions to deal with m_msg... */
+    {NULL,NULL}
+};
+
+
+PyObject* SCA_2DFilterActuator::_getattr(const STR_String& attr) {
+    _getattr_up(SCA_IActuator);
+}
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.h b/source/gameengine/GameLogic/SCA_2DFilterActuator.h
new file mode 100644 (file)
index 0000000..f1871c8
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef __SCA_2DFILETRACTUATOR_H__
+#define __SCA_2DFILETRACTUATOR_H__
+
+#include "RAS_IRasterizer.h"
+#include "RAS_IRenderTools.h"
+#include "SCA_IActuator.h"
+
+
+class SCA_2DFilterActuator : public SCA_IActuator
+{
+    Py_Header;
+
+private:
+       
+       RAS_2DFilterManager::RAS_2DFILTER_MODE m_type;
+       short m_flag;
+       float m_float_arg;
+       int   m_int_arg;
+       RAS_IRasterizer* m_rasterizer;
+       RAS_IRenderTools* m_rendertools;
+
+public:
+
+    SCA_2DFilterActuator(
+        class SCA_IObject* gameobj,
+        RAS_2DFilterManager::RAS_2DFILTER_MODE type,
+               short flag,
+               float float_arg,
+               int int_arg,
+               RAS_IRasterizer* rasterizer,
+               RAS_IRenderTools* rendertools,
+        PyTypeObject* T=&Type
+        );
+
+
+    virtual ~SCA_2DFilterActuator();
+    virtual bool Update();
+
+    virtual CValue* GetReplica();
+    virtual PyObject* _getattr(const STR_String& attr);
+
+};
+#endif
index 7a2c3d91e72e31a197f997edaec047a5633818b1..1ca884f6dec2788c4e8f3a3b0171f0a40edcd64c 100644 (file)
@@ -5,6 +5,7 @@ sources = env.Glob('*.cpp') + env.Glob('Joystick/*.cpp')
 
 incs = '. #/source/kernel/gen_system #/intern/string'
 incs += ' #/source/gameengine/Expressions #/intern/moto/include'
+incs += ' #/source/gameengine/Rasterizer'
 
 incs += ' ' + env['BF_PYTHON_INC']
 incs += ' ' + env['BF_SDL_INC']
index cc5c392d51a5064800d8c91c0d6bf6dd70709907..ffa8bdb32e74f74c69d6f2dba702a215704ad6c0 100644 (file)
@@ -593,4 +593,14 @@ void GPC_RenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
        }
 }
 
+void GPC_RenderTools::Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass)
+{
+       m_filtermanager.EnableFilter(filtermode, pass);
+}
+
+void GPC_RenderTools::Render2DFilters(RAS_ICanvas* canvas)
+{
+       m_filtermanager.RenderFilters( canvas);
+}
+
 unsigned int GPC_RenderTools::m_numgllights;
index e1f2a869c22d3e3ae4a2fa42b5c28a4b10a62133..4b1e990b7175c2f051e2aac18b9a773ebcc15523 100644 (file)
@@ -151,6 +151,11 @@ public:
        bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
 
        virtual void MotionBlur(RAS_IRasterizer* rasterizer);
+
+       virtual void Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass);
+
+       virtual void Render2DFilters(RAS_ICanvas* canvas);
+
 protected:
        /** 
         * Copied from KX_BlenderGL.cpp in KX_blenderhook
@@ -176,3 +181,4 @@ protected:
 #endif  // __GPC_RENDERTOOLS_H
 
 
+
index f8826245aab55644c7643bacd686e859ce640905..e0a826b8d5d6fcb95423498bbd53204559e10edb 100644 (file)
@@ -966,13 +966,18 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam)
        scene->CalculateVisibleMeshes(m_rasterizer,cam);
 
        scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools);
+       
+       PostRenderFrame();
+}
 
+void KX_KetsjiEngine::PostRenderFrame()
+{
+       m_rendertools->PushMatrix();
+       m_rendertools->Render2DFilters(m_canvas);
        m_rendertools->MotionBlur(m_rasterizer);
-
+       m_rendertools->PopMatrix();
 }
 
-
-
 void KX_KetsjiEngine::StopEngine()
 {
        if (m_bInitialized)
@@ -1467,3 +1472,4 @@ void KX_KetsjiEngine::GetOverrideFrameColor(float& r, float& g, float& b) const
 }
 
 
+
index 16b53b6b6886f23ec80c34353d8e0386b3e3e107..fcb4d0a0790ff50aef04caaf7231cd4c5d39b109 100644 (file)
@@ -179,6 +179,7 @@ private:
 
        void                                    SetupRenderFrame(KX_Scene *scene, KX_Camera* cam);
        void                                    RenderFrame(KX_Scene* scene, KX_Camera* cam);
+       void                                    PostRenderFrame();
        void                                    RenderDebugProperties();
        void                                    SetBackGround(KX_WorldInfo* worldinfo);
        void                                    SetWorldSettings(KX_WorldInfo* worldinfo);
@@ -201,6 +202,8 @@ public:
        void                    SetSceneConverter(KX_ISceneConverter* sceneconverter);
        void                    SetGame2IpoMode(bool game2ipo,int startFrame);
 
+       RAS_IRasterizer*                GetRasterizer(){return m_rasterizer;};
+
        ///returns true if an update happened to indicate -> Render
        bool                    NextFrame();
        void                    Render();
@@ -342,3 +345,4 @@ protected:
 
 #endif //__KX_KETSJI_ENGINE
 
+
diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
new file mode 100644 (file)
index 0000000..740a4d7
--- /dev/null
@@ -0,0 +1,285 @@
+
+#define STRINGIFY(A)  #A
+
+#include "RAS_OpenGLFilters/RAS_Blur2DFilter.h"
+#include "RAS_OpenGLFilters/RAS_Sharpen2DFilter.h"
+#include "RAS_OpenGLFilters/RAS_Dilation2DFilter.h"
+#include "RAS_OpenGLFilters/RAS_Erosion2DFilter.h"
+#include "RAS_OpenGLFilters/RAS_Laplacian2DFilter.h"
+#include "RAS_OpenGLFilters/RAS_Sobel2DFilter.h"
+#include "RAS_OpenGLFilters/RAS_Prewitt2DFilter.h"
+#include "RAS_OpenGLFilters/RAS_GrayScale2DFilter.h"
+#include "RAS_OpenGLFilters/RAS_Sepia2DFilter.h"
+#include "RAS_OpenGLFilters/RAS_Invert2DFilter.h"
+
+#include "RAS_ICanvas.h"
+#include "RAS_2DFilterManager.h"
+#include <iostream>
+
+#ifdef WIN32
+// OpenGL gl.h needs 'windows.h' on windows platforms 
+#include <windows.h>
+#endif //WIN32
+#ifdef __APPLE__
+#define GL_GLEXT_LEGACY 1
+#include <OpenGL/gl.h>
+#else
+#include <GL/gl.h>
+#endif
+
+#include "RAS_OpenGLRasterizer/RAS_GLExtensionManager.h"
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+RAS_2DFilterManager::RAS_2DFilterManager():
+texturewidth(-1), textureheight(-1),
+canvaswidth(-1), canvasheight(-1),
+numberoffilters(0),texname(-1)
+{
+       isshadersupported = bgl::QueryVersion(2,0);
+       if(!isshadersupported)
+       {
+               std::cout<<"shaders not supported!" << std::endl;
+               return;
+       }
+
+       int passindex;
+       for(passindex =0; passindex<MAX_RENDER_PASS; passindex++)
+               m_filters[passindex] = 0;
+
+       int programindex;
+       for(programindex=0; programindex<RAS_2DFILTER_NUMBER_OF_FILTERS; programindex++)
+               m_programs[programindex] = 0;
+       
+}
+
+RAS_2DFilterManager::~RAS_2DFilterManager()
+{
+}
+
+unsigned int RAS_2DFilterManager::CreateShaderProgram(char* shadersource)
+{
+               GLuint program; 
+               GLuint fShader = bgl::blCreateShaderObjectARB(GL_FRAGMENT_SHADER);
+        GLint success;
+
+               bgl::blShaderSourceARB(fShader, 1, (const char**)&shadersource, NULL);
+
+               bgl::blCompileShaderARB(fShader);
+
+               bgl::blGetObjectParameterivARB(fShader, GL_COMPILE_STATUS, &success);
+               if(!success)
+               {
+                       /*Shader Comile Error*/
+                       std::cout << "2dFilters - Shader compile error" << std::endl;
+                       return 0;
+               }
+                   
+               program = bgl::blCreateProgramObjectARB();
+               bgl::blAttachObjectARB(program, fShader);
+
+               bgl::blLinkProgramARB(program);
+               bgl::blGetObjectParameterivARB(program, GL_LINK_STATUS, &success);
+               if (!success)
+               {
+                       /*Program Link Error*/
+                       std::cout << "2dFilters - Shader program link error" << std::endl;
+                       return 0;
+               }
+               
+               bgl::blValidateProgramARB(program);
+               bgl::blGetObjectParameterivARB(program, GL_VALIDATE_STATUS, &success);
+        if (!success)
+               {
+                       /*Program Validation Error*/
+                       std::cout << "2dFilters - Shader program validation error" << std::endl;
+                       return 0;
+               }
+               return program;
+}
+
+unsigned int RAS_2DFilterManager::CreateShaderProgram(int filtermode)
+{
+               switch(filtermode)
+               {
+                       case RAS_2DFILTER_BLUR:
+                               return CreateShaderProgram(BlurFragmentShader);
+                       case RAS_2DFILTER_SHARPEN:
+                               return CreateShaderProgram(SharpenFragmentShader);
+                       case RAS_2DFILTER_DILATION:
+                               return CreateShaderProgram(DilationFragmentShader);
+                       case RAS_2DFILTER_EROSION:
+                               return CreateShaderProgram(ErosionFragmentShader);
+                       case RAS_2DFILTER_LAPLACIAN:
+                               return CreateShaderProgram(LaplacionFragmentShader);
+                       case RAS_2DFILTER_SOBEL:
+                               return CreateShaderProgram(SobelFragmentShader);
+                       case RAS_2DFILTER_PREWITT:
+                               return CreateShaderProgram(PrewittFragmentShader);
+                       case RAS_2DFILTER_GRAYSCALE:
+                               return CreateShaderProgram(GrayScaleFragmentShader);
+                       case RAS_2DFILTER_SEPIA:
+                               return CreateShaderProgram(SepiaFragmentShader);
+                       case RAS_2DFILTER_INVERT:
+                               return CreateShaderProgram(InvertFragmentShader);
+               }
+               return 0;
+}
+
+void RAS_2DFilterManager::StartShaderProgram(int filtermode)
+{
+    GLint uniformLoc;
+       bgl::blUseProgramObjectARB(m_programs[filtermode]);
+       uniformLoc = bgl::blGetUniformLocationARB(m_programs[filtermode], "sampler0");
+    if (uniformLoc != -1)
+    {
+               bgl::blUniform1iARB(uniformLoc, 0);
+    }
+       uniformLoc = bgl::blGetUniformLocationARB(m_programs[filtermode], "tc_offset");
+    if (uniformLoc != -1)
+    {
+        bgl::blUniform2fvARB(uniformLoc, 9, textureoffsets);
+    }
+}
+
+void RAS_2DFilterManager::EndShaderProgram()
+{
+       bgl::blUseProgramObjectARB(0);
+}
+
+void RAS_2DFilterManager::SetupTexture()
+{
+       if(texname!=-1)
+       {
+               glDeleteTextures(1,&texname);
+       }
+       glGenTextures(1, &texname);
+       glBindTexture(GL_TEXTURE_2D, texname);
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texturewidth, textureheight, 0, GL_RGB,
+               GL_UNSIGNED_BYTE, 0);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+}
+
+void RAS_2DFilterManager::UpdateOffsetMatrix(int width, int height)
+{
+       canvaswidth = texturewidth = width;
+       canvasheight = textureheight = height;
+
+       GLint i,j;
+       i = 0;
+    while ((1 << i) <= texturewidth)
+        i++;
+    texturewidth = (1 << (i));
+
+    // Now for height
+    i = 0;
+    while ((1 << i) <= textureheight)
+        i++;
+    textureheight = (1 << (i));
+
+       GLfloat xInc = 1.0f / (GLfloat)texturewidth;
+       GLfloat yInc = 1.0f / (GLfloat)textureheight;
+       
+       for (i = 0; i < 3; i++)
+       {
+               for (j = 0; j < 3; j++)
+               {
+                       textureoffsets[(((i*3)+j)*2)+0] = (-1.0f * xInc) + ((GLfloat)i * xInc);
+                       textureoffsets[(((i*3)+j)*2)+1] = (-1.0f * yInc) + ((GLfloat)j * yInc);
+               }
+       }
+
+       SetupTexture();
+}
+
+void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas)
+{
+       if(numberoffilters<=0 || !isshadersupported)
+               return;
+
+       if(canvaswidth != canvas->GetWidth() || canvasheight != canvas->GetHeight())
+       {
+               UpdateOffsetMatrix(canvas->GetWidth(), canvas->GetHeight());
+       }
+       GLuint  viewport[4]={0};
+
+       int passindex;
+       bool first = true;
+       for(passindex =0; passindex<MAX_RENDER_PASS; passindex++)
+       {
+               if(m_filters[passindex])
+               {
+                       if(first)
+                       {
+                               glGetIntegerv(GL_VIEWPORT,(int*)viewport);
+                               glViewport(0, 0, texturewidth, textureheight);
+
+                               glDisable(GL_DEPTH_TEST);
+                               glMatrixMode(GL_PROJECTION);
+                               glLoadIdentity();
+                               glMatrixMode(GL_MODELVIEW);
+                               glLoadIdentity();
+                               first = false;
+                       }
+                       
+                       StartShaderProgram(m_filters[passindex]);
+
+                       glBindTexture(GL_TEXTURE_2D, texname);
+                       glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, texturewidth, textureheight, 0);
+
+                       glClear(GL_COLOR_BUFFER_BIT);
+
+                       glBegin(GL_QUADS);
+                               glColor4f(1.f, 1.f, 1.f, 1.f);
+                               glTexCoord2f(1.0, 1.0); glVertex2f(1,1);
+                               glTexCoord2f(0.0, 1.0); glVertex2f(-1,1);
+                               glTexCoord2f(0.0, 0.0); glVertex2f(-1,-1);
+                               glTexCoord2f(1.0, 0.0); glVertex2f(1,-1);
+                       glEnd();
+               }
+       }
+
+       if(!first)
+       {
+               glEnable(GL_DEPTH_TEST);
+               glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
+               EndShaderProgram();     
+       }
+}
+
+void RAS_2DFilterManager::EnableFilter(RAS_2DFILTER_MODE mode, int pass)
+{
+       if(!isshadersupported)
+               return;
+       if( pass == -1)
+       {
+               if(m_programs[mode] == 0)
+               m_programs[mode] = CreateShaderProgram(mode);
+       }
+       else if( pass < MAX_RENDER_PASS )
+       {
+               if(mode == RAS_2DFILTER_NOFILTER )
+               {
+                       if(m_filters[pass] != 0)
+                               numberoffilters--;
+                       m_filters[pass] = 0;
+               }
+               else
+               {
+                       if(!m_programs[mode])
+                               m_programs[mode] = CreateShaderProgram(mode);
+                       if(m_programs[mode])
+                       {
+                               if(m_filters[pass] == 0)
+                                       numberoffilters++;
+                               m_filters[pass] = mode;
+                       }
+               }
+       }
+}
diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.h b/source/gameengine/Rasterizer/RAS_2DFilterManager.h
new file mode 100644 (file)
index 0000000..e2d9dce
--- /dev/null
@@ -0,0 +1,59 @@
+#ifndef __RAS_I2DFILTER
+#define __RAS_I2DFILTER
+
+
+
+#define MAX_RENDER_PASS        100
+
+class RAS_2DFilterManager
+{
+private:
+       unsigned int    CreateShaderProgram(char* shadersource);
+       unsigned int    CreateShaderProgram(int filtermode);
+       void                    StartShaderProgram(int filtermode);
+       void                    EndShaderProgram();
+
+       float                   textureoffsets[18];
+       float                   view[4];
+       unsigned int    texname;
+       int                             texturewidth;
+       int                             textureheight;
+       int                             canvaswidth;
+       int                             canvasheight;
+       int                             numberoffilters;
+
+       bool                    isshadersupported;
+public:
+       enum RAS_2DFILTER_MODE {
+               RAS_2DFILTER_NOFILTER = 0,
+               RAS_2DFILTER_MOTIONBLUR,
+               RAS_2DFILTER_BLUR,
+               RAS_2DFILTER_SHARPEN,
+               RAS_2DFILTER_DILATION,
+               RAS_2DFILTER_EROSION,
+               RAS_2DFILTER_LAPLACIAN,
+               RAS_2DFILTER_SOBEL,
+               RAS_2DFILTER_PREWITT,
+               RAS_2DFILTER_GRAYSCALE,
+               RAS_2DFILTER_SEPIA,
+               RAS_2DFILTER_INVERT,
+               RAS_2DFILTER_NUMBER_OF_FILTERS
+       };
+
+       int     m_filters[MAX_RENDER_PASS];
+
+       unsigned int m_programs[RAS_2DFILTER_NUMBER_OF_FILTERS];
+       
+       RAS_2DFilterManager();
+
+       ~RAS_2DFilterManager();
+
+       void SetupTexture();
+
+       void UpdateOffsetMatrix(int width, int height);
+
+       void RenderFilters(RAS_ICanvas* canvas);
+
+       void EnableFilter(RAS_2DFILTER_MODE mode, int pass);
+};
+#endif
index 114783b9a47a9908e5aaaf425f0e72f29429bbc2..e7cb1c9176f589548c3b3db4aaec48eff204faeb 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "MT_Transform.h"
 #include "RAS_IRasterizer.h"
+#include "RAS_2DFilterManager.h"
 
 #include <vector>
 #include <algorithm>
@@ -41,6 +42,7 @@
 class          RAS_IPolyMaterial;
 struct         RAS_LightObject;
 
+
 class RAS_IRenderTools
 {
 
@@ -52,7 +54,8 @@ protected:
        bool    m_modified;
        
        std::vector<struct      RAS_LightObject*> m_lights;
-
+       
+       RAS_2DFilterManager m_filtermanager;
 
 public:
        enum RAS_TEXT_RENDER_MODE {
@@ -61,7 +64,7 @@ public:
                RAS_TEXT_PADDED,
                RAS_TEXT_MAX
        };
-       
+
        RAS_IRenderTools(
        ) :
                m_clientobject(NULL),
@@ -178,6 +181,14 @@ public:
                void
        MotionBlur(RAS_IRasterizer* rasterizer)=0;
 
+       virtual
+               void
+               Update2DFilter(RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass)=0;
+
+       virtual
+               void
+               Render2DFilters(RAS_ICanvas* canvas)=0;
+
        virtual 
                class RAS_IPolyMaterial*        
        CreateBlenderPolyMaterial(
@@ -200,3 +211,4 @@ public:
 #endif //__RAS_IRENDERTOOLS
 
 
+
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h
new file mode 100644 (file)
index 0000000..ae7f561
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef __RAS_BLUR2DFILTER
+#define __RAS_BLUR2DFILTER
+
+char * BlurFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+uniform vec2 tc_offset[9];
+
+void main(void)
+{
+    vec4 sample[9];
+
+    for (int i = 0; i < 9; i++)
+    {
+        sample[i] = texture2D(sampler0, 
+                              gl_TexCoord[0].st + tc_offset[i]);
+    }
+
+    gl_FragColor = (sample[0] + (2.0*sample[1]) + sample[2] + 
+                    (2.0*sample[3]) + sample[4] + (2.0*sample[5]) + 
+                    sample[6] + (2.0*sample[7]) + sample[8]) / 13.0;
+}
+);
+#endif
+
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h
new file mode 100644 (file)
index 0000000..6fd7f86
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef __RAS_DILATION2DFILTER
+#define __RAS_DILATION2DFILTER
+
+char * DilationFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+uniform vec2 tc_offset[9];
+
+void main(void)
+{
+    vec4 sample[9];
+    vec4 maxValue = vec4(0.0);
+
+    for (int i = 0; i < 9; i++)
+    {
+        sample[i] = texture2D(sampler0, 
+                              gl_TexCoord[0].st + tc_offset[i]);
+        maxValue = max(sample[i], maxValue);
+    }
+
+    gl_FragColor = maxValue;
+}
+);
+#endif
+
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h
new file mode 100644 (file)
index 0000000..a0fc748
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef __RAS_EROSION2DFILTER
+#define __RAS_EROSION2DFILTER
+
+char * ErosionFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+uniform vec2 tc_offset[9];
+
+void main(void)
+{
+    vec4 sample[9];
+    vec4 minValue = vec4(1.0);
+
+    for (int i = 0; i < 9; i++)
+    {
+        sample[i] = texture2D(sampler0, 
+                              gl_TexCoord[0].st + tc_offset[i]);
+        minValue = min(sample[i], minValue);
+    }
+
+    gl_FragColor = minValue;
+}
+);
+#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h
new file mode 100644 (file)
index 0000000..c6fc4a0
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __RAS_GRAYSCALE2DFILTER
+#define __RAS_GRAYSCALE2DFILTER
+
+char * GrayScaleFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+
+void main(void)
+{
+       vec4 texcolor = texture2D(sampler0, gl_TexCoord[0].st); 
+       float gray = dot(texcolor.rgb, vec3(0.299, 0.587, 0.114));
+    gl_FragColor = vec4(gray, gray, gray, texcolor.a);
+}
+);
+#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h
new file mode 100644 (file)
index 0000000..34e6fe2
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __RAS_INVERT2DFILTER
+#define __RAS_INVERT2DFILTER
+
+char * InvertFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+uniform vec2 offset[9];
+
+void main(void)
+{
+       vec4 texcolor = texture2D(sampler0, gl_TexCoord[0].st); 
+       gl_FragColor.rgb = 1.0 - texcolor.rgb;
+    gl_FragColor.a = texcolor.a;
+}
+);
+#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h
new file mode 100644 (file)
index 0000000..f5b44a6
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef __RAS_LAPLACION2DFILTER
+#define __RAS_LAPLACION2DFILTER
+
+char * LaplacionFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+uniform vec2 tc_offset[9];
+
+void main(void)
+{
+    vec4 sample[9];
+
+    for (int i = 0; i < 9; i++)
+    {
+        sample[i] = texture2D(sampler0, 
+                              gl_TexCoord[0].st + tc_offset[i]);
+    }
+
+    gl_FragColor = (sample[4] * 8.0) - 
+                    (sample[0] + sample[1] + sample[2] + 
+                     sample[3] + sample[5] + 
+                     sample[6] + sample[7] + sample[8]);
+       gl_FragColor = vec4(gl_FragColor.rgb, 1.0);
+}
+);
+#endif
+
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h
new file mode 100644 (file)
index 0000000..a6897bd
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef __RAS_PREWITT2DFILTER
+#define __RAS_PREWITT2DFILTER
+
+char * PrewittFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+uniform vec2 tc_offset[9];
+
+void main(void)
+{
+    vec4 sample[9];
+
+    for (int i = 0; i < 9; i++)
+    {
+        sample[i] = texture2D(sampler0, 
+                              gl_TexCoord[0].st + tc_offset[i]);
+    }
+
+    vec4 horizEdge = sample[2] + sample[5] + sample[8] -
+                     (sample[0] + sample[3] + sample[6]);
+
+    vec4 vertEdge = sample[0] + sample[1] + sample[2] -
+                    (sample[6] + sample[7] + sample[8]);
+
+    gl_FragColor.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) + 
+                            (vertEdge.rgb * vertEdge.rgb));
+    gl_FragColor.a = 1.0;
+}
+
+);
+#endif
+
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h
new file mode 100644 (file)
index 0000000..cfff00e
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __RAS_SEPIA2DFILTER
+#define __RAS_SEPIA2DFILTER
+
+char * SepiaFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+uniform vec2 offset[9];
+
+void main(void)
+{
+       vec4 texcolor = texture2D(sampler0, gl_TexCoord[0].st); 
+       float gray = dot(texcolor.rgb, vec3(0.299, 0.587, 0.114));
+       gl_FragColor = vec4(gray * vec3(1.2, 1.0, 0.8), texcolor.a);
+}
+);
+#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h
new file mode 100644 (file)
index 0000000..6409834
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef __RAS_SHARPEN2DFILTER
+#define __RAS_SHARPEN2DFILTER
+
+char * SharpenFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+uniform vec2 tc_offset[9];
+
+void main(void)
+{
+    vec4 sample[9];
+
+    for (int i = 0; i < 9; i++)
+    {
+        sample[i] = texture2D(sampler0, 
+                              gl_TexCoord[0].st + tc_offset[i]);
+    }
+
+    gl_FragColor = (sample[4] * 9.0) - 
+                    (sample[0] + sample[1] + sample[2] + 
+                     sample[3] + sample[5] + 
+                     sample[6] + sample[7] + sample[8]);
+}
+);
+#endif
+
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h
new file mode 100644 (file)
index 0000000..da1d347
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef __RAS_SOBEL2DFILTER
+#define __RAS_SOBEL2DFILTER
+
+char * SobelFragmentShader=STRINGIFY(
+uniform sampler2D sampler0;
+uniform vec2 tc_offset[9];
+
+void main(void)
+{
+    vec4 sample[9];
+
+    for (int i = 0; i < 9; i++)
+    {
+        sample[i] = texture2D(sampler0, 
+                              gl_TexCoord[0].st + tc_offset[i]);
+    }
+
+    vec4 horizEdge = sample[2] + (2.0*sample[5]) + sample[8] -
+                     (sample[0] + (2.0*sample[3]) + sample[6]);
+
+    vec4 vertEdge = sample[0] + (2.0*sample[1]) + sample[2] -
+                    (sample[6] + (2.0*sample[7]) + sample[8]);
+
+    gl_FragColor.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) + 
+                            (vertEdge.rgb * vertEdge.rgb));
+    gl_FragColor.a = 1.0;
+}
+);
+#endif
+