Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/graphics/LensFlare.h @ 12114

Last change on this file since 12114 was 11083, checked in by muemart, 9 years ago

Fix some clang-tidy warnings.
Also, Serialise.h was doing some C-style casts that ended up being const casts. I moved those const casts as close to the source as possible and changed the loadAndIncrease functions to not do that.

  • Property svn:eol-style set to native
File size: 7.9 KB
RevLine 
[9445]1 /*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
[11075]23 *      David 'davidsa' Salvisberg
[9445]24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30  @file LensFlare.h
31  @brief Definition of the LensFlare class.
32*/
33
34#ifndef _LensFlare_H__
35#define _LensFlare_H__
36
37#include "OrxonoxPrereqs.h"
38
39#include "OgreBillboardSet.h"
40
[9448]41#include "core/GraphicsManager.h"
[9445]42#include "util/Math.h"
[11083]43#include "tools/interfaces/Tickable.h"
[9445]44#include "worldentities/StaticEntity.h"
45#include "graphics/Billboard.h"
46
47namespace orxonox
[9500]48{   
[9445]49      /**
50    @brief
51        This class adds a configurable LensFlare effect by adding multiple billboards for the several components of lens flare.
52        It uses orxonox::Billboard to render this effect, the used images can be changed in lensflare.material
53
54    @author
55        David 'davidsa' Salvisberg
56    */
[9448]57    //TODO: The Hardware Occlusion only works properly for a single Flare on the screen,
58    // if we have multiple strong lights it'll become way more complicated to determine how much of every object is occluded individually
59    // 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
[9461]60    // 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
[9445]61    class _OrxonoxExport LensFlare : public StaticEntity, public Tickable
62    {
[9500]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:
[11078]70                  std::string material_;//!< Which material should the Lens use, current choices include burst, bursthalo, halo1, halo2, halo3
[9500]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
[11078]74                  Lens (const std::string& material, float alpha, float scale, float position)
[9500]75                  {
[11078]76                      this->material_ = material;
77                      this->alpha_ = alpha;
78                      this->scale_ = scale;
79                      this->position_ = position;
[9500]80                  }
81          };
82         
[9445]83        public:
[11073]84            LensFlare(Context* context);
[9445]85            virtual ~LensFlare();
[9448]86           
87            inline void setScale(float scale)
[11078]88                { this->scale_ = scale; }
[9461]89            inline float getScale() const
[9448]90                { return this->scale_; }
[9461]91               
92            /**
93            @brief
[9500]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)
[11078]99                { this->colour_ = colour; }
[9500]100            /**
101            @brief
102                This returns the current base colour of the billboards
103            @return a Vector3 containing r,g,b values
104            */
105            inline const ColourValue& getColour() const
[11078]106                { return this->colour_; }
[9500]107               
108            /**
109            @brief
[9461]110                This sets the resolution of the out-of-screen-fade-effect
111               
112                the higher the resolution, the smoother the transition, but it will also have a greater impact on the performance
113                this happens with O(n^2) since it's a two dimensional operation.
114            @param fadeResolution
115                how many point samples should be used per axis
116               
117                note: this will always be an odd number, so the center point is included in the samples
118            */
119            inline void setFadeResolution(unsigned int fadeResolution)
[11078]120                { this->fadeResolution_ = fadeResolution > 0 ? fadeResolution : 1; }
[9461]121            /**
122            @brief
123                This returns the resolution of the out-of-screen-fade-effect
124            @return how many point samples are being used per axis
125            */
126            inline unsigned int getFadeResolution() const
127                { return this->fadeResolution_; }
128               
129            /**
130            @brief
131                This sets the exponent of the fade-out function
132            @param exponent
133                how strong should the fade-out effect be
134            */
135            inline void setFadeExponent(float exponent)
[11078]136                { this->fadeExponent_ = exponent; }
[9461]137            /**
138            @brief
139                This returns the exponent of the fade-out function
140            @return the exponent of the fade-out function
141            */
142            inline float getFadeExponent() const
143                { return this->fadeExponent_; }
144               
145            /**
146            @brief
147               Turn the out-of-screen-fade-effect on or off
148            @param fadeOnViewBorder
149                true to turn the effect on, false to turn it off
150            */
151            inline void setFadeOnViewBorder(bool fadeOnViewBorder)
[11078]152                { this->fadeOnViewBorder_ = fadeOnViewBorder; }
[9461]153            /**
154            @brief
155               Determine whether the out-of-screen-fade-effect is on or off
156            @return
157                true if the effect is on, false if it is off
158            */
159            inline bool isFadeOnViewBorder() const
160                { return this->fadeOnViewBorder_; }
[9445]161
[11075]162            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
[9445]163
[11075]164            virtual void tick(float dt) override;
[9445]165
[11075]166            virtual void changedVisibility() override;
[9445]167
168        private:
169            void registerVariables();
170           
171            void createBillboards();
172           
[11078]173            void updateBillboardStates(const Vector3& viewDirection, float dimension, bool isLightVisible);
[9448]174           
[9461]175            void updateBillboardAlphas(float alpha);
176           
[9466]177            unsigned int getPointCount(float dimension) const;
[9461]178           
[11078]179            std::vector<Lens> lensConfiguration_;//!< this stores the lensConfiguration
[9461]180            Billboard* occlusionBillboard_;//!< this is a transparent billboard used solely for the Hardware Occlusion Query
[11079]181            std::vector<Billboard*> billboards_; //!< The visible billboards
182
[9461]183            float scale_;//!< this factor is used to scale the billboard to the desired size
184            bool fadeOnViewBorder_;//!< should the effect fade out on the border of the view?
185            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
186            float fadeExponent_;//!< this determines how fast the flare fades away as it gets obstructed
[11078]187            ColourValue colour_;//!< this stores the base colour of the light
[9445]188    };
189}
190
[11078]191#endif /* _LensFlare_H__ */
Note: See TracBrowser for help on using the repository browser.