RefractionExtinction.hpp   RefractionExtinction.hpp 
skipping to change at line 48 skipping to change at line 48
//! and may show stars in their full brightness below -2 degrees. //! and may show stars in their full brightness below -2 degrees.
//! Typical horizons do not go down below -1, so all natural sites should b e covered. //! Typical horizons do not go down below -1, so all natural sites should b e covered.
//! Note that forward/backward are no absolute reverse operations! //! Note that forward/backward are no absolute reverse operations!
//! All the computations should be in effect //! All the computations should be in effect
//! (1) only if atmosphere effects are true //! (1) only if atmosphere effects are true
//! (2) only for terrestrial locations, not on Moon/Mars/Saturn etc //! (2) only for terrestrial locations, not on Moon/Mars/Saturn etc
//! config.ini:astro/flag_extinction_below_horizon=true|false controls if e xtinction kills objects below -2 degrees altitude by setting airmass to 42. //! config.ini:astro/flag_extinction_below_horizon=true|false controls if e xtinction kills objects below -2 degrees altitude by setting airmass to 42.
class Extinction class Extinction
{ {
public: public:
//! Define the extinction strategy for rendering underground objects
(usefull when ground is not rendered)
enum UndergroundExtinctionMode {
UndergroundExtinctionZero = 0, //!< Zero extinction: stars
visible in full brightness
UndergroundExtinctionMax = 1, //!< Maximum extinction: coe
f 42, i.e practically invisible
UndergroundExtinctionMirror = 2 //!< Mirror the extinction f
or the same altutide above the ground.
};
Extinction(); Extinction();
//! Compute extinction effect for arrays of size @param num position vectors and magnitudes. //! Compute extinction effect for arrays of size @param num position vectors and magnitudes.
//! @param altAzPos are the NORMALIZED (!!) (apparent) star position //! @param altAzPos are the NORMALIZED (!!) (geometrical) star posit
vectors, and their z components sin(apparent_altitude). ion vectors, and their z components sin(apparent_altitude).
//! @param mag the magnitudes //! This call must therefore be done before application of Refractio
//! This call must therefore be done after application of Refraction n if atmospheric effects are on.
, and only if atmospheric effects are on. //! Note that forward/backward are no absolute reverse operations!
//! Note that forward/backward are no absolute reverse operations! void forward(const Vec3d& altAzPos, float* mag) const
void forward(const Vec3d *altAzPos, float *mag, const int num=1) con {
st; Q_ASSERT(std::fabs(altAzPos.length()-1.f)<0.001f);
void forward(const Vec3f *altAzPos, float *mag, const int num=1) con *mag += airmass(altAzPos[2], false) * ext_coeff;
st; }
void forward(const double *sinAlt, float *mag, const int num) const
; void forward(const Vec3f& altAzPos, float* mag) const
void forward(const float *sinAlt, float *mag, const int num) const {
; Q_ASSERT(std::fabs(altAzPos.length()-1.f)<0.001f);
void forward(const double *sinAlt, float *mag) const; *mag += airmass(altAzPos[2], false) * ext_coeff;
void forward(const float *sinAlt, float *mag) const; }
//! Compute inverse extinction effect for arrays of size @param num position vectors and magnitudes. //! Compute inverse extinction effect for arrays of size @param num position vectors and magnitudes.
//! @param altAzPos are the NORMALIZED (!!) (apparent) star position //! @param altAzPos are the NORMALIZED (!!) (geometrical) star posit
vectors, and their z components sin(apparent_altitude). ion vectors, and their z components sin(apparent_altitude).
//! @param mag the magnitudes
//! Note that forward/backward are no absolute reverse operations! //! Note that forward/backward are no absolute reverse operations!
void backward(const Vec3d *altAzPos, float *mag, const int num=1) co void backward(const Vec3d& altAzPos, float* mag) const
nst; {
void backward(const Vec3f *altAzPos, float *mag, const int num=1) co *mag -= airmass(altAzPos[2], false) * ext_coeff;
nst; }
void backward(const double *sinAlt, float *mag, const int num=1) co
nst; void backward(const Vec3f& altAzPos, float* mag) const
void backward(const float *sinAlt, float *mag, const int num=1) co {
nst; *mag -= airmass(altAzPos[2], false) * ext_coeff;
}
//! Set visual extinction coefficient (mag/airmass), influences exti nction computation. //! Set visual extinction coefficient (mag/airmass), influences exti nction computation.
//! @param k= 0.1 for highest mountains, 0.2 for very good lowland l ocations, 0.35 for typical lowland, 0.5 in humid climates. //! @param k= 0.1 for highest mountains, 0.2 for very good lowland l ocations, 0.35 for typical lowland, 0.5 in humid climates.
void setExtinctionCoefficient(float k) { ext_coeff=k; } void setExtinctionCoefficient(float k) { ext_coeff=k; }
float getExtinctionCoefficient() const {return ext_coeff;} float getExtinctionCoefficient() const {return ext_coeff;}
void setUndergroundExtinctionMode(UndergroundExtinctionMode mode) {u
ndergroundExtinctionMode=mode;}
UndergroundExtinctionMode getUndergroundExtinctionMode() const {retu
rn undergroundExtinctionMode;}
private: private:
//! airmass computation for @param cosZ = cosine of zenith angle z ( =sin(altitude)!). //! airmass computation for @param cosZ = cosine of zenith angle z ( =sin(altitude)!).
//! The default (@param apparent_z = true) is computing airmass from observed altitude, following Rozenberg (1966) [X(90)~40]. //! The default (@param apparent_z = true) is computing airmass from observed altitude, following Rozenberg (1966) [X(90)~40].
//! if (@param apparent_z = false), we have geometrical altitude and compute airmass from that, //! if (@param apparent_z = false), we have geometrical altitude and compute airmass from that,
//! following Young: Air mass and refraction. Applied Optics 33(6), pp.1108-1110, 1994. [X(90)~32]. //! following Young: Air mass and refraction. Applied Optics 33(6), pp.1108-1110, 1994. [X(90)~32].
//! A problem ist that refraction depends on air pressure and temper ature, but Young's formula assumes T=15C, p=1013.25mbar. //! A problem ist that refraction depends on air pressure and temper ature, but Young's formula assumes T=15C, p=1013.25mbar.
//! So, it seems better to compute refraction first, and then use th e Rozenberg formula here. //! So, it seems better to compute refraction first, and then use th e Rozenberg formula here.
//! Rozenberg is infinite at Z=92.17 deg, Young at Z=93.6 deg, so th is function RETURNS SUBHORIZONTAL_AIRMASS BELOW -2 DEGREES! //! Rozenberg is infinite at Z=92.17 deg, Young at Z=93.6 deg, so th is function RETURNS SUBHORIZONTAL_AIRMASS BELOW -2 DEGREES!
float airmass(const float cosZ, const bool apparent_z=true) const; float airmass(float cosZ, const bool apparent_z=true) const;
//! k, magnitudes/airmass, in [0.00, ... 1.00], (default 0.20). //! k, magnitudes/airmass, in [0.00, ... 1.00], (default 0.20).
float ext_coeff; float ext_coeff;
//! should be either 0.0 (stars visible in full brightness below hor
izon) or 40.0 (or 42? ;-) practically invisible) //! Define what we are going to do for underground stars when ground
//! Maybe make this a user-configurable option? is not rendered
static float SUBHORIZONTAL_AIRMASS; UndergroundExtinctionMode undergroundExtinctionMode;
}; };
//! @class Refraction //! @class Refraction
//! This class performs refraction computations, following literature from atmospheric optics and astronomy. //! This class performs refraction computations, following literature from atmospheric optics and astronomy.
//! Refraction solutions can only be aproximate, given the turbulent, unpre dictable real atmosphere. //! Refraction solutions can only be aproximate, given the turbulent, unpre dictable real atmosphere.
//! Typical horizons do not go down below -1, so strange effects (distortio n) between -2 and -5 should be covered. //! Typical horizons do not go down below -1, so strange effects (distortio n) between -2 and -5 should be covered.
//! Note that forward/backward are no absolute reverse operations! //! Note that forward/backward are no absolute reverse operations!
//! All the computations should be in effect //! All the computations should be in effect
//! (1) only if atmosphere effects are true //! (1) only if atmosphere effects are true
//! (2) only for celestial objects, never for landscape images //! (2) only for celestial objects, never for landscape images
//! (3) only for terrestrial locations, not on Moon/Mars/Saturn etc //! (3) only for terrestrial locations, not on Moon/Mars/Saturn etc
class Refraction: public StelProjector::ModelViewTranform class Refraction: public StelProjector::ModelViewTranform
{ {
public: public:
Refraction(); Refraction();
//! Apply refraction. //! Apply refraction.
//! @param altAzPos is the geometrical star position vector, to be t ransformed into apparent position. //! @param altAzPos is the geometrical star position vector, to be t ransformed into apparent position.
//! Note that forward/backward are no absolute reverse operations! //! Note that forward/backward are no absolute reverse operations!
virtual void forward(Vec3d& altAzPos) const; void forward(Vec3d& altAzPos) const;
//! Remove refraction from position ("reduce"). //! Remove refraction from position ("reduce").
//! @param altAzPos is the apparent star position vector, to be tran sformed into geometrical position. //! @param altAzPos is the apparent star position vector, to be tran sformed into geometrical position.
//! Note that forward/backward are no absolute reverse operations! //! Note that forward/backward are no absolute reverse operations!
virtual void backward(Vec3d& altAzPos) const; void backward(Vec3d& altAzPos) const;
//! Apply refraction. //! Apply refraction.
//! @param altAzPos is the geometrical star position vector, to be t ransformed into apparent position. //! @param altAzPos is the geometrical star position vector, to be t ransformed into apparent position.
//! Note that forward/backward are no absolute reverse operations! //! Note that forward/backward are no absolute reverse operations!
virtual void forward(Vec3f& altAzPos) const; void forward(Vec3f& altAzPos) const;
//! Remove refraction from position ("reduce"). //! Remove refraction from position ("reduce").
//! @param altAzPos is the apparent star position vector, to be tran sformed into geometrical position. //! @param altAzPos is the apparent star position vector, to be tran sformed into geometrical position.
//! Note that forward/backward are no absolute reverse operations! //! Note that forward/backward are no absolute reverse operations!
virtual void backward(Vec3f& altAzPos) const; void backward(Vec3f& altAzPos) const;
virtual void combine(const Mat4d& m) void combine(const Mat4d& m)
{ {
setPreTransfoMat(preTransfoMat*m); setPreTransfoMat(preTransfoMat*m);
} }
virtual Mat4d getApproximateLinearTransfo() const {return postTransf Mat4d getApproximateLinearTransfo() const {return postTransfoMat*pre
oMat*preTransfoMat;} TransfoMat;}
virtual StelProjector::ModelViewTranformP clone() const {Refraction*
refr = new Refraction(); *refr=*this; return StelProjector::ModelViewTranf
ormP(refr);}
virtual bool setupGLSLTransform(StelGLSLShader* shader) StelProjector::ModelViewTranformP clone() const {Refraction* refr =
{ new Refraction(); *refr=*this; return StelProjector::ModelViewTranformP(ref
Q_UNUSED(shader); r);}
return false;
// GL-REFACTOR:
//
// I reimplemented the forward() member function in GLSL, bu
t the result is
// not usable at the moment.
//
// On Intel drivers, the projection gets completely messed u
p.
// On AMD, most of the time, the coordinates are projected i
n slightly
// different locations (e.g. a planet is slightly above/belo
w where it's
// supposed to be), and there is very nasty jitter on the in
dividual vertex
// positions.
// NVidia behaves the same, _and_ the viewport borders are m
essed up.
//
//
// The most likely cause of the problem is the imprecision o
f GLSL
// sin, asin and tan (which AFAIK are implemented through lo
w-resolution
// lookup tables in hardware).
//
// However, it is also possible that I incorrectly translate
d forward() to
// GLSL.
//
//
// Different possible ways to implement refraction in GLSL w
ould be
// to use custom, higher-resolution lookup tables (textures)
, or to use
// a different, maybe simpler (less trig) algorithm for refr
action.
// if(!shader->hasVertexShader("RefractionTransform"))
// {
// static const QString source(
// "uniform mat4 preTransfoMat;\n"
// "uniform mat4 postTransfoMat;\n"
// "uniform float press_temp_corr_Saemundson;\n
"
// "// These values must match the C++ code.\n"
// "const float MIN_GEO_ALTITUDE_DEG = -3.54;\n
"
// "const float TRANSITION_WIDTH_GEO_DEG = 1.46
;\n"
// "\n"
// "vec4 modelViewForward(in vec4 altAzPos)\n"
// "{\n"
// " vec4 localAltAzPos = preTransfoMat * al
tAzPos;\n"
// " float len = length(localAltAzPos.xyz);\
n"
// " float geom_alt_deg = degrees(asin(local
AltAzPos.z / len));\n"
// " if(geom_alt_deg > MIN_GEO_ALTITUDE_DEG)
\n"
// " {\n"
// " // refraction from Saemundsson, S&T
1986 p70 / in Meeus, Astr.Alg.\n"
// " float r = press_temp_corr_Saemundso
n / \n"
// " tan(radians(geom_alt_deg
+ 10.3 / (geom_alt_deg + 5.11))) + 0.0019279;\n"
// " geom_alt_deg += r;\n"
// " geom_alt_deg = min(geom_alt_deg, 90
.0); // SAFETY\n"
// " localAltAzPos.z = sin(radians(geom_
alt_deg)) * len;\n"
// " }\n"
// " else if(geom_alt_deg > (MIN_GEO_ALTITUD
E_DEG - TRANSITION_WIDTH_GEO_DEG))\n"
// " {\n"
// " // Avoids the jump below -5 by inte
rpolating linearly between\n"
// " // MIN_GEO_ALTITUDE_DEG and bottom
of transition zone\n"
// " float r_m5 = press_temp_corr_Saemun
dson / \n"
// " tan(radians(MIN_GEO_AL
TITUDE_DEG + 10.3 / (MIN_GEO_ALTITUDE_DEG + 5.11)))\n"
// " + 0.0019279;\n"
// " geom_alt_deg += r_m5 * \n"
// " (geom_alt_deg - (MI
N_GEO_ALTITUDE_DEG - TRANSITION_WIDTH_GEO_DEG)) /\n"
// " TRANSITION_WIDTH_GE
O_DEG;\n"
// " localAltAzPos.z = sin(radians(geom_
alt_deg)) * len;\n"
// " }\n"
// " return postTransfoMat * localAltAzPos;\
n"
// "}\n");
// if(!shader->addVertexShader("RefractionTransform", s
ource))
// {
// return false;
// }
// qDebug() << "Build log after adding a refraction sha
der: " << shader->log();
// }
// shader->enableVertexShader("RefractionTransform");
// return true;
}
virtual void setGLSLUniforms(StelGLSLShader* shader)
{
Q_UNUSED(shader);
// shader->setUniformValue("preTransfoMat", preTransfoMatf);
// shader->setUniformValue("postTransfoMat", postTransfoMatf
);
// shader->setUniformValue("press_temp_corr_Saemundson", pre
ss_temp_corr_Saemundson);
}
virtual void disableGLSLTransform(StelGLSLShader* shader)
{
Q_UNUSED(shader);
// shader->disableVertexShader("RefractionTransform");
}
//! Set surface air pressure (mbars), influences refraction computat ion. //! Set surface air pressure (mbars), influences refraction computat ion.
void setPressure(float p_mbar); void setPressure(float p_mbar);
float getPressure() const {return pressure;} float getPressure() const {return pressure;}
//! Set surface air temperature (degrees Celsius), influences refrac tion computation. //! Set surface air temperature (degrees Celsius), influences refrac tion computation.
void setTemperature(float t_C); void setTemperature(float t_C);
float getTemperature() const {return temperature;} float getTemperature() const {return temperature;}
//! Set the transformation matrices used to transform input vector t o AltAz frame. //! Set the transformation matrices used to transform input vector t o AltAz frame.
void setPreTransfoMat(const Mat4d& m); void setPreTransfoMat(const Mat4d& m);
void setPostTransfoMat(const Mat4d& m); void setPostTransfoMat(const Mat4d& m);
private: private:
//! Update precomputed variables. //! Update precomputed variables.
void updatePrecomputed(); void updatePrecomputed();
void innerRefractionForward(Vec3d& altAzPos) const;
void innerRefractionBackward(Vec3d& altAzPos) const;
//! These 3 Atmosphere parameters can be controlled by GUI. //! These 3 Atmosphere parameters can be controlled by GUI.
//! Pressure[mbar] (1013) //! Pressure[mbar] (1013)
float pressure; float pressure;
//! Temperature[Celsius deg] (10). //! Temperature[Celsius deg] (10).
float temperature; float temperature;
//! Numerator of refraction formula, to be cached for speed. //! Numerator of refraction formula, to be cached for speed.
float press_temp_corr_Saemundson; float press_temp_corr_Saemundson;
//! Numerator of refraction formula, to be cached for speed. //! Numerator of refraction formula, to be cached for speed.
float press_temp_corr_Bennett; float press_temp_corr_Bennett;
//! These constants are usable for experiments with the limits of re
fraction effects.
static const double MIN_GEO_ALTITUDE_DEG;
static const double MIN_GEO_ALTITUDE_RAD;
static const double MIN_GEO_ALTITUDE_SIN;
static const double MIN_APP_ALTITUDE_DEG;
static const double MIN_APP_ALTITUDE_RAD;
static const double MIN_APP_ALTITUDE_SIN;
static const float MIN_GEO_ALTITUDE_DEG_F;
static const float MIN_GEO_ALTITUDE_RAD_F;
static const float MIN_GEO_ALTITUDE_SIN_F;
static const float MIN_APP_ALTITUDE_DEG_F;
static const float MIN_APP_ALTITUDE_RAD_F;
static const float MIN_APP_ALTITUDE_SIN_F;
static const double TRANSITION_WIDTH_GEO_DEG;
static const double TRANSITION_WIDTH_GEO_DEG_F;
static const double TRANSITION_WIDTH_APP_DEG;
static const double TRANSITION_WIDTH_APP_DEG_F;
//! Used to pretransform coordinates into AltAz frame. //! Used to pretransform coordinates into AltAz frame.
Mat4d preTransfoMat; Mat4d preTransfoMat;
Mat4d invertPreTransfoMat; Mat4d invertPreTransfoMat;
Mat4f preTransfoMatf; Mat4f preTransfoMatf;
Mat4f invertPreTransfoMatf; Mat4f invertPreTransfoMatf;
//! Used to postransform refracted coordinates from AltAz to view. //! Used to postransform refracted coordinates from AltAz to view.
Mat4d postTransfoMat; Mat4d postTransfoMat;
Mat4d invertPostTransfoMat; Mat4d invertPostTransfoMat;
Mat4f postTransfoMatf; Mat4f postTransfoMatf;
 End of changes. 17 change blocks. 
191 lines changed or deleted 62 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/