Index: code/branches/shaders_merge/src/libraries/tools/Mesh.cc
===================================================================
--- code/branches/shaders_merge/src/libraries/tools/Mesh.cc	(revision 11072)
+++ code/branches/shaders_merge/src/libraries/tools/Mesh.cc	(revision 11073)
@@ -33,4 +33,5 @@
 #include <string>
 #include <OgreEntity.h>
+#include <OgreSubEntity.h>
 #include <OgreSceneManager.h>
 
@@ -93,4 +94,23 @@
     }
 
+    void Mesh::setMaterial(const std::string& name)
+    {
+        if (this->entity_)
+            this->entity_->setMaterialName(name);
+    }
+
+    const std::string& Mesh::getMaterial() const
+    {
+        if (this->entity_)
+        {
+            if(this->entity_->getSubEntity(0))
+                return this->entity_->getSubEntity(0)->getMaterialName(); //return the Material of the first SubEntity, should be enough for now
+            else
+                return BLANKSTRING;
+        }
+        else
+            return BLANKSTRING;
+    }
+
     void Mesh::setVisible(bool bVisible)
     {
Index: code/branches/shaders_merge/src/libraries/tools/Mesh.h
===================================================================
--- code/branches/shaders_merge/src/libraries/tools/Mesh.h	(revision 11072)
+++ code/branches/shaders_merge/src/libraries/tools/Mesh.h	(revision 11073)
@@ -48,4 +48,7 @@
             const std::string& getName() const;
 
+            void setMaterial(const std::string& name);
+            const std::string& getMaterial() const;
+
             void setVisible(bool bVisible);
             bool isVisible() const;
Index: code/branches/shaders_merge/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/shaders_merge/src/orxonox/CMakeLists.txt	(revision 11072)
+++ code/branches/shaders_merge/src/orxonox/CMakeLists.txt	(revision 11073)
@@ -36,4 +36,5 @@
   CameraManager.cc
   Scene.cc
+  RenderQueueListener.cc
 END_BUILD_UNIT
 )
Index: code/branches/shaders_merge/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/branches/shaders_merge/src/orxonox/OrxonoxPrereqs.h	(revision 11072)
+++ code/branches/shaders_merge/src/orxonox/OrxonoxPrereqs.h	(revision 11073)
@@ -75,4 +75,5 @@
     class PlayerManager;
     class Radar;
+    class RenderQueueListener;
     class Scene;
     class GSLevelMemento;
