[Orxonox-commit 4738] r9407 - in code/branches/shaders/src/orxonox: . graphics

davidsa at orxonox.net davidsa at orxonox.net
Sun Oct 21 17:32:00 CEST 2012


Author: davidsa
Date: 2012-10-21 17:32:00 +0200 (Sun, 21 Oct 2012)
New Revision: 9407

Added:
   code/branches/shaders/src/orxonox/RenderQueueListener.cc
   code/branches/shaders/src/orxonox/RenderQueueListener.h
Modified:
   code/branches/shaders/src/orxonox/CMakeLists.txt
   code/branches/shaders/src/orxonox/OrxonoxPrereqs.h
   code/branches/shaders/src/orxonox/Scene.cc
   code/branches/shaders/src/orxonox/graphics/Model.cc
   code/branches/shaders/src/orxonox/graphics/Model.h
Log:
orxonox::RenderQueueListener: Implemented a rudimentary RenderQueueListener to enable the use of stencil buffer for elaborate alpha blending shaders without creating artifacts from overlapping faces. Also added a XML Port to assign a Model to a certain RenderQueueGroup. Needs to be improved to allow the use of strings for choosing the group instead of a static int which may change in the feature.

Modified: code/branches/shaders/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/shaders/src/orxonox/CMakeLists.txt	2012-10-21 13:46:43 UTC (rev 9406)
+++ code/branches/shaders/src/orxonox/CMakeLists.txt	2012-10-21 15:32:00 UTC (rev 9407)
@@ -36,6 +36,7 @@
 BUILD_UNIT SceneBuildUnit.cc
   CameraManager.cc
   Scene.cc
+  RenderQueueListener.cc
 END_BUILD_UNIT
 )
 

Modified: code/branches/shaders/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/branches/shaders/src/orxonox/OrxonoxPrereqs.h	2012-10-21 13:46:43 UTC (rev 9406)
+++ code/branches/shaders/src/orxonox/OrxonoxPrereqs.h	2012-10-21 15:32:00 UTC (rev 9407)
@@ -75,6 +75,7 @@
     class PawnManager;
     class PlayerManager;
     class Radar;
+    class RenderQueueListener;
     class Scene;
 
     // chat

Added: code/branches/shaders/src/orxonox/RenderQueueListener.cc
===================================================================
--- code/branches/shaders/src/orxonox/RenderQueueListener.cc	                        (rev 0)
+++ code/branches/shaders/src/orxonox/RenderQueueListener.cc	2012-10-21 15:32:00 UTC (rev 9407)
@@ -0,0 +1,68 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   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.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *      Reto Grieder (physics)
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "RenderQueueListener.h"
+
+#include <OgreRoot.h>
+#include <OgreRenderQueueListener.h>
+
+namespace orxonox
+{
+    void RenderQueueListener::renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation)
+    {
+        if (queueGroupId == RENDER_QUEUE_STENCIL_OBJECTS)
+        { 
+            Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); 
+
+            renderSystem->clearFrameBuffer(Ogre::FBT_STENCIL); 
+            renderSystem->setStencilCheckEnabled(true); 
+            renderSystem->setStencilBufferParams(Ogre::CMPF_ALWAYS_PASS,
+                STENCIL_VALUE_FOR_GLOW, STENCIL_FULL_MASK, 
+                Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
+        } 
+        if (queueGroupId == RENDER_QUEUE_STENCIL_GLOW)
+        { 
+              Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); 
+              renderSystem->setStencilCheckEnabled(true); 
+              renderSystem->setStencilBufferParams(Ogre::CMPF_NOT_EQUAL,
+                  STENCIL_VALUE_FOR_GLOW, STENCIL_FULL_MASK, 
+                  Ogre::SOP_KEEP,Ogre::SOP_KEEP,Ogre::SOP_REPLACE,false);       
+        }
+    }
+   
+    void RenderQueueListener::renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation)
+    {
+        if (queueGroupId == RENDER_QUEUE_STENCIL_LAST) 
+        {
+            Ogre::RenderSystem * renderSystem = Ogre::Root::getSingleton().getRenderSystem(); 
+            renderSystem->setStencilCheckEnabled(false); 
+            renderSystem->setStencilBufferParams(); 
+        }
+    }
+}
\ No newline at end of file

Added: code/branches/shaders/src/orxonox/RenderQueueListener.h
===================================================================
--- code/branches/shaders/src/orxonox/RenderQueueListener.h	                        (rev 0)
+++ code/branches/shaders/src/orxonox/RenderQueueListener.h	2012-10-21 15:32:00 UTC (rev 9407)
@@ -0,0 +1,60 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   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.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *      Reto Grieder (physics)
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _ORenderQueueListener_H__
+#define _ORenderQueueListener_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <OgreRenderQueueListener.h>
+
+namespace orxonox
+{
+    /* Defining some render queue groups based around the main render queue to enable a stenicl buffer based glow effect */
+    enum RenderQueueGroupID
+    {
+        RENDER_QUEUE_MAIN = Ogre::RENDER_QUEUE_MAIN,
+        RENDER_QUEUE_STENCIL_OBJECTS = RENDER_QUEUE_MAIN+1,
+        RENDER_QUEUE_STENCIL_GLOW = RENDER_QUEUE_MAIN+2,
+        RENDER_QUEUE_STENCIL_LAST = RENDER_QUEUE_STENCIL_GLOW
+    };
+
+    const int STENCIL_VALUE_FOR_GLOW = 1; //if more than one type of stencil mask is to be used it needs to use another value
+    const int STENCIL_FULL_MASK = 0xFFFFFFFF;
+    
+    /* Deriving from the Ogre RenderQueueListener to define our own handling of the different rendering stages to enable alpha based shader/glow effects */
+    class _OrxonoxExport RenderQueueListener : public Ogre::RenderQueueListener
+    {
+        public:
+            virtual void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation);
+            virtual void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation);
+    };
+}
+
+#endif /* _ORenderQueueListener_H__ */
\ No newline at end of file

