Stellarium 0.15.0
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
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  */
23 #include "RefractionExtinction.hpp"
24 #include "StelTextureTypes.hpp"
25 #include "StelProjectorType.hpp"
26 #include "VecMath.hpp"
28 #include <QObject>
30 class StelToneReproducer;
31 class StelCore;
32 class StelPainter;
36 struct RCMag
37 {
38  float radius;
39  float luminance;
40 };
45 class StelSkyDrawer : public QObject
46 {
50  Q_PROPERTY(double relativeStarScale READ getRelativeStarScale WRITE setRelativeStarScale NOTIFY relativeStarScaleChanged)
52  Q_PROPERTY(double absoluteStarScale READ getAbsoluteStarScale WRITE setAbsoluteStarScale NOTIFY absoluteStarScaleChanged)
53  Q_PROPERTY(double twinkleAmount READ getTwinkleAmount WRITE setTwinkleAmount NOTIFY twinkleAmountChanged)
54  Q_PROPERTY(bool flagTwinkle READ getFlagTwinkle WRITE setFlagTwinkle NOTIFY flagTwinkleChanged)
55  Q_PROPERTY(int bortleScaleIndex READ getBortleScaleIndex WRITE setBortleScaleIndex NOTIFY bortleScaleIndexChanged)
57  Q_PROPERTY(bool flagStarMagnitudeLimit READ getFlagStarMagnitudeLimit WRITE setFlagStarMagnitudeLimit NOTIFY flagStarMagnitudeLimitChanged)
58  Q_PROPERTY(bool flagNebulaMagnitudeLimit READ getFlagNebulaMagnitudeLimit WRITE setFlagNebulaMagnitudeLimit NOTIFY flagNebulaMagnitudeLimitChanged)
59  Q_PROPERTY(bool flagPlanetMagnitudeLimit READ getFlagPlanetMagnitudeLimit WRITE setFlagPlanetMagnitudeLimit NOTIFY flagPlanetMagnitudeLimitChanged)
61  Q_PROPERTY(double customStarMagLimit READ getCustomStarMagnitudeLimit WRITE setCustomStarMagnitudeLimit NOTIFY customStarMagLimitChanged)
62  Q_PROPERTY(double customNebulaMagLimit READ getCustomNebulaMagnitudeLimit WRITE setCustomNebulaMagnitudeLimit NOTIFY customNebulaMagLimitChanged)
63  Q_PROPERTY(double customPlanetMagLimit READ getCustomPlanetMagnitudeLimit WRITE setCustomPlanetMagnitudeLimit NOTIFY customPlanetMagLimitChanged)
65  Q_PROPERTY(bool flagLuminanceAdaptation READ getFlagLuminanceAdaptation WRITE setFlagLuminanceAdaptation NOTIFY flagLuminanceAdaptationChanged)
67  Q_PROPERTY(double extinctionCoefficient READ getExtinctionCoefficient WRITE setExtinctionCoefficient NOTIFY extinctionCoefficientChanged)
68  Q_PROPERTY(double atmosphereTemperature READ getAtmosphereTemperature WRITE setAtmosphereTemperature NOTIFY atmosphereTemperatureChanged)
69  Q_PROPERTY(double atmospherePressure READ getAtmospherePressure WRITE setAtmospherePressure NOTIFY atmospherePressureChanged)
71 public:
74  StelSkyDrawer(StelCore* core);
79  void init();
83  void update(double deltaTime);
90  void postDrawPointSource(StelPainter* sPainter);
100  bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const RCMag &rcMag, unsigned int bV, bool checkInScreen=false, float twinkleFactor=1.0f)
101  {
102  return drawPointSource(sPainter, v, rcMag, colorTable[bV], checkInScreen, twinkleFactor);
103  }
105  bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const RCMag &rcMag, const Vec3f& bcolor, bool checkInScreen=false, float twinkleFactor=1.0f);
107  void drawSunCorona(StelPainter* painter, const Vec3f& v, float radius, const Vec3f& color, const float alpha);
115  void postDrawSky3dModel(StelPainter* p, const Vec3f& v, float illuminatedArea, float mag, const Vec3f& color = Vec3f(1.f,1.f,1.f));
121  bool computeRCMag(float mag, RCMag*) const;
128  void reportLuminanceInFov(float lum, bool fastAdaptation=false);
131  void preDraw();
136  static float surfacebrightnessToLuminance(float sb);
140  static float luminanceToSurfacebrightness(float lum);
143  static inline float indexToBV(unsigned char bV)
144  {
145  return (float)bV*(4.f/127.f)-0.5f;
146  }
149  static inline const Vec3f& indexToColor(unsigned char bV)
150  {
151  return colorTable[bV];
152  }
154 public slots:
156  void setRelativeStarScale(double b=1.0) {if(b!=starRelativeScale){ starRelativeScale=b; emit relativeStarScaleChanged(b);}}
158  double getRelativeStarScale() const {return starRelativeScale;}
161  void setAbsoluteStarScale(double b=1.0) {if(b!=starAbsoluteScaleF){ starAbsoluteScaleF=b; emit absoluteStarScaleChanged(b);}}
163  double getAbsoluteStarScale() const {return starAbsoluteScaleF;}
166  void setTwinkleAmount(double b) {if(b!=twinkleAmount){ twinkleAmount=b; emit twinkleAmountChanged(b);}}
168  double getTwinkleAmount() const {return twinkleAmount;}
171  void setFlagTwinkle(bool b) {if(b!=flagStarTwinkle){ flagStarTwinkle=b; emit flagTwinkleChanged(b);}}
173  bool getFlagTwinkle() const {return flagStarTwinkle;}
178  void setBortleScaleIndex(int index);
181  int getBortleScaleIndex() const {return bortleScaleIndex;}
186  float getLimitMagnitude() const {return limitMagnitude;}
191  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
192  void setFlagStarMagnitudeLimit(bool b) {if(b!=flagStarMagnitudeLimit){ flagStarMagnitudeLimit = b; emit flagStarMagnitudeLimitChanged(b);}}
194  bool getFlagStarMagnitudeLimit() const {return flagStarMagnitudeLimit;}
198  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
199  void setFlagNebulaMagnitudeLimit(bool b) {if(b!=flagNebulaMagnitudeLimit){ flagNebulaMagnitudeLimit = b; emit flagNebulaMagnitudeLimitChanged(b);}}
201  bool getFlagNebulaMagnitudeLimit() const {return flagNebulaMagnitudeLimit;}
205  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM --- GZ: this was copy/paste. Track down BM's changes!!!
206  void setFlagPlanetMagnitudeLimit(bool b) {if(b!=flagPlanetMagnitudeLimit){ flagPlanetMagnitudeLimit = b; emit flagPlanetMagnitudeLimitChanged(b);}}
208  bool getFlagPlanetMagnitudeLimit() const {return flagPlanetMagnitudeLimit;}
211  double getCustomStarMagnitudeLimit() const {return customStarMagLimit;}
214  void setCustomStarMagnitudeLimit(double limit) {if(limit!=customStarMagLimit){ customStarMagLimit=limit; emit customStarMagLimitChanged(limit);}}
216  double getCustomNebulaMagnitudeLimit() const {return customNebulaMagLimit;}
219  void setCustomNebulaMagnitudeLimit(double limit) {if(limit!=customNebulaMagLimit){ customNebulaMagLimit=limit; emit customNebulaMagLimitChanged(limit);}}
221  double getCustomPlanetMagnitudeLimit() const {return customPlanetMagLimit;}
224  void setCustomPlanetMagnitudeLimit(double limit) {if(limit!=customPlanetMagLimit){ customPlanetMagLimit=limit; emit customPlanetMagLimitChanged(limit);}}
229  float getLimitLuminance() const {return limitLuminance;}
232  void setFlagLuminanceAdaptation(bool b) {if(b!=flagLuminanceAdaptation){ flagLuminanceAdaptation=b; emit flagLuminanceAdaptationChanged(b);}}
234  bool getFlagLuminanceAdaptation() const {return flagLuminanceAdaptation;}
238  void setFlagHasAtmosphere(bool b) {flagHasAtmosphere=b;}
240  bool getFlagHasAtmosphere() const {return flagHasAtmosphere;}
243  void setExtinctionCoefficient(double extCoeff) {if(extCoeff!=extinction.getExtinctionCoefficient()){ extinction.setExtinctionCoefficient(extCoeff); emit extinctionCoefficientChanged(extinction.getExtinctionCoefficient());}}
245  double getExtinctionCoefficient() const {return extinction.getExtinctionCoefficient();}
247  void setAtmosphereTemperature(double celsius) {if(celsius!=refraction.getTemperature()){refraction.setTemperature(celsius); emit atmosphereTemperatureChanged(refraction.getTemperature());}}
249  double getAtmosphereTemperature() const {return refraction.getTemperature();}
251  void setAtmospherePressure(double mbar) {if(mbar!=refraction.getPressure()){ refraction.setPressure(mbar); emit atmospherePressureChanged(refraction.getPressure());}}
253  double getAtmospherePressure() const {return refraction.getPressure();}
256  const Extinction& getExtinction() const {return extinction;}
258  const Refraction& getRefraction() const {return refraction;}
261  float getBig3dModelHaloRadius() const {return big3dModelHaloRadius;}
263  void setBig3dModelHaloRadius(float r) {big3dModelHaloRadius=r;}
264 signals:
266  void relativeStarScaleChanged(double b);
268  void absoluteStarScaleChanged(double b);
270  void twinkleAmountChanged(double b);
272  void flagTwinkleChanged(bool b);
274  void bortleScaleIndexChanged(int index);
277  void flagStarMagnitudeLimitChanged(bool b);
279  void flagNebulaMagnitudeLimitChanged(bool b);
281  void flagPlanetMagnitudeLimitChanged(bool b);
284  void customStarMagLimitChanged(double limit);
286  void customNebulaMagLimitChanged(double limit);
288  void customPlanetMagLimitChanged(double limit);
291  void flagLuminanceAdaptationChanged(bool b);
293  void extinctionCoefficientChanged(double coeff);
294  void atmosphereTemperatureChanged(double celsius);
295  void atmospherePressureChanged(double mbar);
297 private:
298  // Debug
299  float reverseComputeRCMag(float rmag) const;
302  float computeLimitMagnitude() const;
305  float computeLimitLuminance() const;
308  float getMaxAdaptFov(void) const {return maxAdaptFov;}
313  void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
316  float getMinAdaptFov(void) const {return minAdaptFov;}
321  void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
324  void setInputScale(float in) {inScale = in;}
326  float getInputScale() const {return inScale;}
331  inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
336  float pointSourceLuminanceToMag(float lum);
341  float pointSourceMagToLnLuminance(float mag) const;
345  float findWorldLumForMag(float mag, float targetRadius);
347  StelCore* core;
348  StelToneReproducer* eye;
350  Extinction extinction;
351  Refraction refraction;
353  float maxAdaptFov, minAdaptFov, lnfovFactor;
354  bool flagStarTwinkle;
355  double twinkleAmount;
359  bool flagHasAtmosphere;
363  bool flagStarMagnitudeLimit;
366  bool flagNebulaMagnitudeLimit;
369  bool flagPlanetMagnitudeLimit;
371  double starRelativeScale;
372  double starAbsoluteScaleF;
374  float starLinearScale; // optimization variable
377  float limitMagnitude;
380  float limitLuminance;
386  double customStarMagLimit;
392  // GZ To explain: we have 3 limits for stars, nebulae, planets. It's easier to maintain the pretty similar code in 1 place.
393  double customNebulaMagLimit;
398  double customPlanetMagLimit;
401  StelTextureSP texHalo;
404  void initColorTableFromConfigFile(class QSettings* conf);
407  static Vec3f colorTable[128];
410  int bortleScaleIndex;
413  float inScale;
415  // Variables used for GL optimization when displaying point sources
418  struct StarVertex {
419  Vec2f pos;
420  unsigned char color[4];
421  };
424  StarVertex* vertexArray;
427  unsigned char* textureCoordArray;
429  class QOpenGLShaderProgram* starShaderProgram;
430  struct StarShaderVars {
431  int projectionMatrix;
432  int texCoord;
433  int pos;
434  int color;
435  int texture;
436  };
437  StarShaderVars starShaderVars;
440  unsigned int nbPointSources;
442  unsigned int maxPointSources;
445  float maxLum;
447  float oldLum;
450  StelTextureSP texBigHalo;
451  StelTextureSP texSunHalo;
452  StelTextureSP texSunCorona;
454  bool flagLuminanceAdaptation;
456  float big3dModelHaloRadius;
457 };
459 #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)
void preDraw()
To be called before the drawing stage starts.
bool getFlagTwinkle() const
Get flag for source twinkling.
double getCustomStarMagnitudeLimit() const
Get the value used for forced star magnitude limiting.
void flagLuminanceAdaptationChanged(bool b)
Emitted whenever the luminance adaptation flag is toggled.
void flagTwinkleChanged(bool b)
Emitted whenever the twinkle flag is toggled.
void relativeStarScaleChanged(double b)
Emitted whenever the relative star scale changed.
bool getFlagNebulaMagnitudeLimit() const
void flagNebulaMagnitudeLimitChanged(bool b)
Emitted whenever the nebula magnitude limit flag is toggled.
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.
A templatized 3d vector compatible with openGL.
Definition: VecMath.hpp:33
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.
void flagStarMagnitudeLimitChanged(bool b)
Emitted whenever the star magnitude limit flag is toggled.
void setFlagLuminanceAdaptation(bool b)
Set the value of the eye adaptation flag.
void twinkleAmountChanged(double b)
Emitted whenever the twinkle amount changed.
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:48
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.
void bortleScaleIndexChanged(int index)
Emitted whenever the Bortle scale index changed.
void flagPlanetMagnitudeLimitChanged(bool b)
Emitted whenever the planet magnitude limit flag is toggled.
double getAtmospherePressure() const
Get atmospheric (ground) pressure in mbar (for refraction).
void customPlanetMagLimitChanged(double limit)
Emitted whenever the planet magnitude limit changed.
double getAtmosphereTemperature() const
Get atmospheric (ground) temperature in deg celsius (for refraction).
bool getFlagStarMagnitudeLimit() const
double getAbsoluteStarScale() const
Get the absolute star brightness scale.
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.
bool getFlagPlanetMagnitudeLimit() const
void init()
Init parameters from config file.
void customNebulaMagLimitChanged(double limit)
Emitted whenever the nebula magnitude limit changed.
Contains the 2 parameters necessary to draw a star on screen.
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
void setBortleScaleIndex(int index)
Set the parameters so that the stars disappear at about the limit given by the bortle scale The limit...
void setFlagTwinkle(bool b)
Set flag for source twinkling.
void setCustomPlanetMagnitudeLimit(double limit)
Sets a lower limit for solar system object magnitudes (anything fainter is ignored).
float getLimitMagnitude() const
Get the magnitude of the currently faintest visible point source It depends on the zoom level...
void absoluteStarScaleChanged(double b)
Emitted whenever the absolute star scale changed.
double getCustomNebulaMagnitudeLimit() const
Get the value used for forced nebula magnitude limiting.
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.
double getRelativeStarScale() const
Get the way brighter stars will look bigger as the fainter ones.
double getCustomPlanetMagnitudeLimit() const
Get the value used for forced solar system object magnitude limiting.
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.
bool drawPointSource(StelPainter *sPainter, const Vec3f &v, const RCMag &rcMag, unsigned int bV, bool checkInScreen=false, float twinkleFactor=1.0f)
Draw a point source halo.
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.
double getTwinkleAmount() const
Get source twinkle amount.
void setFlagPlanetMagnitudeLimit(bool b)
Toggle the application of user-defined solar system object magnitude limit.
static float indexToBV(unsigned char bV)
Convert quantized B-V index to float B-V.
void customStarMagLimitChanged(double limit)
Emitted whenever the star magnitude limit changed.
void postDrawPointSource(StelPainter *sPainter)
Finalize the drawing of point sources.
void setTwinkleAmount(double b)
Set source twinkle amount.