Stellarium 0.13.1
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  {return drawPointSource(sPainter, v, rcMag, colorTable[bV], checkInScreen);}
78 
79  bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const RCMag &rcMag, const Vec3f& bcolor, bool checkInScreen=false);
80 
87  void postDrawSky3dModel(StelPainter* p, const Vec3f& v, float illuminatedArea, float mag, const Vec3f& color = Vec3f(1.f,1.f,1.f));
88 
93  bool computeRCMag(float mag, RCMag*) const;
94 
100  void reportLuminanceInFov(float lum, bool fastAdaptation=false);
101 
103  void preDraw();
104 
108  static float surfacebrightnessToLuminance(float sb);
112  static float luminanceToSurfacebrightness(float lum);
113 
115  static inline float indexToBV(unsigned char bV)
116  {
117  return (float)bV*(4.f/127.f)-0.5f;
118  }
119 
121  static inline const Vec3f& indexToColor(unsigned char bV)
122  {
123  return colorTable[bV];
124  }
125 
126 public slots:
128  void setRelativeStarScale(double b=1.0) {starRelativeScale=b;}
130  float getRelativeStarScale() const {return starRelativeScale;}
131 
133  void setAbsoluteStarScale(double b=1.0) {starAbsoluteScaleF=b;}
135  float getAbsoluteStarScale() const {return starAbsoluteScaleF;}
136 
138  void setTwinkleAmount(double b) {twinkleAmount=b;}
140  float getTwinkleAmount() const {return twinkleAmount;}
141 
143  void setFlagTwinkle(bool b) {flagStarTwinkle=b;}
145  bool getFlagTwinkle() const {return flagStarTwinkle;}
146 
150  void setBortleScaleIndex(int index);
152  int getBortleScaleIndex() const {return bortleScaleIndex;}
153 
157  float getLimitMagnitude() const {return limitMagnitude;}
158 
162  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
163  void setFlagStarMagnitudeLimit(bool b) {flagStarMagnitudeLimit = b;}
167  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
168  void setFlagNebulaMagnitudeLimit(bool b) {flagNebulaMagnitudeLimit = b;}
170  bool getFlagStarMagnitudeLimit() const {return flagStarMagnitudeLimit;}
172  bool getFlagNebulaMagnitudeLimit() const {return flagNebulaMagnitudeLimit;}
173 
175  float getCustomStarMagnitudeLimit() const {return customStarMagLimit;}
178  void setCustomStarMagnitudeLimit(double limit) {customStarMagLimit=limit;}
180  float getCustomNebulaMagnitudeLimit() const {return customNebulaMagLimit;}
183  void setCustomNebulaMagnitudeLimit(double limit) {customNebulaMagLimit=limit;}
184 
188  float getLimitLuminance() const {return limitLuminance;}
189 
191  void setFlagLuminanceAdaptation(bool b) {flagLuminanceAdaptation=b;}
193  bool getFlagLuminanceAdaptation() const {return flagLuminanceAdaptation;}
194 
197  void setFlagHasAtmosphere(bool b) {flagHasAtmosphere=b;}
199  bool getFlagHasAtmosphere() const {return flagHasAtmosphere;}
200 
202  void setExtinctionCoefficient(double extCoeff) {extinction.setExtinctionCoefficient(extCoeff);}
204  double getExtinctionCoefficient() const {return extinction.getExtinctionCoefficient();}
206  void setAtmosphereTemperature(double celsius) {refraction.setTemperature(celsius);}
208  double getAtmosphereTemperature() const {return refraction.getTemperature();}
210  void setAtmospherePressure(double mbar) {refraction.setPressure(mbar);}
212  double getAtmospherePressure() const {return refraction.getPressure();}
213 
215  const Extinction& getExtinction() const {return extinction;}
217  const Refraction& getRefraction() const {return refraction;}
218 
220  float getBig3dModelHaloRadius() const {return big3dModelHaloRadius;}
222  void setBig3dModelHaloRadius(float r) {big3dModelHaloRadius=r;}
223 
224 private:
225  // Debug
226  float reverseComputeRCMag(float rmag) const;
227 
229  float computeLimitMagnitude() const;
230 
232  float computeLimitLuminance() const;
233 
235  float getMaxAdaptFov(void) const {return maxAdaptFov;}
240  void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
241 
243  float getMinAdaptFov(void) const {return minAdaptFov;}
248  void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
249 
251  void setInputScale(float in) {inScale = in;}
253  float getInputScale() const {return inScale;}
254 
258  inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
259 
263  float pointSourceLuminanceToMag(float lum);
264 
268  float pointSourceMagToLnLuminance(float mag) const;
269 
272  float findWorldLumForMag(float mag, float targetRadius);
273 
274  StelCore* core;
275  StelToneReproducer* eye;
276 
277  Extinction extinction;
278  Refraction refraction;
279 
280  float maxAdaptFov, minAdaptFov, lnfovFactor;
281  bool flagStarTwinkle;
282  float twinkleAmount;
283 
286  bool flagHasAtmosphere;
287 
290  bool flagStarMagnitudeLimit;
293  bool flagNebulaMagnitudeLimit;
294 
295  float starRelativeScale;
296  float starAbsoluteScaleF;
297 
298  float starLinearScale; // optimization variable
299 
301  float limitMagnitude;
302 
304  float limitLuminance;
305 
310  float customStarMagLimit;
316  float customNebulaMagLimit;
317 
319  StelTextureSP texHalo;
320 
322  void initColorTableFromConfigFile(class QSettings* conf);
323 
325  static Vec3f colorTable[128];
326 
328  int bortleScaleIndex;
329 
331  float inScale;
332 
333  // Variables used for GL optimization when displaying point sources
336  struct StarVertex {
337  Vec2f pos;
338  unsigned char color[4];
339  };
340 
342  StarVertex* vertexArray;
343 
345  unsigned char* textureCoordArray;
346 
347  class QOpenGLShaderProgram* starShaderProgram;
348  struct StarShaderVars {
349  int projectionMatrix;
350  int texCoord;
351  int pos;
352  int color;
353  int texture;
354  };
355  StarShaderVars starShaderVars;
356 
358  unsigned int nbPointSources;
360  unsigned int maxPointSources;
361 
363  float maxLum;
365  float oldLum;
366 
368  StelTextureSP texBigHalo;
369  StelTextureSP texSunHalo;
370 
371  bool flagLuminanceAdaptation;
372 
373  float big3dModelHaloRadius;
374 };
375 
376 #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.
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.