00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _STELSKYDRAWER_HPP_
00021 #define _STELSKYDRAWER_HPP_
00022
00023 #include "StelTextureTypes.hpp"
00024 #include "StelProjectorType.hpp"
00025 #include "VecMath.hpp"
00026
00027 #include <QObject>
00028
00029 class StelToneReproducer;
00030 class StelCore;
00031 class StelPainter;
00032
00036 class StelSkyDrawer : public QObject
00037 {
00038 Q_OBJECT
00039 public:
00041 StelSkyDrawer(StelCore* core);
00043 ~StelSkyDrawer();
00044
00046 void init();
00047
00050 void update(double deltaTime);
00051
00054 void preDrawPointSource(StelPainter* p);
00055
00057 void postDrawPointSource(StelPainter* sPainter);
00058
00066 bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const float rcMag[2], unsigned int bV, bool checkInScreen=false)
00067 {return drawPointSource(sPainter, v, rcMag, colorTable[bV], checkInScreen);}
00068
00069 bool drawPointSource(StelPainter* sPainter,const Vec3f& v, const float rcMag[2], const Vec3f& color, bool checkInScreen=false);
00070
00077 void postDrawSky3dModel(StelPainter* p, const Vec3f& v, float illuminatedArea, float mag, const Vec3f& color = Vec3f(1.f,1.f,1.f));
00078
00083 bool computeRCMag(float mag, float rcMag[2]) const;
00084
00090 void reportLuminanceInFov(float lum, bool fastAdaptation=false);
00091
00093 void preDraw();
00094
00098 static float surfacebrightnessToLuminance(float sb);
00102 static float luminanceToSurfacebrightness(float lum);
00103
00105 static inline float indexToBV(unsigned char bV)
00106 {
00107 return (float)bV*(4.f/127.f)-0.5f;
00108 }
00109
00111 static inline const Vec3f& indexToColor(unsigned char bV)
00112 {
00113 return colorTable[bV];
00114 }
00115
00116 public slots:
00118 void setRelativeStarScale(double b=1.0) {starRelativeScale=b;}
00120 float getRelativeStarScale() const {return starRelativeScale;}
00121
00123 void setAbsoluteStarScale(double b=1.0) {starAbsoluteScaleF=b;}
00125 float getAbsoluteStarScale() const {return starAbsoluteScaleF;}
00126
00128 void setTwinkleAmount(double b) {twinkleAmount=b;}
00130 float getTwinkleAmount() const {return twinkleAmount;}
00131
00133 void setFlagTwinkle(bool b) {flagStarTwinkle=b;}
00135 bool getFlagTwinkle() const {return flagStarTwinkle;}
00136
00138 void setFlagPointStar(bool b) {flagPointStar=b;}
00140 bool getFlagPointStar() const {return flagPointStar;}
00141
00145 void setBortleScale(int index);
00147 int getBortleScale() const {return bortleScaleIndex;}
00148
00152 float getLimitMagnitude() const {return limitMagnitude;}
00153
00157 float getLimitLuminance() const {return limitLuminance;}
00158
00160 void setFlagLuminanceAdaptation(bool b) {flagLuminanceAdaptation=b;}
00162 bool getFlagLuminanceAdaptation(void) const {return flagLuminanceAdaptation;}
00163
00166 void setFlagHasAtmosphere(bool b) {flagHasAtmosphere=b;}
00167
00168 private:
00169
00170 float reverseComputeRCMag(float rmag) const;
00171
00173 float computeLimitMagnitude() const;
00174
00176 float computeLimitLuminance() const;
00177
00179 float getMaxAdaptFov(void) const {return maxAdaptFov;}
00184 void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
00185
00187 float getMinAdaptFov(void) const {return minAdaptFov;}
00192 void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
00193
00195 void setInputScale(float in) {inScale = in;}
00197 float getInputScale() const {return inScale;}
00198
00202 inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
00203
00207 float pointSourceLuminanceToMag(float lum);
00208
00212 float pointSourceMagToLnLuminance(float mag) const;
00213
00216 float findWorldLumForMag(float mag, float targetRadius);
00217
00218 StelCore* core;
00219 StelToneReproducer* eye;
00220
00221 float maxAdaptFov, minAdaptFov, lnfovFactor;
00222 bool flagPointStar;
00223 bool flagStarTwinkle;
00224 float twinkleAmount;
00225
00228 bool flagHasAtmosphere;
00229
00230 float starRelativeScale;
00231 float starAbsoluteScaleF;
00232
00233 float starLinearScale;
00234
00236 float limitMagnitude;
00237
00239 float limitLuminance;
00240
00242 StelTextureSP texHalo;
00243
00245 void initColorTableFromConfigFile(class QSettings* conf);
00246
00248 static Vec3f colorTable[128];
00249
00251 int bortleScaleIndex;
00252
00254 float inScale;
00255
00256
00258 Vec2f* verticesGrid;
00260 Vec3f* colorGrid;
00262 Vec2f* textureGrid;
00264 unsigned int nbPointSources;
00266 unsigned int maxPointSources;
00267
00269 float maxLum;
00271 float oldLum;
00272
00274 StelTextureSP texBigHalo;
00275 StelTextureSP texSunHalo;
00276
00277 bool flagLuminanceAdaptation;
00278
00279 bool useShader;
00280 class QGLShaderProgram* starsShaderProgram;
00281 };
00282
00283 #endif // _STELSKYDRAWER_HPP_