Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2011, 12:28:31 AM (14 years ago)
Author:
marwegma
Message:

Godrays: Safety commit. 90017 N8

Location:
code/branches/environment2
Files:
2 added
6 edited
2 moved

Legend:

Unmodified
Added
Removed
  • code/branches/environment2/src/libraries/tools/Shader.h

    r8079 r8557  
    8989            inline Ogre::SceneManager* getSceneManager() const
    9090                { return this->scenemanager_; }
    91 
     91           
     92            /// Returns the compositor instance. Normally used for manually modifiying compositor parameters, when mt-type conversatio.
     93            inline Ogre::CompositorInstance* getMutableCompositorInstance()
     94                { return this->compositorInstance_; }
     95       
    9296            virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera);
    9397
     98            void setParameter(size_t technique, size_t pass, const std::string& parameter, int value);
    9499            void setParameter(size_t technique, size_t pass, const std::string& parameter, float value);
    95             void setParameter(size_t technique, size_t pass, const std::string& parameter, int value);
    96100
    97101            virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr& materialPtr);
  • code/branches/environment2/src/orxonox/OrxonoxPrereqs.h

    r8435 r8557  
    111111    class FadingBillboard;
    112112    class GlobalShader;
    113     class GlobalGodrayShader;
     113    class GodrayShader;
    114114    class Light;
    115115    class Model;
  • code/branches/environment2/src/orxonox/graphics/CMakeLists.txt

    r8435 r8557  
    44  FadingBillboard.cc
    55  GlobalShader.cc
    6   GlobalGodrayShader.cc
     6  GodrayShader.cc
    77  MeshLodInformation.cc
    88  Model.cc
     
    1010  ParticleEmitter.cc
    1111  ParticleSpawner.cc
     12  WorldEntityShader.cc
    1213COMPILATION_BEGIN GraphicsCompilation.cc
    1314  Backlight.cc
  • code/branches/environment2/src/orxonox/graphics/GlobalShader.h

    r8079 r8557  
    5050            inline const Shader& getShader() const
    5151                { return this->shader_; }
     52       
     53            inline Shader& getMutableShader()
     54                { return this->shader_; }
    5255
    5356        private:
  • code/branches/environment2/src/orxonox/graphics/GodrayShader.cc

    r8497 r8557  
    3030 @file
    3131 
    32  @brief Implementation of the GlobalGodrayShader class.
     32 @brief Implementation of the GodrayShader class.
    3333 */
    3434
    35 #include "GlobalGodrayShader.h"
     35
     36#include "GodrayShader.h"
    3637
    3738#include "util/Exception.h"
     
    4142namespace orxonox
    4243{
    43     CreateFactory(GlobalGodrayShader);
     44    CreateFactory(GodrayShader);
    4445   
    45     GlobalGodrayShader::GlobalGodrayShader(BaseObject* creator) : BaseObject(creator), globalShader_(creator)
     46    GodrayShader::GodrayShader(BaseObject* creator) : BaseObject(creator), globalShader_(creator)
    4647    {
    47         RegisterObject(GlobalGodrayShader);
     48        RegisterObject(GodrayShader);
    4849       
    49         if (!this->getScene())
    50             ThrowException(AbortLoading, "Can't create GlobalGodrayShader, no scene given.");
    51         //        if (!this->getScene()->getSceneManager())
    52         //            ThrowException(AbortLoading, "Can't create GlobalGodrayShader, no scene manager given.");
    53        
     50        // Default parameters are initialized
     51        this->sunPosition_ = Vector3::Zero;
     52        this->sunColor_ = ColourValue::White;
    5453        this->skyColor_ = ColourValue::Black;
    55         this->exposure_ = 1.0f;
     54        this->exposure_ = 1.0f; 
    5655        this->decay_ = 0.1f;
    5756        this->density_ = 0.7f;
    5857       
    59         //// Init ////
     58        // Godrays.compositor is getting initialized
     59        this->globalShader_.getMutableShader().setCompositorName("Godrays");
     60        this->compositor_ = this->globalShader_.getMutableShader().getMutableCompositorInstance();
    6061    }
    6162   
    62     GlobalGodrayShader::~GlobalGodrayShader()
     63    GodrayShader::~GodrayShader()
    6364    {
    6465        this->setVisible(false);
    6566    }
    6667   
    67     void GlobalGodrayShader::tick(float dt)
     68    void GodrayShader::tick(float dt)
    6869    {
    69         // To-Do
     70        if(this->isVisible())
     71        {
     72           
     73            //Reset sunPosition in the compositor instance every tick
     74            this->compositor_->getTechnique()->getTargetPass(2)
     75        }
    7076    }
    7177   
    72     void GlobalGodrayShader::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     78    void GodrayShader::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7379    {
    74         SUPER(GlobalGodrayShader, XMLPort, xmlelement, mode);
     80        SUPER(GodrayShader, XMLPort, xmlelement, mode);
    7581       
    76         XMLPortParamTemplate(GlobalGodrayShader, "sunPosition", setSunPosition, getSunPosition, xmlelement, mode, const Vector3&);
    77         XMLPortParamTemplate(GlobalGodrayShader, "skyColor", setSkyColor, getSkyColor, xmlelement, mode, const ColourValue&);
    78         XMLPortParamVariable(GlobalGodrayShader, "exposure", exposure_, xmlelement, mode);
    79         XMLPortParamVariable(GlobalGodrayShader, "decay", decay_, xmlelement, mode);
    80         XMLPortParamVariable(GlobalGodrayShader, "density", density_, xmlelement, mode);
     82        XMLPortParamTemplate(GodrayShader, "sunColor", setSunColor, getSunColor, xmlelement, mode, const ColourValue&);
     83        XMLPortParamTemplate(GodrayShader, "skyColor", setSkyColor, getSkyColor, xmlelement, mode, const ColourValue&);
     84        XMLPortParamVariable(GodrayShader, "exposure", exposure_, xmlelement, mode);
     85        XMLPortParamVariable(GodrayShader, "decay", decay_, xmlelement, mode);
     86        XMLPortParamVariable(GodrayShader, "density", density_, xmlelement, mode);
    8187    }
    8288   
    83     void GlobalGodrayShader::setSunPosition(const Vector3& position)
     89    void GodrayShader::setWorldEntity(WorldEntity* worldEntity)
     90    {
     91        this->worldEntity_ = worldEntity;
     92        this->setSunPosition(worldEntity->getWorldPosition());
     93    }
     94   
     95    void GodrayShader::setSunPosition(const Vector3& position)
    8496    {
    8597        this->sunPosition_ = position;
    8698    }
    87     void GlobalGodrayShader::setSkyColor(const ColourValue& color)
     99    void GodrayShader::setSunColor(const ColourValue& color)
    88100    {
    89101        this->skyColor_ = color;
    90102    }
    91     const Vector3& GlobalGodrayShader::getSunPosition() const
     103    void GodrayShader::setSkyColor(const ColourValue& color)
     104    {
     105        this->skyColor_ = color;
     106    }
     107    const Vector3& GodrayShader::getSunPosition() const
    92108    {
    93109        return this->sunPosition_;
    94110    }
    95     const ColourValue& GlobalGodrayShader::getSkyColor() const
     111    const ColourValue& GodrayShader::getSunColor() const
     112    {
     113        return this->sunColor_;
     114    }
     115    const ColourValue& GodrayShader::getSkyColor() const
    96116    {
    97117        return this->skyColor_;
    98118    }
    99119   
    100     void GlobalGodrayShader::changedVisibility()
     120    void GodrayShader::changedVisibility()
    101121    {
    102         SUPER(GlobalGodrayShader, changedVisibility);
     122        SUPER(GodrayShader, changedVisibility);
    103123       
    104124        this->globalShader_.setVisible(this->isVisible());
  • code/branches/environment2/src/orxonox/graphics/GodrayShader.h

    r8497 r8557  
    3131 @file
    3232 
    33  @brief Header of the GlobalGodrayShader class.
     33 @brief Header of the GodrayShader class.
    3434*/
    3535
    3636
    37 #ifndef _GlobalGodrayShader_H__
    38 #define _GlobalGodrayShader_H__
     37#ifndef _GodrayShader_H__
     38#define _GodrayShader_H__
    3939
    4040#include "OrxonoxPrereqs.h"
     41
     42#include <OgreCompositorInstance.h>
    4143
    4244#include "tools/interfaces/Tickable.h"
    4345#include "core/BaseObject.h"
    4446#include "util/Math.h"
     47#include "WorldEntity.h"
    4548#include "GlobalShader.h"
    4649
     
    5255     
    5356    */
    54     class _OrxonoxExport GlobalGodrayShader : public BaseObject, public Tickable
     57    class _OrxonoxExport GodrayShader : public BaseObject, public Tickable
    5558    {
    5659        public:
    57             GlobalGodrayShader(BaseObject* creator);
    58             virtual ~GlobalGodrayShader();
     60            GodrayShader(BaseObject* creator);
     61            virtual ~GodrayShader();
    5962           
    6063            virtual void tick(float dt);
     64       
     65            virtual void updateParameters();
    6166           
    6267            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    6368       
    6469            virtual void changedVisibility();
     70       
     71            void setWorldEntity(WorldEntity* worldEntity);
    6572           
    6673            inline const GlobalShader& getGlobalShader() const
     
    6875       
    6976            void setSunPosition(const Vector3& position);
     77            void setSunColor(const ColourValue& color);
    7078            void setSkyColor(const ColourValue& color);
    7179            const Vector3& getSunPosition() const;
     80            const ColourValue& getSunColor() const;
    7281            const ColourValue& getSkyColor() const;
    7382       
    7483        private:
    75            
     84       
     85            WorldEntity* worldEntity_;
    7686            GlobalShader globalShader_;
    77            
     87            Ogre::CompositorInstance* compositor_;
    7888            Vector3 sunPosition_;
     89            ColourValue sunColor_;
    7990            ColourValue skyColor_;
    8091            float exposure_;
     
    8495}
    8596
    86 #endif /* _GlobalGodrayShader_H__ */
     97#endif /* _GodrayShader_H__ */
  • code/branches/environment2/src/orxonox/worldentities/WorldEntity.cc

    r7937 r8557  
    177177        // Attached collision shapes
    178178        XMLPortObject(WorldEntity, CollisionShape, "collisionShapes", attachCollisionShape, getAttachedCollisionShape, xmlelement, mode);
     179        // Attach WorldEntityShaders that depend on WorldEntity data (e.g. position). -- TODO -- Extend to WorldEntityShader.
     180        XMLPortObject(WorldEntity, GodrayShader, "shaders", attachShader, getAttachedObject, xmlelement, mode);
    179181    }
    180182
     
    510512        return 0;
    511513    }
     514   
     515    void WorldEntity::attachShader(GodrayShader* object)
     516    {
     517        object->setWorldEntity(object);
     518       
     519        this->shaders_.insert(object);
     520    }
     521    void WorldEntity::detachShader(GodrayShader* object)
     522    {
     523        std::set<WorldEntity*>::iterator it = this->children_.find(object);
     524        this->shaders_.erase(it);
     525       
     526    }
     527    GodrayShader* WorldEntity::getAttachedShader(unsigned int index)
     528    {
     529        unsigned int i = 0;
     530        for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it)
     531        {
     532            if (i == index)
     533                return (*it);
     534            ++i;
     535        }
     536        return 0;
     537    }
    512538
    513539    //! Attaches an Ogre::SceneNode to this WorldEntity.
  • code/branches/environment2/src/orxonox/worldentities/WorldEntity.h

    r7910 r8557  
    199199            void attachToNode(Ogre::SceneNode* node);
    200200            void detachFromNode(Ogre::SceneNode* node);
     201           
     202            void attachShader(GodrayShader* object);
     203            void detachShader(GodrayShader* object);
     204            GodrayShader* getAttachedShader(unsigned int index);
     205            inline const std::set<WorldEntity*>& getAttachedShaders() const
     206            { return this->shaders_; }
    201207
    202208            inline void setDeleteWithParent(bool value)
     
    234240            unsigned int parentID_;
    235241            std::set<WorldEntity*> children_;
     242            std::set<WorldEntity*> shaders_;
    236243            bool bDeleteWithParent_;
    237244
Note: See TracChangeset for help on using the changeset viewer.