Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/shaders_merge/src/orxonox/graphics/LensFlare.h @ 11079

Last change on this file since 11079 was 11079, checked in by landauf, 8 years ago

bugfix: the attached objects are stored in a set, so there's no guarantee about the order of the elements. store the billboards of the lens flare in an ordered vector to ensure that the billboards are updated with the correct parameters.

  • Property svn:eol-style set to native
File size: 7.8 KB
Line 
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:
23 *      David 'davidsa' Salvisberg
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
41#include "core/GraphicsManager.h"
42#include "util/Math.h"
43#include "worldentities/StaticEntity.h"
44#include "graphics/Billboard.h"
45
46namespace orxonox
47{   
48      /**
49    @brief
50        This class adds a configurable LensFlare effect by adding multiple billboards for the several components of lens flare.
51        It uses orxonox::Billboard to render this effect, the used images can be changed in lensflare.material
52
53    @author
54        David 'davidsa' Salvisberg
55    */
56    //TODO: The Hardware Occlusion only works properly for a single Flare on the screen,
57    // if we have multiple strong lights it'll become way more complicated to determine how much of every object is occluded individually
58    // 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
59    // 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
60    class _OrxonoxExport LensFlare : public StaticEntity, public Tickable
61    {
62          /**
63          @brief
64              This is a nested Class used to easily set properties of the different sublenses of a LensFlare effect
65          */
66          class Lens
67          {
68              public:
69                  std::string material_;//!< Which material should the Lens use, current choices include burst, bursthalo, halo1, halo2, halo3
70                  float alpha_;//!< Which base alpha value should the Lens use
71                  float scale_;//!< Which base scale should the Lens Flare have
72                  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
73                  Lens (const std::string& material, float alpha, float scale, float position)
74                  {
75                      this->material_ = material;
76                      this->alpha_ = alpha;
77                      this->scale_ = scale;
78                      this->position_ = position;
79                  }
80          };
81         
82        public:
83            LensFlare(Context* context);
84            virtual ~LensFlare();
85           
86            inline void setScale(float scale)
87                { this->scale_ = scale; }
88            inline float getScale() const
89                { return this->scale_; }
90               
91            /**
92            @brief
93                This sets the base colour of the billboards
94            @param colour
95                Vector3 containing r,g,b values
96            */
97            inline void setColour(const ColourValue& colour)
98                { this->colour_ = colour; }
99            /**
100            @brief
101                This returns the current base colour of the billboards
102            @return a Vector3 containing r,g,b values
103            */
104            inline const ColourValue& getColour() const
105                { return this->colour_; }
106               
107            /**
108            @brief
109                This sets the resolution of the out-of-screen-fade-effect
110               
111                the higher the resolution, the smoother the transition, but it will also have a greater impact on the performance
112                this happens with O(n^2) since it's a two dimensional operation.
113            @param fadeResolution
114                how many point samples should be used per axis
115               
116                note: this will always be an odd number, so the center point is included in the samples
117            */
118            inline void setFadeResolution(unsigned int fadeResolution)
119                { this->fadeResolution_ = fadeResolution > 0 ? fadeResolution : 1; }
120            /**
121            @brief
122                This returns the resolution of the out-of-screen-fade-effect
123            @return how many point samples are being used per axis
124            */
125            inline unsigned int getFadeResolution() const
126                { return this->fadeResolution_; }
127               
128            /**
129            @brief
130                This sets the exponent of the fade-out function
131            @param exponent
132                how strong should the fade-out effect be
133            */
134            inline void setFadeExponent(float exponent)
135                { this->fadeExponent_ = exponent; }
136            /**
137            @brief
138                This returns the exponent of the fade-out function
139            @return the exponent of the fade-out function
140            */
141            inline float getFadeExponent() const
142                { return this->fadeExponent_; }
143               
144            /**
145            @brief
146               Turn the out-of-screen-fade-effect on or off
147            @param fadeOnViewBorder
148                true to turn the effect on, false to turn it off
149            */
150            inline void setFadeOnViewBorder(bool fadeOnViewBorder)
151                { this->fadeOnViewBorder_ = fadeOnViewBorder; }
152            /**
153            @brief
154               Determine whether the out-of-screen-fade-effect is on or off
155            @return
156                true if the effect is on, false if it is off
157            */
158            inline bool isFadeOnViewBorder() const
159                { return this->fadeOnViewBorder_; }
160
161            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
162
163            virtual void tick(float dt) override;
164
165            virtual void changedVisibility() override;
166
167        private:
168            void registerVariables();
169           
170            void createBillboards();
171           
172            void updateBillboardStates(const Vector3& viewDirection, float dimension, bool isLightVisible);
173           
174            void updateBillboardAlphas(float alpha);
175           
176            unsigned int getPointCount(float dimension) const;
177           
178            std::vector<Lens> lensConfiguration_;//!< this stores the lensConfiguration
179            Billboard* occlusionBillboard_;//!< this is a transparent billboard used solely for the Hardware Occlusion Query
180            std::vector<Billboard*> billboards_; //!< The visible billboards
181
182            float scale_;//!< this factor is used to scale the billboard to the desired size
183            bool fadeOnViewBorder_;//!< should the effect fade out on the border of the view?
184            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
185            float fadeExponent_;//!< this determines how fast the flare fades away as it gets obstructed
186            ColourValue colour_;//!< this stores the base colour of the light
187    };
188}
189
190#endif /* _LensFlare_H__ */
Note: See TracBrowser for help on using the repository browser.