Index: code/branches/shaders_merge/src/orxonox/RenderQueueListener.cc
===================================================================
--- code/branches/shaders_merge/src/orxonox/RenderQueueListener.cc	(revision 11073)
+++ code/branches/shaders_merge/src/orxonox/RenderQueueListener.cc	(revision 11073)
@@ -0,0 +1,124 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+/**
+  @file RenderQueueListener.cc
+  @brief Implementation of the RenderQueueListener class.
+*/
+
+#include "RenderQueueListener.h"
+
+#include <OgreRoot.h>
+#include <OgreRenderQueueListener.h>
+#include <OgreHardwareOcclusionQuery.h>
+
+namespace orxonox
+{
+    RenderQueueListener::RenderQueueListener() : pixelCount_(0), pixelState_(RenderQueueListener::READY_FOR_RENDER)
+    {
+        hardwareOcclusionQuery_ = Ogre::Root::getSingleton().getRenderSystem()->createHardwareOcclusionQuery(); //create a new HOQ for the scene this listener is used in
+    }
+    
+    RenderQueueListener::~RenderQueueListener()
+    {
+        Ogre::Root::getSingleton().getRenderSystem()->destroyHardwareOcclusionQuery(hardwareOcclusionQuery_); //destroy the created HOQ
+    }
+    
+    /**
+    @brief
+    This function is returning the current pixel count and resets the pixel state if we're ready to do another Hardware Occlusion Query
+    
+    @return
+    current pixel count taken from the last Hardware Occlusion Query
+    */
+    unsigned int RenderQueueListener::getPixelCount()
+    {
+        if(this->pixelState_==RenderQueueListener::READY_FOR_ACCESS)
+        {
+            this->hardwareOcclusionQuery_->pullOcclusionQuery(&(this->pixelCount_));
+            this->pixelState_=RenderQueueListener::READY_FOR_RENDER;
+        }
+        return this->pixelCount_;
+    }
+    
+    /**
+    @brief
+    This function is called just before a RenderQueueGroup is rendered, this function is called by Ogre automatically with the correct parameters.
+
+    In this case we use it to set the stencil buffer parameters of the render system and issue a Hardware Occlusion Query
+    */
+    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);       
+        }
+        if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==RenderQueueListener::READY_FOR_RENDER)
+        { 
+            this->hardwareOcclusionQuery_->beginOcclusionQuery();
+            this->pixelState_=RenderQueueListener::QUERY_STARTED;
+            //TODO: Skip this rendering step altogheter if we haven't requested the pixel count yet, not sure if this is possible without a custom SceneManager
+        }
+    }
+    
+    /**
+    @brief
+        This function is called just after a RenderQueueGroup has been rendered, this function is called by Ogre automatically with the correct parameters.
+        
+        in this case we use it to unset the stencil buffer parameters, so the rest of the render queue is unaffected by it.
+    */
+    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(); 
+        }
+        if (queueGroupId == RENDER_QUEUE_HOQ && this->pixelState_==RenderQueueListener::QUERY_STARTED)
+        {
+            this->hardwareOcclusionQuery_->endOcclusionQuery();
+            this->pixelState_=RenderQueueListener::READY_FOR_ACCESS;
+        }
+    }
+}
Index: code/branches/shaders_merge/src/orxonox/RenderQueueListener.h
===================================================================
--- code/branches/shaders_merge/src/orxonox/RenderQueueListener.h	(revision 11073)
+++ code/branches/shaders_merge/src/orxonox/RenderQueueListener.h	(revision 11073)
@@ -0,0 +1,111 @@
+/*
+ *   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:
+ *      ...
+ *
+ */
+
+/**
+  @file RenderQueueListener.h
+  @brief Definition of the RenderQueueListener class.
+*/
+
+#ifndef _ORenderQueueListener_H__
+#define _ORenderQueueListener_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <OgreRenderQueueListener.h>
+#include <OgreHardwareOcclusionQuery.h>
+
+namespace orxonox
+{
+    enum RenderQueueGroupID //!< these are IDs for render queues that are executed just after the main render queue defined by Ogre, we need more than one for Stencil Glow
+    {
+        RENDER_QUEUE_MAIN = Ogre::RENDER_QUEUE_MAIN, //reference to the main render queue
+        RENDER_QUEUE_STENCIL_OBJECTS = RENDER_QUEUE_MAIN+1,
+        RENDER_QUEUE_STENCIL_GLOW = RENDER_QUEUE_MAIN+2,
+        RENDER_QUEUE_STENCIL_LAST = RENDER_QUEUE_STENCIL_GLOW, //this is a reference to the last render queue to be affected by stencil glow effects
+        RENDER_QUEUE_HOQ = RENDER_QUEUE_STENCIL_LAST+1 //this is where we render the objects for occlusion queries (use transparent material)
+    };
+
+    const int STENCIL_VALUE_FOR_GLOW = 1; //!< this is a reference value for our mask, 
+                                          //!< if more than one type of stencil mask is to be used, each of them need their own value
+    const int STENCIL_FULL_MASK = 0xFFFFFFFF; //!< this is a reference mask used in our stencil buffer
+    
+    /**
+    @brief
+        This class derives from the Ogre-Class RenderQueueListener and provides a way to define new rendering stages to enable use of e.g. stencil buffers
+        to increase the number of shader effects we can create. Especially important for shader-based alpha blending.
+
+    @author
+        David 'davidsa' Salvisberg
+    */
+    class _OrxonoxExport RenderQueueListener : public Ogre::RenderQueueListener
+    {
+        public:
+            RenderQueueListener();
+            ~RenderQueueListener();
+    
+            /**
+            @brief
+            This function is returning the current pixel count and resets the pixel state if we're ready to do another Hardware Occlusion Query
+            
+            @return
+            current pixel count taken from the last Hardware Occlusion Query
+            */
+            unsigned int getPixelCount();
+            
+            /**
+            @brief
+                This function is called just before a RenderQueueGroup is rendered, this function is called by Ogre automatically with the correct parameters.
+                
+                In this case we use it to set the stencil buffer parameters of the render system
+            */
+            virtual void renderQueueStarted(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation);
+            /**
+            @brief
+                This function is called just after a RenderQueueGroup has been rendered, this function is called by Ogre automatically with the correct parameters.
+                
+                in this case we use it to unset the stencil buffer parameters, so the rest of the render queue is unaffected by it.
+            */
+            virtual void renderQueueEnded(Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation);
+            
+        private:
+            Ogre::HardwareOcclusionQuery* hardwareOcclusionQuery_; //!< this stores the current instance of the HOQ used in the render system
+            unsigned int pixelCount_; //!< this stores the last pixel count returned by the last HOQ in the corresponding render group
+            
+            enum PixelState //!< enum to distinguish the several HOQ pixel count states
+            {
+                READY_FOR_RENDER,
+                QUERY_STARTED,
+                READY_FOR_ACCESS
+            };
+            
+            PixelState pixelState_; //!< this stores the current state of the Hardware Occlusion Query
+    };
+}
+
+#endif /* _ORenderQueueListener_H__ */
Index: code/branches/shaders_merge/src/orxonox/Scene.cc
===================================================================
--- code/branches/shaders_merge/src/orxonox/Scene.cc	(revision 11072)
+++ code/branches/shaders_merge/src/orxonox/Scene.cc	(revision 11073)
@@ -27,4 +27,10 @@
  *
  */
