Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 10, 2012, 3:26:49 PM (12 years ago)
Author:
davidsa
Message:

Added nested Class Lens to LensFlare, to simplify lens flare configuration and some of the methods. Might also be used to define presets in the future.

Location:
code/branches/shaders/src/orxonox/graphics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/shaders/src/orxonox/graphics/LensFlare.cc

    r9491 r9500  
    5151        RegisterObject(LensFlare);
    5252       
     53        this->lensConfiguration_=new std::vector<LensFlare::Lens*>();
     54        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/burst"),1.0f,1.0f,1.0f)); //main burst
     55        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/bursthalo"),0.7f,0.9f,1.0f)); //halo around main burst
     56        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo1"),0.4f,0.2f,0.8f)); //all the different distanced lenses
     57        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo2"),0.7f,0.3f,0.7f));
     58        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo3"),0.3f,0.4f,0.6f));
     59        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo3"),0.1f,0.8f,0.4f));
     60        this->lensConfiguration_->push_back(new LensFlare::Lens(new std::string("lensflare/halo1"),0.15f,0.5f,0.35f));
     61       
    5362        this->createBillboards();
    5463       
     
    6776        XMLPortParam(LensFlare, "fadeResolution", setFadeResolution, getFadeResolution, xmlelement, mode).defaultValues(7);
    6877        XMLPortParam(LensFlare, "fadeExponent", setFadeExponent, getFadeExponent, xmlelement, mode).defaultValues(2.0f);
     78        XMLPortParam(LensFlare, "colour", setColour, getColour, xmlelement, mode);
    6979    }
    7080   
     
    8292    void LensFlare::createBillboards()
    8393    {
    84         //TODO: add more billboards, possibly do some cleaning up, by using a loop
    8594        this->occlusionBillboard_ = new Billboard(this);
    8695        this->occlusionBillboard_->setMaterial("lensflare/hoq");
     
    9099        this->attach(this->occlusionBillboard_);
    91100       
    92         Billboard* burst = new Billboard(this);
    93         burst->setMaterial("lensflare/burst");
    94         burst->disableFrustumCulling();
    95         burst->setVisible(true);
    96         this->attach(burst);
    97        
    98         Billboard* bursthalo = new Billboard(this);
    99         bursthalo->setMaterial("lensflare/bursthalo");
    100         bursthalo->disableFrustumCulling();
    101         bursthalo->setVisible(true);
    102         this->attach(bursthalo);
    103        
    104         bursthalo = new Billboard(this);
    105         bursthalo->setMaterial("lensflare/halo1");
    106         bursthalo->disableFrustumCulling();
    107         bursthalo->setVisible(true);
    108         this->attach(bursthalo);
    109        
    110         bursthalo = new Billboard(this);
    111         bursthalo->setMaterial("lensflare/halo2");
    112         bursthalo->disableFrustumCulling();
    113         bursthalo->setVisible(true);
    114         this->attach(bursthalo);
    115        
    116         bursthalo = new Billboard(this);
    117         bursthalo->setMaterial("lensflare/halo3");
    118         bursthalo->disableFrustumCulling();
    119         bursthalo->setVisible(true);
    120         this->attach(bursthalo);
     101        for(std::vector<LensFlare::Lens*>::iterator it = lensConfiguration_->begin(); it != lensConfiguration_->end(); ++it) {
     102            Billboard* lensPart=new Billboard(this);
     103            lensPart->setMaterial(*(*it)->material_);
     104            lensPart->disableFrustumCulling();
     105            lensPart->setVisible(true);
     106            this->attach(lensPart);
     107        }
    121108    }
    122109
     
    133120    void LensFlare::updateBillboardStates(Vector3& viewDirection, float dimension, bool lightIsVisible)
    134121    {
    135         //TODO: develop a more sane method for determining positions and scale factors of the flare components
    136         //A good solution would probably be to introduce a data structure which stores a lens flare configuration
    137         int i=0;
    138         float step=0.0f;
    139         for(std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin(); it != this->getAttachedObjects().end(); it++) {
     122        this->occlusionBillboard_->setDefaultDimensions(dimension*0.5f,dimension*0.5f);
     123        this->occlusionBillboard_->setVisible(lightIsVisible);
     124        std::set<WorldEntity*>::const_iterator it = this->getAttachedObjects().begin();
     125        it++;
     126        for(int i=0; it != this->getAttachedObjects().end(); it++) {
    140127            Billboard* billboard=static_cast<Billboard*>(*it);
    141             billboard->setPosition(-viewDirection*step);
     128            LensFlare::Lens* lens=lensConfiguration_->at(i);
     129            billboard->setPosition(-viewDirection*(1.0f-lens->position_));
    142130            billboard->setVisible(lightIsVisible);
    143             billboard->setDefaultDimensions((i==0?0.5f:1.0f)*(i>2?0.25f:1.0f)*dimension*std::pow((1.0f-step),-1.0f),(i==0?0.5f:1.0f)*(i>2?0.25f:1.0f)*dimension*std::pow((1.0f-step),-1.0f));
    144             step=0.25f*(i>2?(i-2):0);
     131            billboard->setDefaultDimensions(dimension*lens->scale_,dimension*lens->scale_);
    145132            i++;
    146133        }
     
    159146        it++;
    160147        for(int i=0;it!=this->getAttachedObjects().end(); it++) {
    161             if(i==2)
    162             {
    163                 this->colour_->a*=0.33f;
    164             }
     148            ColourValue* cur=new ColourValue(0,0,0,0);
     149            (*cur)+= *(this->colour_);
     150            cur->a*=lensConfiguration_->at(i)->alpha_;
    165151            Billboard* billboard=static_cast<Billboard*>(*it);
    166             billboard->setColour(*(this->colour_));
     152            billboard->setColour(*cur);
    167153            i++;
    168154        }
  • code/branches/shaders/src/orxonox/graphics/LensFlare.h

    r9466 r9500  
    4646
    4747namespace orxonox
    48 {
     48{   
    4949      /**
    5050    @brief
     
    6161    class _OrxonoxExport LensFlare : public StaticEntity, public Tickable
    6262    {
     63          /**
     64          @brief
     65              This is a nested Class used to easily set properties of the different sublenses of a LensFlare effect
     66          */
     67          class Lens
     68          {
     69              public:
     70                  std::string* material_;//!< Which material should the Lens use, current choices include burst, bursthalo, halo1, halo2, halo3
     71                  float alpha_;//!< Which base alpha value should the Lens use
     72                  float scale_;//!< Which base scale should the Lens Flare have
     73                  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
     74                  Lens(std::string* material, float alpha, float scale, float position)
     75                  {
     76                      this->material_=material;
     77                      this->alpha_=alpha;
     78                      this->scale_=scale;
     79                      this->position_=position;
     80                  }
     81          };
     82         
    6383        public:
    6484            LensFlare(BaseObject* creator);
     
    6989            inline float getScale() const
    7090                { return this->scale_; }
     91               
     92            /**
     93            @brief
     94                This sets the base colour of the billboards
     95            @param colour
     96                Vector3 containing r,g,b values
     97            */
     98            inline void setColour(const ColourValue& colour)
     99            {
     100                this->colour_->r=colour.r;
     101                this->colour_->g=colour.g;
     102                this->colour_->b=colour.b;
     103            }
     104            /**
     105            @brief
     106                This returns the current base colour of the billboards
     107            @return a Vector3 containing r,g,b values
     108            */
     109            inline const ColourValue& getColour() const
     110                { return *(new ColourValue(this->colour_->r,this->colour_->g,this->colour_->b)); }
    71111               
    72112            /**
     
    141181            unsigned int getPointCount(float dimension) const;
    142182           
     183            std::vector<Lens*>* lensConfiguration_;//!< this stores the lensConfiguration
    143184            Billboard* occlusionBillboard_;//!< this is a transparent billboard used solely for the Hardware Occlusion Query
    144185            float cameraDistance_;//!< current distance of the lensflare center from the camera
     
    147188            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
    148189            float fadeExponent_;//!< this determines how fast the flare fades away as it gets obstructed
    149             //TODO: add XML port for colour manipulation
    150190            ColourValue* colour_;//!< this stores the base colour of the light
    151191    };
Note: See TracChangeset for help on using the changeset viewer.