[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: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Reto Grieder (physics) |
---|
| 25 | * Co-authors: |
---|
| 26 | * ... |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | /** |
---|
| 31 | @file LensFlare.h |
---|
| 32 | @brief Definition of the LensFlare class. |
---|
| 33 | */ |
---|
| 34 | |
---|
| 35 | #ifndef _LensFlare_H__ |
---|
| 36 | #define _LensFlare_H__ |
---|
| 37 | |
---|
| 38 | #include "OrxonoxPrereqs.h" |
---|
| 39 | |
---|
| 40 | #include "OgreBillboardSet.h" |
---|
| 41 | |
---|
[9448] | 42 | #include "core/GraphicsManager.h" |
---|
[9445] | 43 | #include "util/Math.h" |
---|
| 44 | #include "worldentities/StaticEntity.h" |
---|
| 45 | #include "graphics/Billboard.h" |
---|
| 46 | |
---|
| 47 | namespace orxonox |
---|
| 48 | { |
---|
| 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 | { |
---|
| 63 | public: |
---|
| 64 | LensFlare(BaseObject* creator); |
---|
| 65 | virtual ~LensFlare(); |
---|
[9448] | 66 | |
---|
| 67 | inline void setScale(float scale) |
---|
| 68 | { this->scale_=scale; } |
---|
[9461] | 69 | inline float getScale() const |
---|
[9448] | 70 | { return this->scale_; } |
---|
[9461] | 71 | |
---|
| 72 | /** |
---|
| 73 | @brief |
---|
| 74 | This sets the resolution of the out-of-screen-fade-effect |
---|
| 75 | |
---|
| 76 | the higher the resolution, the smoother the transition, but it will also have a greater impact on the performance |
---|
| 77 | this happens with O(n^2) since it's a two dimensional operation. |
---|
| 78 | @param fadeResolution |
---|
| 79 | how many point samples should be used per axis |
---|
| 80 | |
---|
| 81 | note: this will always be an odd number, so the center point is included in the samples |
---|
| 82 | */ |
---|
| 83 | inline void setFadeResolution(unsigned int fadeResolution) |
---|
| 84 | { this->fadeResolution_=fadeResolution>0?fadeResolution:1; } |
---|
| 85 | /** |
---|
| 86 | @brief |
---|
| 87 | This returns the resolution of the out-of-screen-fade-effect |
---|
| 88 | @return how many point samples are being used per axis |
---|
| 89 | */ |
---|
| 90 | inline unsigned int getFadeResolution() const |
---|
| 91 | { return this->fadeResolution_; } |
---|
| 92 | |
---|
| 93 | /** |
---|
| 94 | @brief |
---|
| 95 | This sets the exponent of the fade-out function |
---|
| 96 | @param exponent |
---|
| 97 | how strong should the fade-out effect be |
---|
| 98 | */ |
---|
| 99 | inline void setFadeExponent(float exponent) |
---|
| 100 | { this->fadeExponent_=exponent; } |
---|
| 101 | /** |
---|
| 102 | @brief |
---|
| 103 | This returns the exponent of the fade-out function |
---|
| 104 | @return the exponent of the fade-out function |
---|
| 105 | */ |
---|
| 106 | inline float getFadeExponent() const |
---|
| 107 | { return this->fadeExponent_; } |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | @brief |
---|
| 111 | Turn the out-of-screen-fade-effect on or off |
---|
| 112 | @param fadeOnViewBorder |
---|
| 113 | true to turn the effect on, false to turn it off |
---|
| 114 | */ |
---|
| 115 | inline void setFadeOnViewBorder(bool fadeOnViewBorder) |
---|
| 116 | { this->fadeOnViewBorder_=fadeOnViewBorder; } |
---|
| 117 | /** |
---|
| 118 | @brief |
---|
| 119 | Determine whether the out-of-screen-fade-effect is on or off |
---|
| 120 | @return |
---|
| 121 | true if the effect is on, false if it is off |
---|
| 122 | */ |
---|
| 123 | inline bool isFadeOnViewBorder() const |
---|
| 124 | { return this->fadeOnViewBorder_; } |
---|
[9445] | 125 | |
---|
| 126 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
| 127 | |
---|
| 128 | virtual void tick(float dt); |
---|
| 129 | |
---|
| 130 | virtual void changedVisibility(); |
---|
| 131 | |
---|
| 132 | private: |
---|
| 133 | void registerVariables(); |
---|
| 134 | |
---|
| 135 | void createBillboards(); |
---|
| 136 | |
---|
[9466] | 137 | void updateBillboardStates(Vector3& viewDirection, float dimension, bool isLightVisible); |
---|
[9448] | 138 | |
---|
[9461] | 139 | void updateBillboardAlphas(float alpha); |
---|
| 140 | |
---|
[9466] | 141 | unsigned int getPointCount(float dimension) const; |
---|
[9461] | 142 | |
---|
| 143 | Billboard* occlusionBillboard_;//!< this is a transparent billboard used solely for the Hardware Occlusion Query |
---|
[9466] | 144 | float cameraDistance_;//!< current distance of the lensflare center from the camera |
---|
[9461] | 145 | float scale_;//!< this factor is used to scale the billboard to the desired size |
---|
| 146 | bool fadeOnViewBorder_;//!< should the effect fade out on the border of the view? |
---|
| 147 | 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 |
---|
| 148 | float fadeExponent_;//!< this determines how fast the flare fades away as it gets obstructed |
---|
[9464] | 149 | //TODO: add XML port for colour manipulation |
---|
| 150 | ColourValue* colour_;//!< this stores the base colour of the light |
---|
[9445] | 151 | }; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | #endif /* _LensFlare_H__ */ |
---|