+
+/**
+@file Scene.cc
+@brief Implementation of Scene Class
+*/
+
 
 #include "Scene.h"
@@ -51,9 +57,15 @@
 #include "worldentities/WorldEntity.h"
 #include "Level.h"
+#include "RenderQueueListener.h"
 
 namespace orxonox
 {
     RegisterClass(Scene);
-
+    
+    /**
+    @brief 
+        Constructor, it sets common standard paramters for a scene depending on whether it will be rendered or not.
+        It also makes sure we user our own render queue listener for rendering instead of the standard listener provided by Ogre
+    */
     SetConsoleCommand("Scene", "debugDrawPhysics", &Scene::consoleCommand_debugDrawPhysics).addShortcut().defaultValue(1, true).defaultValue(2, 0.5f);
 
@@ -75,4 +87,6 @@
             this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);
             this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
+            this->renderQueueListener_ = new RenderQueueListener();
+            this->sceneManager_->addRenderQueueListener(this->renderQueueListener_);//add our own renderQueueListener
 
             this->radar_ = new Radar();
Index: code/branches/shaders_merge/src/orxonox/Scene.h
===================================================================
--- code/branches/shaders_merge/src/orxonox/Scene.h	(revision 11072)
+++ code/branches/shaders_merge/src/orxonox/Scene.h	(revision 11073)
@@ -28,4 +28,9 @@
  */
 
+/**
+@file Scene.h
+@brief Definition of Scene Class
+*/
+
 #ifndef _Scene_H__
 #define _Scene_H__
@@ -49,4 +54,10 @@
     {
         public:
+            /**
+            @brief 
+                This class holds a Scene which is a collection of all kinds of objects to be rendered in the same space,
+                with the same physics and the same light properties. Objects can be anything from a light source, over non physical objects
+                like Billboards to just plain Models with an attached Mesh
+            */
             Scene(Context* context);
             virtual ~Scene();
@@ -59,4 +70,6 @@
             inline Ogre::SceneNode* getRootSceneNode() const
                 { return this->rootSceneNode_; }
+            inline RenderQueueListener* getRenderQueueListener() const
+                { return this->renderQueueListener_; }
 
             void setSkybox(const std::string& skybox);
@@ -95,13 +108,14 @@
                 { this->setShadow(this->bShadows_); }
 
-            Ogre::SceneManager*      sceneManager_;
-            Ogre::SceneNode*         rootSceneNode_;
+            Ogre::SceneManager*      sceneManager_; //!< This is a pointer to the Ogre SceneManager we're using to render the Scene
+            Ogre::SceneNode*         rootSceneNode_; //!< This is a pointer to the root node of the Scene tree
+            RenderQueueListener*     renderQueueListener_; //!< this is a pointer to the RenderQueueListener we're using for this Scene
 
-            std::string              skybox_;
-            ColourValue              ambientLight_;
-            std::list<BaseObject*>   objects_;
-            bool                     bShadows_;
-            float                    soundReferenceDistance_;
-            Radar*                   radar_;
+            std::string              skybox_; //!< This string holds information about the skybox we're using
+            ColourValue              ambientLight_; //!< This variable holds the color value for the ambient light in our scene, usually black in space
+            std::list<BaseObject*>   objects_; //!< This list holds all the objects created in our scene
+            bool                     bShadows_; //!< Do we want shadows in our scene?
+            float                    soundReferenceDistance_; //!< This holds a reference distance, which represents the distance between our scene and the listener
+            Radar*                   radar_; //!< This is a pointer to a Radar object assigned with this scene
 
 
Index: code/branches/shaders_merge/src/orxonox/graphics/Billboard.cc
===================================================================
--- code/branches/shaders_merge/src/orxonox/graphics/Billboard.cc	(revision 11072)
+++ code/branches/shaders_merge/src/orxonox/graphics/Billboard.cc	(revision 11073)
@@ -171,3 +171,21 @@
         }
     }