Modified: code/branches/shaders/src/orxonox/Scene.cc
===================================================================
--- code/branches/shaders/src/orxonox/Scene.cc	2012-10-21 13:46:43 UTC (rev 9406)
+++ code/branches/shaders/src/orxonox/Scene.cc	2012-10-21 15:32:00 UTC (rev 9407)
@@ -47,6 +47,7 @@
 #include "Radar.h"
 #include "worldentities/WorldEntity.h"
 #include "Level.h"
+#include "RenderQueueListener.h"
 
 namespace orxonox
 {
@@ -65,6 +66,8 @@
             assert(Ogre::Root::getSingletonPtr());
             this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);
             this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
+            RenderQueueListener* renderQueueListener = new RenderQueueListener();
+            this->sceneManager_->addRenderQueueListener(renderQueueListener);//add our own renderQueueListener
 
             this->radar_ = new Radar();
         }

Modified: code/branches/shaders/src/orxonox/graphics/Model.cc
===================================================================
--- code/branches/shaders/src/orxonox/graphics/Model.cc	2012-10-21 13:46:43 UTC (rev 9406)
+++ code/branches/shaders/src/orxonox/graphics/Model.cc	2012-10-21 15:32:00 UTC (rev 9407)
@@ -43,7 +43,7 @@
     CreateFactory(Model);
 
     Model::Model(BaseObject* creator) :
-        StaticEntity(creator), bCastShadows_(true), lodLevel_(5), bLodEnabled_(true), numLodLevels_(10), lodReductionRate_(.15f)
+        StaticEntity(creator), bCastShadows_(true), renderQueueGroup_(RENDER_QUEUE_STENCIL_OBJECTS), lodLevel_(5), bLodEnabled_(true), numLodLevels_(10), lodReductionRate_(.15f)
     {
         RegisterObject(Model);
 
@@ -70,6 +70,7 @@
         XMLPortParam(Model, "lodLevel", setLodLevel, getLodLevel, xmlelement, mode);
 
         XMLPortParam(Model, "mesh", setMeshSource, getMeshSource, xmlelement, mode);
+        XMLPortParam(Model, "renderQueueGroup", setRenderQueueGroup, getRenderQueueGroup, xmlelement, mode);
         XMLPortParam(Model, "material", setMaterial, getMaterial, xmlelement, mode);
         XMLPortParam(Model, "shadow", setCastShadows, getCastShadows, xmlelement, mode).defaultValues(true);
     }
@@ -77,6 +78,8 @@
     void Model::registerVariables()
     {
         registerVariable(this->meshSrc_,    VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedMesh));
+        registerVariable(this->renderQueueGroup_,    VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedRenderQueueGroup));
+        registerVariable(this->materialName_,    VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedMaterial));
         registerVariable(this->bCastShadows_, VariableDirection::ToClient, new NetworkCallback<Model>(this, &Model::changedShadows));
     }
 
@@ -111,6 +114,17 @@
         }
     }
 
+    void Model::changedRenderQueueGroup()
+    {
+        if (GameMode::showsGraphics())
+        {
+            if (this->mesh_.getEntity())
+            {
+                this->mesh_.getEntity()->setRenderQueueGroup(this->renderQueueGroup_);
+            }
+        }
+    }
+
     void Model::changedMaterial()
     {
         this->mesh_.setMaterial(this->materialName_);

Modified: code/branches/shaders/src/orxonox/graphics/Model.h
===================================================================
--- code/branches/shaders/src/orxonox/graphics/Model.h	2012-10-21 13:46:43 UTC (rev 9406)
+++ code/branches/shaders/src/orxonox/graphics/Model.h	2012-10-21 15:32:00 UTC (rev 9407)
@@ -33,6 +33,7 @@
 
 #include <string>
 #include "tools/Mesh.h"
+#include "RenderQueueListener.h"
 #include "worldentities/StaticEntity.h"
 
 namespace orxonox
@@ -57,6 +58,12 @@
             inline const std::string& getMeshSource() const
                 { return this->meshSrc_; }
 
+            //TODO: let this function accept strings instead of ints for the XML Port, so we don't have to rely on static int values which may change in future Ogre revisions
+            inline void setRenderQueueGroup(const int renderQueueGroup)
+                { this->renderQueueGroup_ = renderQueueGroup; this->changedRenderQueueGroup(); }
+            inline const int getRenderQueueGroup() const
+                { return this->renderQueueGroup_; }
+
             inline void setCastShadows(bool bCastShadows)
                 { this->bCastShadows_ = bCastShadows; this->changedShadows(); }
             inline bool getCastShadows() const
@@ -70,6 +77,7 @@
         protected:
             void registerVariables();
             void changedMesh();
+            void changedRenderQueueGroup();
             void changedMaterial();
             void changedShadows();
 
@@ -85,6 +93,7 @@
             std::string meshSrc_;
             Mesh mesh_;
             bool bCastShadows_;
+            int renderQueueGroup_;
             std::string materialName_;
 
             //LoD




More information about the Orxonox-commit mailing list