diff options
author | Mal Duffin <malachyduffin@gmail.com> | 2007-09-29 22:51:01 +0400 |
---|---|---|
committer | Mal Duffin <malachyduffin@gmail.com> | 2007-09-29 22:51:01 +0400 |
commit | 51b56a4d3f17e8cea35ba02132af0c2b893e1ff2 (patch) | |
tree | 721c5d1d3e015cb4432e22d4bf23f75d93319ad9 /source | |
parent | ae40a1d86e5917dbd23ac4bcdcbeca07a3505e0d (diff) |
GE Patch by Hamed Zaghaghi - Adding Motion Blur to the Game Engine.
I reviewed the code, suggested an update ( initialising accumulation buffer ), and tested the resulting update successfully.
It's great to see more GE developers!GE Patch by Hamed Zaghaghi to add motion blur to the GE ( using the accumulation buffer ).
I reviewed code and tested, gave some feedback ( initialising accumulation buffer ) which was implemented straight away, and re-reviewed.
It's great to have another GE coder on the team!
Diffstat (limited to 'source')
10 files changed, 130 insertions, 3 deletions
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp index caf3d120fab..463f06869d6 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp @@ -452,4 +452,27 @@ RAS_IPolyMaterial* KX_BlenderRenderTools::CreateBlenderPolyMaterial( return NULL; } +void KX_BlenderRenderTools::MotionBlur(RAS_IRasterizer* rasterizer) +{ + int state = rasterizer->GetMotionBlurState(); + float motionblurvalue; + if(state) + { + motionblurvalue = rasterizer->GetMotionBlurValue(); + if(state==1) + { + //bugfix:load color buffer into accum buffer for the first time(state=1) + glAccum(GL_LOAD, 1.0); + rasterizer->SetMotionBlurState(2); + } + else if(motionblurvalue>=0.0 && motionblurvalue<=1.0) + { + glAccum(GL_MULT, motionblurvalue); + glAccum(GL_ACCUM, 1-motionblurvalue); + glAccum(GL_RETURN, 1.0); + glFlush(); + } + } +} + unsigned int KX_BlenderRenderTools::m_numgllights; diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h index dc638d1a43a..a79302a283e 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h @@ -100,7 +100,10 @@ public: void* tface); bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data); + + virtual void MotionBlur(RAS_IRasterizer* rasterizer); }; #endif //__KX_BLENDERRENDERTOOLS + diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp index 0f6bec30437..cc5c392d51a 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp @@ -570,4 +570,27 @@ void GPC_RenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmatrix,in } } +void GPC_RenderTools::MotionBlur(RAS_IRasterizer* rasterizer) +{ + int state = rasterizer->GetMotionBlurState(); + float motionblurvalue; + if(state) + { + motionblurvalue = rasterizer->GetMotionBlurValue(); + if(state==1) + { + //bugfix:load color buffer into accum buffer for the first time(state=1) + glAccum(GL_LOAD, 1.0); + rasterizer->SetMotionBlurState(2); + } + else if(motionblurvalue>=0.0 && motionblurvalue<=1.0) + { + glAccum(GL_MULT, motionblurvalue); + glAccum(GL_ACCUM, 1-motionblurvalue); + glAccum(GL_RETURN, 1.0); + glFlush(); + } + } +} + unsigned int GPC_RenderTools::m_numgllights; diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.h b/source/gameengine/GamePlayer/common/GPC_RenderTools.h index b7f73df3c34..e1f2a869c22 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.h +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.h @@ -149,6 +149,8 @@ public: int applyLights(int objectlayer); bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data); + + virtual void MotionBlur(RAS_IRasterizer* rasterizer); protected: /** * Copied from KX_BlenderGL.cpp in KX_blenderhook @@ -173,3 +175,4 @@ protected: #endif // __GPC_RENDERTOOLS_H + diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index e76e28bcb7b..f8826245aab 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -966,6 +966,9 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam) scene->CalculateVisibleMeshes(m_rasterizer,cam); scene->RenderBuckets(camtrans, m_rasterizer, m_rendertools); + + m_rendertools->MotionBlur(m_rasterizer); + } @@ -1463,3 +1466,4 @@ void KX_KetsjiEngine::GetOverrideFrameColor(float& r, float& g, float& b) const b = m_overrideFrameColorB; } + diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 7a937d5e349..1a3a0490d21 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -618,7 +618,31 @@ static PyObject* gPyMakeScreenshot(PyObject*, Py_Return; } +static PyObject* gPyEnableMotionBlur(PyObject*, + PyObject* args, + PyObject*) +{ + float motionblurvalue; + if (PyArg_ParseTuple(args,"f",&motionblurvalue)) + { + if(gp_Rasterizer) + { + gp_Rasterizer->EnableMotionBlur(motionblurvalue); + } + } + Py_Return; +} +static PyObject* gPyDisableMotionBlur(PyObject*, + PyObject* args, + PyObject*) +{ + if(gp_Rasterizer) + { + gp_Rasterizer->DisableMotionBlur(); + } + Py_Return; +} STR_String gPyGetWindowHeight__doc__="getWindowHeight doc"; STR_String gPyGetWindowWidth__doc__="getWindowWidth doc"; @@ -645,6 +669,9 @@ static struct PyMethodDef rasterizer_methods[] = { {"setMistColor",(PyCFunction)gPySetMistColor,METH_VARARGS,"set Mist Color (rgb)"}, {"setMistStart",(PyCFunction)gPySetMistStart,METH_VARARGS,"set Mist Start(rgb)"}, {"setMistEnd",(PyCFunction)gPySetMistEnd,METH_VARARGS,"set Mist End(rgb)"}, + {"enableMotionBlur",(PyCFunction)gPyEnableMotionBlur,METH_VARARGS,"enable motion blur"}, + {"disableMotionBlur",(PyCFunction)gPyDisableMotionBlur,METH_VARARGS,"disable motion blur"}, + {"setEyeSeparation", (PyCFunction) gPySetEyeSeparation, METH_VARARGS, "set the eye separation for stereo mode"}, {"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_VARARGS, "get the eye separation for stereo mode"}, diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 8ecc9e7ad05..560c6741260 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -48,7 +48,6 @@ class RAS_IPolyMaterial; */ class RAS_IRasterizer { - public: RAS_IRasterizer(RAS_ICanvas* canv){}; @@ -398,7 +397,15 @@ public: virtual bool QueryLists(){return false;} virtual bool QueryArrays(){return false;} + + virtual void EnableMotionBlur(float motionblurvalue)=0; + virtual void DisableMotionBlur()=0; + + virtual float GetMotionBlurValue()=0; + virtual int GetMotionBlurState()=0; + virtual void SetMotionBlurState(int newstate)=0; }; #endif //__RAS_IRASTERIZER + diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.h b/source/gameengine/Rasterizer/RAS_IRenderTools.h index fa3c777553d..114783b9a47 100644 --- a/source/gameengine/Rasterizer/RAS_IRenderTools.h +++ b/source/gameengine/Rasterizer/RAS_IRenderTools.h @@ -174,6 +174,10 @@ public: struct RAS_LightObject* lightobject ); + virtual + void + MotionBlur(RAS_IRasterizer* rasterizer)=0; + virtual class RAS_IPolyMaterial* CreateBlenderPolyMaterial( @@ -195,3 +199,4 @@ public: #endif //__RAS_IRENDERTOOLS + diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 53ec7a02e6f..85250fcd552 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -82,7 +82,9 @@ RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas) m_setfocallength(false), m_noOfScanlines(32), m_useTang(false), - m_materialCachingInfo(0) + m_materialCachingInfo(0), + m_motionblur(0), + m_motionblurvalue(-1.0) { m_viewmatrix.Identity(); @@ -1979,3 +1981,15 @@ void RAS_OpenGLRasterizer::SetPolygonOffset(float mult, float add) else glDisable(mode); } + +void RAS_OpenGLRasterizer::EnableMotionBlur(float motionblurvalue) +{ + m_motionblur = 1; + m_motionblurvalue = motionblurvalue; +} + +void RAS_OpenGLRasterizer::DisableMotionBlur() +{ + m_motionblur = 0; + m_motionblurvalue = -1.0; +} diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index d95ced658ce..6728905aa57 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -91,6 +91,10 @@ class RAS_OpenGLRasterizer : public RAS_IRasterizer int m_noOfScanlines; bool InterlacedStereo() const; + //motion blur + int m_motionblur; + float m_motionblurvalue; + protected: int m_drawingmode; TexCoGen m_texco[RAS_MAX]; @@ -293,8 +297,22 @@ public: const RAS_TexVert& v2, const RAS_TexVert& v3, const MT_Vector3 &no); - + + virtual void EnableMotionBlur(float motionblurvalue); + virtual void DisableMotionBlur(); + virtual float GetMotionBlurValue(){return m_motionblurvalue;}; + virtual int GetMotionBlurState(){return m_motionblur;}; + virtual void SetMotionBlurState(int newstate) + { + if(newstate<0) + m_motionblur = 0; + else if(newstate>2) + m_motionblur = 2; + else + m_motionblur = newstate; + }; }; #endif //__RAS_OPENGLRASTERIZER + |