+    
+    void Billboard::setRenderQueueGroup(unsigned char groupID)
+    {
+        Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
+        if( bSet != NULL )
+        {
+            bSet->setRenderQueueGroup(groupID);
+        }
+    }
+    
+    void Billboard::disableFrustumCulling()
+    {
+        Ogre::BillboardSet* bSet = this->billboard_.getBillboardSet();
+        if( bSet != NULL )
+        {
+            bSet->setBounds(Ogre::AxisAlignedBox(Ogre::AxisAlignedBox::EXTENT_INFINITE),0);
+        }
+    }
 }
Index: code/branches/shaders_merge/src/orxonox/graphics/Billboard.h
===================================================================
--- code/branches/shaders_merge/src/orxonox/graphics/Billboard.h	(revision 11072)
+++ code/branches/shaders_merge/src/orxonox/graphics/Billboard.h	(revision 11073)
@@ -81,4 +81,8 @@
             
             void setDefaultDimensions(float width, float height);
+            
+            void setRenderQueueGroup(unsigned char groupID);
+            
+            void disableFrustumCulling();
 
 
Index: code/branches/shaders_merge/src/orxonox/graphics/CMakeLists.txt
===================================================================
--- code/branches/shaders_merge/src/orxonox/graphics/CMakeLists.txt	(revision 11072)
+++ code/branches/shaders_merge/src/orxonox/graphics/CMakeLists.txt	(revision 11073)
@@ -13,4 +13,5 @@
   Backlight.cc
   Camera.cc
+  LensFlare.cc
   Light.cc
 END_BUILD_UNIT
