Stellarium 0.14.0
StelSkyDrawer.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2007 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELSKYDRAWER_HPP_
21 #define _STELSKYDRAWER_HPP_
22 
23 #include "RefractionExtinction.hpp"
24 #include "StelTextureTypes.hpp"
25 #include "StelProjectorType.hpp"
26 #include "VecMath.hpp"
27 
28 #include <QObject>
29 
30 class StelToneReproducer;
31 class StelCore;
32 class StelPainter;
33 
36 struct RCMag
37 {
38  float radius;
39  float luminance;
40 };
41 
45 class StelSkyDrawer : public QObject
46 {
47  Q_OBJECT
48 public:
49 
51  StelSkyDrawer(StelCore* core);
54 
56  void init();
57 
60  void update(double deltaTime);
61 
65 
67  void postDrawPointSource(StelPainter* sPainter);
68 
76  bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const RCMag &rcMag, unsigned int bV, bool checkInScreen=false)
77  {
78  return drawPointSource(sPainter, v, rcMag, colorTable[bV], checkInScreen);
79  }
80 
81  bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const RCMag &rcMag, const Vec3f& bcolor, bool checkInScreen=false);
82 
89  void postDrawSky3dModel(StelPainter* p, const Vec3f& v, float illuminatedArea, float mag, const Vec3f& color = Vec3f(1.f,1.f,1.f));
90 
95  bool computeRCMag(float mag, RCMag*) const;
96 
102  void reportLuminanceInFov(float lum, bool fastAdaptation=false);
103 
105  void preDraw();
106 
110  static float surfacebrightnessToLuminance(float sb);
114  static float luminanceToSurfacebrightness(float lum);
115 
117  static inline float indexToBV(unsigned char bV)
118  {
119  return (float)bV*(4.f/127.f)-0.5f;
120  }
121 
123  static inline const Vec3f& indexToColor(unsigned char bV)
124  {
125  return colorTable[bV];
126  }
127 
128 public slots:
130  void setRelativeStarScale(double b=1.0) {starRelativeScale=b;}
132  float getRelativeStarScale() const {return starRelativeScale;}
133 
135  void setAbsoluteStarScale(double b=1.0) {starAbsoluteScaleF=b;}
137  float getAbsoluteStarScale() const {return starAbsoluteScaleF;}
138 
140  void setTwinkleAmount(double b) {twinkleAmount=b;}
142  float getTwinkleAmount() const {return twinkleAmount;}
143 
145  void setFlagTwinkle(bool b) {flagStarTwinkle=b;}
147  bool getFlagTwinkle() const {return flagStarTwinkle;}
148 
152  void setBortleScaleIndex(int index);
154  int getBortleScaleIndex() const {return bortleScaleIndex;}
155 
159  float getLimitMagnitude() const {return limitMagnitude;}
160 
164  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
165  void setFlagStarMagnitudeLimit(bool b) {flagStarMagnitudeLimit = b;}
169  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
170  void setFlagNebulaMagnitudeLimit(bool b) {flagNebulaMagnitudeLimit = b;}
172  bool getFlagStarMagnitudeLimit() const {return flagStarMagnitudeLimit;}
174  bool getFlagNebulaMagnitudeLimit() const {return flagNebulaMagnitudeLimit;}
175 
177  float getCustomStarMagnitudeLimit() const {return customStarMagLimit;}
180  void setCustomStarMagnitudeLimit(double limit) {customStarMagLimit=limit;}
182  float getCustomNebulaMagnitudeLimit() const {return customNebulaMagLimit;}
185  void setCustomNebulaMagnitudeLimit(double limit) {customNebulaMagLimit=limit;}
186 
190  float getLimitLuminance() const {return limitLuminance;}
191 
193  void setFlagLuminanceAdaptation(bool b) {flagLuminanceAdaptation=b;}
195  bool getFlagLuminanceAdaptation() const {return flagLuminanceAdaptation;}
196 
199  void setFlagHasAtmosphere(bool b) {flagHasAtmosphere=b;}
201  bool getFlagHasAtmosphere() const {return flagHasAtmosphere;}
202 
204  void setExtinctionCoefficient(double extCoeff) {extinction.setExtinctionCoefficient(extCoeff);}
206  double getExtinctionCoefficient() const {return extinction.getExtinctionCoefficient();}
208  void setAtmosphereTemperature(double celsius) {refraction.setTemperature(celsius);}
210  double getAtmosphereTemperature() const {return refraction.getTemperature();}
212  void setAtmospherePressure(double mbar) {refraction.setPressure(mbar);}
214  double getAtmospherePressure() const {return refraction.getPressure();}
215 
217  const Extinction& getExtinction() const {return extinction;}
219  const Refraction& getRefraction() const {return refraction;}
220 
222  float getBig3dModelHaloRadius() const {return big3dModelHaloRadius;}
224  void setBig3dModelHaloRadius(float r) {big3dModelHaloRadius=r;}
225 
226 private:
227  // Debug
228  float reverseComputeRCMag(float rmag) const;
229 
231  float computeLimitMagnitude() const;
232 
234  float computeLimitLuminance() const;
235 
237  float getMaxAdaptFov(void) const {return maxAdaptFov;}
242  void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
243 
245  float getMinAdaptFov(void) const {return minAdaptFov;}
250  void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
251 
253  void setInputScale(float in) {inScale = in;}
255  float getInputScale() const {return inScale;}
256 
260  inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
261 
265  float pointSourceLuminanceToMag(float lum);
266 
270  float pointSourceMagToLnLuminance(float mag) const;
271 
274  float findWorldLumForMag(float mag, float targetRadius);
275 
276  StelCore* core;
277  StelToneReproducer* eye;
278 
279  Extinction extinction;
280  Refraction refraction;
281 
282  float maxAdaptFov, minAdaptFov, lnfovFactor;
283  bool flagStarTwinkle;
284  float twinkleAmount;
285 
288  bool flagHasAtmosphere;
289 
292  bool flagStarMagnitudeLimit;
295  bool flagNebulaMagnitudeLimit;
296 
297  float starRelativeScale;
298  float starAbsoluteScaleF;
299 
300  float starLinearScale; // optimization variable
301 
303  float limitMagnitude;
304 
306  float limitLuminance;
307 
312  float customStarMagLimit;
318  float customNebulaMagLimit;
319 
321  StelTextureSP texHalo;
322 
324  void initColorTableFromConfigFile(class QSettings* conf);
325 
327  static Vec3f colorTable[128];
328 
330  int bortleScaleIndex;
331 
333  float inScale;
334 
335  // Variables used for GL optimization when displaying point sources
338  struct StarVertex {
339  Vec2f pos;
340  unsigned char color[4];
341  };
342 
344  StarVertex* vertexArray;
345 
347  unsigned char* textureCoordArray;
348 
349  class QOpenGLShaderProgram* starShaderProgram;
350  struct StarShaderVars {
351  int projectionMatrix;
352  int texCoord;
353  int pos;
354  int color;
355  int texture;
356  };
357  StarShaderVars starShaderVars;
358 
360  unsigned int nbPointSources;
362  unsigned int maxPointSources;
363 
365  float maxLum;
367  float oldLum;
368 
370  StelTextureSP texBigHalo;
371  StelTextureSP texSunHalo;
372 
373  bool flagLuminanceAdaptation;
374 
375  float big3dModelHaloRadius;
376 };
377 
378 #endif // _STELSKYDRAWER_HPP_
void setExtinctionCoefficient(float k)
Set visual extinction coefficient (mag/airmass), influences extinction computation.
static const Vec3f & indexToColor(unsigned char bV)
Convert quantized B-V index to RGB colors.
StelSkyDrawer(StelCore *core)
Constructor.
void preDraw()
To be called before the drawing stage starts.
bool getFlagTwinkle() const
Get flag for source twinkling.
bool getFlagNebulaMagnitudeLimit() const
Provide a set of methods used to draw sky objects taking into account eyes adaptation, zoom level, instrument model and artificially set magnitude limits.
void setFlagHasAtmosphere(bool b)
Informing the drawer whether atmosphere is displayed.
void setExtinctionCoefficient(double extCoeff)
Set extinction coefficient, mag/airmass (for extinction).
void setCustomNebulaMagnitudeLimit(double limit)
Sets a lower limit for nebula magnitudes (anything fainter is ignored).
void update(double deltaTime)
Update with respect to the time and StelProjector/StelToneReproducer state.
void setBig3dModelHaloRadius(float r)
Set the radius of the big halo texture used when a 3d model is very bright.
static float surfacebrightnessToLuminance(float sb)
Compute the luminance for an extended source with the given surface brightness.
Define the StelTextureSP type.
void setFlagStarMagnitudeLimit(bool b)
Toggle the application of user-defined star magnitude limit.
const Extinction & getExtinction() const
Get the current valid extinction computation object.
This class performs extinction computations, following literature from atmospheric optics and astrono...
void preDrawPointSource(StelPainter *p)
Set the proper openGL state before making calls to drawPointSource.
const Refraction & getRefraction() const
Get the current valid refraction computation object.
float getLimitLuminance() const
Get the luminance of the faintest visible object (e.g.
This class performs refraction computations, following literature from atmospheric optics and astrono...
float getBig3dModelHaloRadius() const
Get the radius of the big halo texture used when a 3d model is very bright.
A templatized 2d vector compatible with openGL.
Definition: VecMath.hpp:32
void setFlagLuminanceAdaptation(bool b)
Set the value of the eye adaptation flag.
void setRelativeStarScale(double b=1.0)
Set the way brighter stars will look bigger as the fainter ones.
Main class for Stellarium core processing.
Definition: StelCore.hpp:46
void setAtmosphereTemperature(double celsius)
Set atmospheric (ground) temperature in deg celsius (for refraction).
void setPressure(float p_mbar)
Set surface air pressure (mbars), influences refraction computation.
void setFlagNebulaMagnitudeLimit(bool b)
Toggle the application of user-defined deep-sky object magnitude limit.
void postDrawSky3dModel(StelPainter *p, const Vec3f &v, float illuminatedArea, float mag, const Vec3f &color=Vec3f(1.f, 1.f, 1.f))
Terminate drawing of a 3D model, draw the halo.
~StelSkyDrawer()
Destructor.
float getCustomStarMagnitudeLimit() const
Get the value used for forced star magnitude limiting.
double getAtmospherePressure() const
Get atmospheric (ground) pressure in mbar (for refraction).
double getAtmosphereTemperature() const
Get atmospheric (ground) temperature in deg celsius (for refraction).
bool getFlagStarMagnitudeLimit() const
void setAbsoluteStarScale(double b=1.0)
Set the absolute star brightness scale.
double getExtinctionCoefficient() const
Get extinction coefficient, mag/airmass (for extinction).
bool computeRCMag(float mag, RCMag *) const
Compute RMag and CMag from magnitude.
Converts tones in function of the eye adaptation to luminance.
float getCustomNebulaMagnitudeLimit() const
Get the value used for forced nebula magnitude limiting.
void init()
Init parameters from config file.
bool drawPointSource(StelPainter *sPainter, const Vec3f &v, const RCMag &rcMag, unsigned int bV, bool checkInScreen=false)
Draw a point source halo.
Contains the 2 parameters necessary to draw a star on screen.
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
float getTwinkleAmount() const
Get source twinkle amount.
void setBortleScaleIndex(int index)
Set the parameters so that the stars disappear at about the limit given by the bortle scale The limit...
float getRelativeStarScale() const
Get the way brighter stars will look bigger as the fainter ones.
void setFlagTwinkle(bool b)
Set flag for source twinkling.
float getLimitMagnitude() const
Get the magnitude of the currently faintest visible point source It depends on the zoom level...
bool getFlagHasAtmosphere() const
This is used to decide whether to apply refraction/extinction before rendering point sources et al...
void setCustomStarMagnitudeLimit(double limit)
Sets a lower limit for star magnitudes (anything fainter is ignored).
bool getFlagLuminanceAdaptation() const
Get the current value of eye adaptation flag.
void setTemperature(float t_C)
Set surface air temperature (degrees Celsius), influences refraction computation. ...
Define the StelProjectorP type.
void reportLuminanceInFov(float lum, bool fastAdaptation=false)
Report that an object of luminance lum with an on-screen area of area pixels is currently displayed T...
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
static float luminanceToSurfacebrightness(float lum)
Compute the surface brightness from the luminance of an extended source.
void setAtmospherePressure(double mbar)
Set atmospheric (ground) pressure in mbar (for refraction).
int getBortleScaleIndex() const
Get the current Bortle scale index.
static float indexToBV(unsigned char bV)
Convert quantized B-V index to float B-V.
float getAbsoluteStarScale() const
Get the absolute star brightness scale.
void postDrawPointSource(StelPainter *sPainter)
Finalize the drawing of point sources.
void setTwinkleAmount(double b)
Set source twinkle amount.