1 /* 2 * Stellarium 3 * Copyright (C) 2003 Fabien Chereau 4 * Copyright (C) 2012 Timothy Reaves 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 19 */ 20 21 #ifndef ATMOSPHERE_HPP 22 #define ATMOSPHERE_HPP 23 24 #include "Skylight.hpp" 25 #include "VecMath.hpp" 26 27 #include "Skybright.hpp" 28 #include "StelFader.hpp" 29 30 #include <QOpenGLBuffer> 31 32 class StelProjector; 33 class StelToneReproducer; 34 class StelCore; 35 36 //! Compute and display the daylight sky color using OpenGL. 37 //! The sky brightness is computed with the SkyBright class, the color with the SkyLight. 38 //! Don't use this class directly but use it through the LandscapeMgr. 39 class Atmosphere 40 { 41 public: 42 Atmosphere(); 43 virtual ~Atmosphere(); 44 45 //! Compute sky brightness values and average luminance. 46 void computeColor(double JD, Vec3d _sunPos, Vec3d moonPos, float moonPhase, float moonMagnitude, StelCore* core, 47 float latitude = 45.f, float altitude = 200.f, 48 float temperature = 15.f, float relativeHumidity = 40.f); 49 void draw(StelCore* core); update(double deltaTime)50 void update(double deltaTime) {fader.update(static_cast<int>(deltaTime*1000));} 51 52 //! Set fade in/out duration in seconds setFadeDuration(float duration)53 void setFadeDuration(float duration) {fader.setDuration(static_cast<int>(duration*1000.f));} 54 //! Get fade in/out duration in seconds getFadeDuration() const55 float getFadeDuration() const {return static_cast<float>(fader.getDuration()/1000.f);} 56 57 //! Define whether to display atmosphere setFlagShow(bool b)58 void setFlagShow(bool b){fader = b;} 59 //! Get whether atmosphere is displayed getFlagShow() const60 bool getFlagShow() const {return fader;} 61 62 //! Get the actual atmosphere intensity due to eclipses + fader 63 //! @return the display intensity ranging from 0 to 1 getRealDisplayIntensityFactor() const64 float getRealDisplayIntensityFactor() const {return fader.getInterstate()*eclipseFactor;} 65 66 // lets you know how far faded in or out the atmosphere is (0..1) getFadeIntensity() const67 float getFadeIntensity() const {return fader.getInterstate();} 68 69 //! Get the average luminance of the atmosphere in cd/m2 70 //! If atmosphere is off, the luminance equals the background starlight (0.001cd/m2). 71 // TODO: Find reference for this value? Why 1 mcd/m2 without atmosphere and 0.1 mcd/m2 inside? Absorption? 72 //! Otherwise it includes the (atmosphere + background starlight (0.0001cd/m2) * eclipse factor + light pollution. 73 //! @return the last computed average luminance of the atmosphere in cd/m2. getAverageLuminance() const74 float getAverageLuminance() const {return averageLuminance;} 75 76 //! override computable luminance. This is for special operations only, e.g. for scripting of brightness-balanced image export. 77 //! To return to auto-computed values, set any negative value at the end of the script. 78 void setAverageLuminance(float overrideLum); 79 //! Set the light pollution luminance in cd/m^2 setLightPollutionLuminance(float f)80 void setLightPollutionLuminance(float f) { lightPollutionLuminance = f; } 81 //! Get the light pollution luminance in cd/m^2 getLightPollutionLuminance() const82 float getLightPollutionLuminance() const { return lightPollutionLuminance; } 83 84 private: 85 Vec4i viewport; 86 Skylight sky; 87 Skybright skyb; 88 unsigned int skyResolutionY,skyResolutionX; 89 90 Vec2f* posGrid; 91 QOpenGLBuffer posGridBuffer; 92 QOpenGLBuffer indicesBuffer; 93 Vec4f* colorGrid; 94 QOpenGLBuffer colorGridBuffer; 95 96 //! The average luminance of the atmosphere in cd/m2 97 float averageLuminance; 98 bool overrideAverageLuminance; // if true, don't compute but keep value set via setAverageLuminance(float) 99 float eclipseFactor; 100 LinearFader fader; 101 float lightPollutionLuminance; 102 103 //! Vertex shader used for xyYToRGB computation 104 class QOpenGLShaderProgram* atmoShaderProgram; 105 struct { 106 int bayerPattern; 107 int rgbMaxValue; 108 int alphaWaOverAlphaDa; 109 int oneOverGamma; 110 int term2TimesOneOverMaxdLpOneOverGamma; 111 int brightnessScale; 112 int sunPos; 113 int term_x, Ax, Bx, Cx, Dx, Ex; 114 int term_y, Ay, By, Cy, Dy, Ey; 115 int projectionMatrix; 116 int skyVertex; 117 int skyColor; 118 } shaderAttribLocations; 119 120 GLuint bayerPatternTex=0; 121 }; 122 123 #endif // ATMOSPHERE_HPP 124