Index: code/branches/shaders_merge/src/orxonox/graphics/LensFlare.cc
===================================================================
--- code/branches/shaders_merge/src/orxonox/graphics/LensFlare.cc	(revision 11073)
+++ code/branches/shaders_merge/src/orxonox/graphics/LensFlare.cc	(revision 11073)
@@ -0,0 +1,229 @@
+ /*
+ *   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:
+ *      ...
+ *
+ */
+
+/**
+  @file LensFlare.cc
+  @brief Implementation of the LensFlare class.
+*/
+
+#include "LensFlare.h"
+
+#include "core/XMLPort.h"
+#include "graphics/Billboard.h"
+#include "CameraManager.h"
+#include "RenderQueueListener.h"
+
+#include <OgreSphere.h>
+#include <OgreRenderWindow.h>
+
+namespace orxonox
+{
+    RegisterClass(LensFlare);
+    
+    LensFlare::LensFlare(Context* context) : StaticEntity(context), scale_(1.0f), fadeOnViewBorder_(true), fadeResolution_(7), fadeExponent_(2.0f), colour_(new ColourValue(1.0f,0.9f,0.9f))
+    {
+        RegisterObject(LensFlare);
+        
+        this->lensConfiguration_=new std::vector<LensFlare::Lens*>();
+        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/burst"),1.0f,1.0f,1.0f)); //main burst
+        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/burst"),0.7f,1.2f,1.05f)); //secondary burst
+        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/bursthalo"),0.7f,0.9f,1.0f)); //halo around main burst
+        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/ring"),0.1f,2.5f,0.9f)); //all the different distanced lenses
+        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/iris"),0.1f,0.2f,0.5f));
+        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo5"),0.1f,0.3f,0.45f));
+        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo5"),0.4f,0.2f,0.35f));
+        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/iris"),0.1f,0.4f,0.25f));
+        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo4"),0.05f,0.2f,0.2f));
+        
+        this->createBillboards();
+        
+        this->registerVariables();
+    }
+
+    LensFlare::~LensFlare()
+    {
+    }
+
+    void LensFlare::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(LensFlare, XMLPort, xmlelement, mode);
+        XMLPortParam(LensFlare, "scale", setScale, getScale, xmlelement, mode).defaultValues(1.0f);
+        XMLPortParam(LensFlare, "fadeOnViewBorder", setFadeOnViewBorder, isFadeOnViewBorder, xmlelement, mode).defaultValues(true);
+        XMLPortParam(LensFlare, "fadeResolution", setFadeResolution, getFadeResolution, xmlelement, mode).defaultValues(7);
+        XMLPortParam(LensFlare, "fadeExponent", setFadeExponent, getFadeExponent, xmlelement, mode).defaultValues(2.0f);
+        XMLPortParam(LensFlare, "colour", setColour, getColour, xmlelement, mode);
+    }
+    
+    void LensFlare::registerVariables()
+    {
+        registerVariable(this->scale_, VariableDirection::ToClient);
+        registerVariable(this->fadeOnViewBorder_, VariableDirection::ToClient);
+        registerVariable(this->fadeResolution_, VariableDirection::ToClient);
+    }
+
+    /**
+    @brief
+        This function creates all the billboards needed for the flare effect
+    */
+    void LensFlare::createBillboards()
+    {
+        this->occlusionBillboard_ = new Billboard(this->getContext());
+        this->occlusionBillboard_->setMaterial("lensflare/hoq");
+        this->occlusionBillboard_->setVisible(false);
+        this->occlusionBillboard_->disableFrustumCulling();
+        this->occlusionBillboard_->setRenderQueueGroup(RENDER_QUEUE_HOQ);
+        this->attach(this->occlusionBillboard_);
+        
+        for(std::vector<LensFlare::Lens*>::iterator it = lensConfiguration_->begin(); it != lensConfiguration_->end(); ++it) {
+            Billboard* lensPart=new Billboard(this->getContext());
+            lensPart->setMaterial(*(*it)->material_);
+            lensPart->disableFrustumCulling();
+            lensPart->setVisible(true);
+            this->attach(lensPart);
+        }
+    }
+
+    /**
+    @brief
+        This function updates the states of all the billboards, i.e. their positions, visibilty and dimensions
+    @param viewDirection
+        normalised vector pointing from the current camera to the point light center
+    @param dimension
+        the current dimension of the main billboard, we're always using square billboards
+    @param lightIsVisible
+        is the (point-)light source currently visible
+    */
+    void LensFlare::updateBillboardStates(Vector3& viewDirection, float dimension, bool lightIsVisible)
+    { 
+        this->occlusionBillboard_->setDefaultDimensions(dimension*0.5f,dimension*0.5f);
+        this->occlusionBillboard_->setVisible(lightIsVisible);
+        std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
+        it++;
+        for(int i=0; it != this->getAttachedObjects().end(); it++) {
+            Billboard* billboard=static_cast<Billboard*>(*it);
+            LensFlare::Lens* lens=lensConfiguration_->at(i);
+            billboard->setPosition(-viewDirection*(1.0f-lens->position_));
+            billboard->setVisible(lightIsVisible);
+            billboard->setDefaultDimensions(dimension*lens->scale_,dimension*lens->scale_);
+            i++;
+        }
+    }
+
+    /**
+    @brief
+        This function updates the alpha values for all billboards except for the one used for Hardware Occlusion Querying
+    @param alpha
+        the new alpha value all visible billboards should use
+    */
+    void LensFlare::updateBillboardAlphas(float alpha)
+    {
+        this->colour_->a=alpha;
+        std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
+        it++;
+        for(int i=0;it!=this->getAttachedObjects().end(); it++) {
+            ColourValue* cur=new ColourValue(0,0,0,0);
+            (*cur)+= *(this->colour_);
+            cur->a*=lensConfiguration_->at(i)->alpha_;
+            Billboard* billboard=static_cast<Billboard*>(*it);
+            billboard->setColour(*cur);
+            i++;
+        }
+    }
+    
+    /**
+    @brief
+        This function generates point samples of the main burst billboard according to the fadeResolution and returns how many of them are in the view port
+    @param dimension
+        the current dimension of the main billboard, we're always using square billboards
+    @return
+        the absolute amount of point samples that are currently captured by the camera of the view port
+    */
+    unsigned int LensFlare::getPointCount(float dimension) const
+    {
+        Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera();
+        Vector3 position = this->getWorldPosition();
+        Vector3 nX = camera->getDerivedOrientation().xAxis().normalisedCopy();
+        Vector3 nY = camera->getDerivedOrientation().yAxis().normalisedCopy();
+        int halfRes=fadeResolution_/2;
+        float resDim=dimension/fadeResolution_;
+        unsigned int count=0;
+        for(int i=-halfRes;i<=halfRes;i++)
+        {
+            for(int j=-halfRes;j<=halfRes;j++)
+            {
+                Vector3 point=position+(i*resDim)*nX+(j*resDim)*nY;//generate point samples
+                if(camera->isVisible(point))
+                {
+                    count++;
+                }
+            }
+        }
+        return count;
+    }
+
+    void LensFlare::tick(float dt)
+    {
+        if(this->isVisible())
+        {
+            Ogre::Camera* camera=CameraManager::getInstance().getActiveCamera()->getOgreCamera(); //get active Ogre Camera Instance, so we can check whether the light source is visible
+            this->cameraDistance_=camera->getDerivedPosition().distance(this->getPosition());
+            float dimension=this->cameraDistance_*this->scale_;
+            if(!this->fadeOnViewBorder_)
+            {
+                this->fadeResolution_=3;//this is so we can still determine when the billboard has left the screen
+            }
+            unsigned int pointCount=this->getPointCount(dimension*0.25f*this->scale_);
+            Vector3 viewDirection=this->getWorldPosition()-camera->getDerivedPosition()-camera->getDerivedDirection()*this->cameraDistance_;
+            updateBillboardStates(viewDirection,dimension,pointCount>0);
+            if(pointCount>0) {
+                Ogre::Sphere* sphere=new Ogre::Sphere(this->getPosition(),dimension*0.25f*this->scale_);
+                float left, right, top, bottom;
+                camera->projectSphere(*sphere,&left,&top,&right,&bottom);//approximate maximum pixel count of billboard with a sphere
+                delete sphere;
+                
+                Ogre::RenderWindow* window = GraphicsManager::getInstance().getRenderWindow();
+                float maxCount=(right-left)*(top-bottom)*window->getWidth()*window->getHeight()*0.25f;
+                float pixelCount=this->getScene()->getRenderQueueListener()->getPixelCount();//get pixel count
+                float ratio=(maxCount<0.0f)?0.0f:(pixelCount/maxCount);//prevent underflow and division by zero
+                float borderRatio=1.0f;
+                if(this->fadeOnViewBorder_)
+                {
+                    borderRatio=((float) pointCount)/(((float) fadeResolution_)*((float) fadeResolution_));//ratio for the border fade
+                }
+                //update alpha values of all billboards except the HOQ billboard
+                this->updateBillboardAlphas(std::min(1.0f,std::pow(std::min(ratio,borderRatio),this->fadeExponent_)));
+            }
+        }
+    }
+
+    void LensFlare::changedVisibility()
+    {
+      
+    }
+}
Index: code/branches/shaders_merge/src/orxonox/graphics/LensFlare.h
===================================================================
--- code/branches/shaders_merge/src/orxonox/graphics/LensFlare.h	(revision 11073)
+++ code/branches/shaders_merge/src/orxonox/graphics/LensFlare.h	(revision 11073)
@@ -0,0 +1,194 @@
+ /*
+ *   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:
+ *      ...
+ *
+ */
+
+/**
+  @file LensFlare.h
+  @brief Definition of the LensFlare class.
+*/
+
+#ifndef _LensFlare_H__
+#define _LensFlare_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "OgreBillboardSet.h"
+
+#include "core/GraphicsManager.h"
+#include "util/Math.h"
+#include "worldentities/StaticEntity.h"
+#include "graphics/Billboard.h"
+
+namespace orxonox
+{    
+      /**
+    @brief
+        This class adds a configurable LensFlare effect by adding multiple billboards for the several components of lens flare.
+        It uses orxonox::Billboard to render this effect, the used images can be changed in lensflare.material
+
+    @author
+        David 'davidsa' Salvisberg
+    */
+    //TODO: The Hardware Occlusion only works properly for a single Flare on the screen,
+    // if we have multiple strong lights it'll become way more complicated to determine how much of every object is occluded individually
+    // there's below a 100 render queue groups, so maybe we should take turns for each object to be tested, so we only have one of the objects rendered at a time
+    // obviously we shouldn't use too many of these effects anyways, since they use a lot of processing power, so not sure whether it's worth implementing a solution that works for multiple lens flares on screen 
+    class _OrxonoxExport LensFlare : public StaticEntity, public Tickable
+    {
+          /**
+          @brief
+              This is a nested Class used to easily set properties of the different sublenses of a LensFlare effect
+          */
+          class Lens
+          {
+              public:
+                  std::string* material_;//!< Which material should the Lens use, current choices include burst, bursthalo, halo1, halo2, halo3
+                  float alpha_;//!< Which base alpha value should the Lens use
+                  float scale_;//!< Which base scale should the Lens Flare have
+                  float position_;//!< This defines how far along the view direction the flare should be positioned, e.g. 0.5 would position the flare halfway between the viewer and the base burst, 0 at the camera, 1 at the burst
+                  Lens(std::string* material, float alpha, float scale, float position)
+                  {
+                      this->material_=material;
+                      this->alpha_=alpha;
+                      this->scale_=scale;
+                      this->position_=position;
+                  }
+          };
+          
+        public:
+            LensFlare(Context* context);
+            virtual ~LensFlare();
+            
+            inline void setScale(float scale)
+                { this->scale_=scale; }
+            inline float getScale() const
+                { return this->scale_; }
+                
+            /**
+            @brief
+                This sets the base colour of the billboards
+            @param colour
+                Vector3 containing r,g,b values
+            */
+            inline void setColour(const ColourValue& colour)
+            {
+                this->colour_->r=colour.r;
+                this->colour_->g=colour.g;
+                this->colour_->b=colour.b;
+            }
+            /**
+            @brief
+                This returns the current base colour of the billboards
+            @return a Vector3 containing r,g,b values
+            */
+            inline const ColourValue& getColour() const
+                { return *(new ColourValue(this->colour_->r,this->colour_->g,this->colour_->b)); }
+                
+            /**
+            @brief
+                This sets the resolution of the out-of-screen-fade-effect
+                
+                the higher the resolution, the smoother the transition, but it will also have a greater impact on the performance
+                this happens with O(n^2) since it's a two dimensional operation.
+            @param fadeResolution
+                how many point samples should be used per axis
+                
+                note: this will always be an odd number, so the center point is included in the samples
+            */
+            inline void setFadeResolution(unsigned int fadeResolution)
+                { this->fadeResolution_=fadeResolution>0?fadeResolution:1; }
+            /**
+            @brief
+                This returns the resolution of the out-of-screen-fade-effect
+            @return how many point samples are being used per axis
+            */
+            inline unsigned int getFadeResolution() const
+                { return this->fadeResolution_; }
+                
+            /**
+            @brief
+                This sets the exponent of the fade-out function
+            @param exponent
+                how strong should the fade-out effect be
+            */
+            inline void setFadeExponent(float exponent)
+                { this->fadeExponent_=exponent; }
+            /**
+            @brief
+                This returns the exponent of the fade-out function
+            @return the exponent of the fade-out function
+            */
+            inline float getFadeExponent() const
+                { return this->fadeExponent_; }
+                
+            /**
+            @brief
+               Turn the out-of-screen-fade-effect on or off
+            @param fadeOnViewBorder
+                true to turn the effect on, false to turn it off
+            */
+            inline void setFadeOnViewBorder(bool fadeOnViewBorder)
+                { this->fadeOnViewBorder_=fadeOnViewBorder; }
+            /**
+            @brief
+               Determine whether the out-of-screen-fade-effect is on or off
+            @return
+                true if the effect is on, false if it is off
+            */
+            inline bool isFadeOnViewBorder() const
+                { return this->fadeOnViewBorder_; }
+
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+            virtual void tick(float dt);
+
+            virtual void changedVisibility();
+
+        private:
+            void registerVariables();
+            
+            void createBillboards();
+            
+            void updateBillboardStates(Vector3& viewDirection, float dimension, bool isLightVisible);
+            
+            void updateBillboardAlphas(float alpha);
+            
+            unsigned int getPointCount(float dimension) const;
+            
+            std::vector<Lens*>* lensConfiguration_;//!< this stores the lensConfiguration
+            Billboard* occlusionBillboard_;//!< this is a transparent billboard used solely for the Hardware Occlusion Query
+            float cameraDistance_;//!< current distance of the lensflare center from the camera
+            float scale_;//!< this factor is used to scale the billboard to the desired size
+            bool fadeOnViewBorder_;//!< should the effect fade out on the border of the view?
+            unsigned int fadeResolution_;//!< how many points should be sampled per axis for the screen border fade. High number => smooth fade, but uses more processing power
+            float fadeExponent_;//!< this determines how fast the flare fades away as it gets obstructed
+            ColourValue* colour_;//!< this stores the base colour of the light
+    };
+}
+
+#endif /* _LensFlare_H__ */
Index: code/branches/shaders_merge/src/orxonox/graphics/Model.cc
===================================================================
--- code/branches/shaders_merge/src/orxonox/graphics/Model.cc	(revision 11072)
+++ code/branches/shaders_merge/src/orxonox/graphics/Model.cc	(revision 11073)
@@ -37,4 +37,5 @@
 #include "core/XMLPort.h"
 #include "Scene.h"
