Stellarium 0.14.3
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 
83  void drawSunCorona(StelPainter* painter, const Vec3f& v, float radius, const Vec3f& color, const float alpha);
84 
91  void postDrawSky3dModel(StelPainter* p, const Vec3f& v, float illuminatedArea, float mag, const Vec3f& color = Vec3f(1.f,1.f,1.f));
92 
97  bool computeRCMag(float mag, RCMag*) const;
98 
104  void reportLuminanceInFov(float lum, bool fastAdaptation=false);
105 
107  void preDraw();
108 
112  static float surfacebrightnessToLuminance(float sb);
116  static float luminanceToSurfacebrightness(float lum);
117 
119  static inline float indexToBV(unsigned char bV)
120  {
121  return (float)bV*(4.f/127.f)-0.5f;
122  }
123 
125  static inline const Vec3f& indexToColor(unsigned char bV)
126  {
127  return colorTable[bV];
128  }
129 
130 public slots:
132  void setRelativeStarScale(double b=1.0) {starRelativeScale=b;}
134  float getRelativeStarScale() const {return starRelativeScale;}
135 
137  void setAbsoluteStarScale(double b=1.0) {starAbsoluteScaleF=b;}
139  float getAbsoluteStarScale() const {return starAbsoluteScaleF;}
140 
142  void setTwinkleAmount(double b) {twinkleAmount=b;}
144  float getTwinkleAmount() const {return twinkleAmount;}
145 
147  void setFlagTwinkle(bool b) {flagStarTwinkle=b;}
149  bool getFlagTwinkle() const {return flagStarTwinkle;}
150 
154  void setBortleScaleIndex(int index);
156  int getBortleScaleIndex() const {return bortleScaleIndex;}
157 
161  float getLimitMagnitude() const {return limitMagnitude;}
162 
166  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
167  void setFlagStarMagnitudeLimit(bool b) {flagStarMagnitudeLimit = b;}
169  bool getFlagStarMagnitudeLimit() const {return flagStarMagnitudeLimit;}
173  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
174  void setFlagNebulaMagnitudeLimit(bool b) {flagNebulaMagnitudeLimit = b;}
176  bool getFlagNebulaMagnitudeLimit() const {return flagNebulaMagnitudeLimit;}
180  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM --- GZ: this was copy/paste. Track down BM's changes!!!
181  void setFlagPlanetMagnitudeLimit(bool b) {flagPlanetMagnitudeLimit = b;}
183  bool getFlagPlanetMagnitudeLimit() const {return flagPlanetMagnitudeLimit;}
184 
186  float getCustomStarMagnitudeLimit() const {return customStarMagLimit;}
189  void setCustomStarMagnitudeLimit(double limit) {customStarMagLimit=limit;}
191  float getCustomNebulaMagnitudeLimit() const {return customNebulaMagLimit;}
194  void setCustomNebulaMagnitudeLimit(double limit) {customNebulaMagLimit=limit;}
196  float getCustomPlanetMagnitudeLimit() const {return customPlanetMagLimit;}
199  void setCustomPlanetMagnitudeLimit(double limit) {customPlanetMagLimit=limit;}
200 
204  float getLimitLuminance() const {return limitLuminance;}
205 
207  void setFlagLuminanceAdaptation(bool b) {flagLuminanceAdaptation=b;}
209  bool getFlagLuminanceAdaptation() const {return flagLuminanceAdaptation;}
210 
213  void setFlagHasAtmosphere(bool b) {flagHasAtmosphere=b;}
215  bool getFlagHasAtmosphere() const {return flagHasAtmosphere;}
216 
218  void setExtinctionCoefficient(double extCoeff) {extinction.setExtinctionCoefficient(extCoeff);}
220  double getExtinctionCoefficient() const {return extinction.getExtinctionCoefficient();}
222  void setAtmosphereTemperature(double celsius) {refraction.setTemperature(celsius);}
224  double getAtmosphereTemperature() const {return refraction.getTemperature();}
226  void setAtmospherePressure(double mbar) {refraction.setPressure(mbar);}
228  double getAtmospherePressure() const {return refraction.getPressure();}
229 
231  const Extinction& getExtinction() const {return extinction;}
233  const Refraction& getRefraction() const {return refraction;}
234 
236  float getBig3dModelHaloRadius() const {return big3dModelHaloRadius;}
238  void setBig3dModelHaloRadius(float r) {big3dModelHaloRadius=r;}
239 
240 private:
241  // Debug
242  float reverseComputeRCMag(float rmag) const;
243 
245  float computeLimitMagnitude() const;
246 
248  float computeLimitLuminance() const;
249 
251  float getMaxAdaptFov(void) const {return maxAdaptFov;}
256  void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
257 
259  float getMinAdaptFov(void) const {return minAdaptFov;}
264  void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
265 
267  void setInputScale(float in) {inScale = in;}
269  float getInputScale() const {return inScale;}
270 
274  inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
275 
279  float pointSourceLuminanceToMag(float lum);
280 
284  float pointSourceMagToLnLuminance(float mag) const;
285 
288  float findWorldLumForMag(float mag, float targetRadius);
289 
290  StelCore* core;
291  StelToneReproducer* eye;
292 
293  Extinction extinction;
294  Refraction refraction;
295 
296  float maxAdaptFov, minAdaptFov, lnfovFactor;
297  bool flagStarTwinkle;
298  float twinkleAmount;
299 
302  bool flagHasAtmosphere;
303 
306  bool flagStarMagnitudeLimit;
309  bool flagNebulaMagnitudeLimit;
312  bool flagPlanetMagnitudeLimit;
313 
314  float starRelativeScale;
315  float starAbsoluteScaleF;
316 
317  float starLinearScale; // optimization variable
318 
320  float limitMagnitude;
321 
323  float limitLuminance;
324 
329  float customStarMagLimit;
335  // GZ To explain: we have 3 limits for stars, nebulae, planets. It's easier to maintain the pretty similar code in 1 place.
336  float customNebulaMagLimit;
341  float customPlanetMagLimit;
342 
344  StelTextureSP texHalo;
345 
347  void initColorTableFromConfigFile(class QSettings* conf);
348 
350  static Vec3f colorTable[128];
351 
353  int bortleScaleIndex;
354 
356  float inScale;
357 
358  // Variables used for GL optimization when displaying point sources
361  struct StarVertex {
362  Vec2f pos;
363  unsigned char color[4];
364  };
365 
367  StarVertex* vertexArray;
368 
370  unsigned char* textureCoordArray;
371 
372  class QOpenGLShaderProgram* starShaderProgram;
373  struct StarShaderVars {
374  int projectionMatrix;
375  int texCoord;
376  int pos;
377  int color;
378  int texture;
379  };
380  StarShaderVars starShaderVars;
381 
383  unsigned int nbPointSources;
385  unsigned int maxPointSources;
386 
388  float maxLum;
390  float oldLum;
391 
393  StelTextureSP texBigHalo;
394  StelTextureSP texSunHalo;
395  StelTextureSP texSunCorona;
396 
397  bool flagLuminanceAdaptation;
398 
399  float big3dModelHaloRadius;
400 };
401 
402 #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.
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.
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: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.
~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).
float getCustomPlanetMagnitudeLimit() const
Get the value used for forced solar system object magnitude limiting.
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.
bool getFlagPlanetMagnitudeLimit() const
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.
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...
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.
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.
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.