+#include "RenderQueueListener.h"
 #include "graphics/MeshLodInformation.h"
 #include "Level.h"
@@ -45,5 +46,5 @@
 
     Model::Model(Context* context) :
-        StaticEntity(context), bCastShadows_(true), lodLevel_(5), bLodEnabled_(true), numLodLevels_(10), lodReductionRate_(.15f)
+        StaticEntity(context), bCastShadows_(true), renderQueueGroup_(RENDER_QUEUE_MAIN), lodLevel_(5), bLodEnabled_(true), numLodLevels_(10), lodReductionRate_(.15f)
     {
         RegisterObject(Model);
@@ -72,10 +73,36 @@
 
         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);
     }
+    
+    /**
+    @brief
+        This function turns a string from XML Port into a usable ID for the rendering system
+        It defaults to the main queue if the group isn't recognized.
+        
+    @param renderQueueGroup
+        This is a string representing the render queue group. Accepted values:
+        'main', 'stencil glow', 'stencil object'
+    */
+    const unsigned int Model::getRenderQueueGroupID(const std::string& renderQueueGroup) const
+    {
+        if(renderQueueGroup.compare("stencil glow")==0)
+        {
+            return RENDER_QUEUE_STENCIL_GLOW;
+        }
+        if(renderQueueGroup.compare("stencil object")==0)
+        {
+            return RENDER_QUEUE_STENCIL_OBJECTS;
+        }
+        return RENDER_QUEUE_MAIN;
+    }
 
     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));
     }
@@ -104,4 +131,5 @@
                 this->attachOgreObject(this->mesh_.getEntity());
                 this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
+                this->mesh_.getEntity()->setRenderQueueGroup(this->renderQueueGroup_);
                 this->mesh_.setVisible(this->isVisible());
 
@@ -110,4 +138,20 @@
             }
         }
+    }
+
+    void Model::changedRenderQueueGroup()
+    {
+        if (GameMode::showsGraphics())
+        {
+            if (this->mesh_.getEntity())
+            {
+                this->mesh_.getEntity()->setRenderQueueGroup(this->renderQueueGroup_);
+            }
+        }
+    }
+
+    void Model::changedMaterial()
+    {
+        this->mesh_.setMaterial(this->materialName_);
     }
 
Index: code/branches/shaders_merge/src/orxonox/graphics/Model.h
===================================================================
--- code/branches/shaders_merge/src/orxonox/graphics/Model.h	(revision 11072)
+++ code/branches/shaders_merge/src/orxonox/graphics/Model.h	(revision 11073)
@@ -27,4 +27,9 @@
  */
 
+/**
+  @file Model.h
+  @brief Definition of Model Class
+*/
+
 #ifndef _Model_H__
 #define _Model_H__
@@ -34,4 +39,5 @@
 #include <string>
 #include "tools/Mesh.h"
+#include "RenderQueueListener.h"
 #include "worldentities/StaticEntity.h"
 
@@ -40,4 +46,11 @@
     class _OrxonoxExport Model : public StaticEntity
     {
+        /**
+        @brief
+            The class Model stores a Mesh and some additional properties, so you can easily render any Model and apply different effects to it.
+            
+            You can assign any Material to any Mesh to completely change the way it looks, to further add versatility you can also assign the Model
+            to a render queue group, to enable proper rendering of fancy effect like glowing edges around objects with alpha blending.
+        */
         public:
             Model(Context* context);
@@ -58,4 +71,9 @@
                 { return this->meshSrc_; }
 
+            inline void setRenderQueueGroup(const std::string& renderQueueGroup)
+                { this->renderQueueGroup_ = getRenderQueueGroupID(renderQueueGroup); this->changedRenderQueueGroup(); }
+            inline const int getRenderQueueGroup() const
+                { return this->renderQueueGroup_; }
+
             inline void setCastShadows(bool bCastShadows)
                 { this->bCastShadows_ = bCastShadows; this->changedShadows(); }
@@ -63,7 +81,25 @@
                 { return this->bCastShadows_; }
 
+            inline void setMaterial(const std::string& materialname)
+                { this->materialName_ = materialname; this->changedMaterial(); }
+            inline const std::string& getMaterial() const
+                { return this->materialName_; }
+
         protected:
+            /**
+            @brief
+                This function turns a string from XML Port into a usable ID for the rendering system
+                It defaults to the main queue if the group isn't recognized.
+                
+            @param renderQueueGroup
+                This is a string representing the render queue group. Accepted values:
+                main, stencil glow, stencil object
+            */
+            const unsigned int getRenderQueueGroupID(const std::string& renderQueueGroup) const;
+
             void registerVariables();
             void changedMesh();
+            void changedRenderQueueGroup();
+            void changedMaterial();
             void changedShadows();
 
@@ -77,14 +113,16 @@
             float getBiggestScale(Vector3 scale3d);
 
-            std::string meshSrc_;
-            Mesh mesh_;
-            bool bCastShadows_;
+            std::string meshSrc_; //!< This string stores the path where the mesh is stored
+            Mesh mesh_; //!< This is the mesh object linked to this Object, it stores the data from the mesh file in a usable format for the Ogre engine
+            bool bCastShadows_; //!< This value determines whether a Model is casting a shadow or not, turn it off to save performance, when not needed
+            unsigned int renderQueueGroup_; //!< This variable stores which render queue group this object is assigned to
+            std::string materialName_; //!< This string stores the name of the material to be applied to the mesh/model
 
             //LoD
-            bool bGlobalEnableLod_;
-            float lodLevel_;
-            bool bLodEnabled_;
-            unsigned int numLodLevels_;
-            float lodReductionRate_;
+            bool bGlobalEnableLod_; //!< Has LoD been turned on in the graphics configuration?
+            float lodLevel_; //!< Standard LoD Level
+            bool bLodEnabled_; //!< Is LoD to be used on this model?
+            unsigned int numLodLevels_; //!< How many LoD does this model feature
+            float lodReductionRate_; //!< How fast should be switched to lower LoDs
 
     };
