StelSkyDrawer.cpp   StelSkyDrawer.cpp 
skipping to change at line 51 skipping to change at line 51
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelMovementMgr.hpp" #include "StelMovementMgr.hpp"
#include "StelPainter.hpp" #include "StelPainter.hpp"
#include <QStringList> #include <QStringList>
#include <QSettings> #include <QSettings>
#include <QDebug> #include <QDebug>
#include <QtGlobal> #include <QtGlobal>
// The 0.025 corresponds to the maximum eye resolution in degree // The 0.025 corresponds to the maximum eye resolution in degree
#define EYE_RESOLUTION (0.25) #define EYE_RESOLUTION (0.25f)
#define MAX_LINEAR_RADIUS 8.f #define MAX_LINEAR_RADIUS 8.f
StelSkyDrawer::StelSkyDrawer(StelCore* acore) : core(acore), starsShaderPro gram(NULL) StelSkyDrawer::StelSkyDrawer(StelCore* acore) : core(acore), flagHasAtmosph ere(true), starsShaderProgram(NULL)
{ {
eye = core->getToneReproducer(); eye = core->getToneReproducer();
inScale = 1.; inScale = 1.f;
bortleScaleIndex = 3; bortleScaleIndex = 3;
limitMagnitude = -100.f; limitMagnitude = -100.f;
limitLuminance = 0; limitLuminance = 0;
oldLum=-1.f; oldLum=-1.f;
maxLum = 0.f; maxLum = 0.f;
setMaxAdaptFov(180.f); setMaxAdaptFov(180.f);
setMinAdaptFov(0.1f); setMinAdaptFov(0.1f);
starAbsoluteScaleF = 1.f; starAbsoluteScaleF = 1.f;
starRelativeScale = 1.f; starRelativeScale = 1.f;
starLinearScale = 19.569f; starLinearScale = 19.569f;
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
initColorTableFromConfigFile(conf); initColorTableFromConfigFile(conf);
setTwinkleAmount(conf->value("stars/star_twinkle_amount",0.3).toDoub le()); setTwinkleAmount(conf->value("stars/star_twinkle_amount",0.3).toFloa t());
setFlagTwinkle(conf->value("stars/flag_star_twinkle",true).toBool()) ; setFlagTwinkle(conf->value("stars/flag_star_twinkle",true).toBool()) ;
setFlagPointStar(conf->value("stars/flag_point_star",false).toBool() ); setFlagPointStar(conf->value("stars/flag_point_star",false).toBool() );
setMaxAdaptFov(conf->value("stars/mag_converter_max_fov",70.0).toDou setMaxAdaptFov(conf->value("stars/mag_converter_max_fov",70.0).toFlo
ble()); at());
setMinAdaptFov(conf->value("stars/mag_converter_min_fov",0.1).toDoub setMinAdaptFov(conf->value("stars/mag_converter_min_fov",0.1).toFloa
le()); t());
setFlagLuminanceAdaptation(conf->value("viewing/use_luminance_adapta tion",true).toBool()); setFlagLuminanceAdaptation(conf->value("viewing/use_luminance_adapta tion",true).toBool());
bool ok=true; bool ok=true;
setBortleScale(conf->value("stars/init_bortle_scale",3).toInt(&ok)); setBortleScale(conf->value("stars/init_bortle_scale",3).toInt(&ok));
if (!ok) if (!ok)
{ {
conf->setValue("stars/init_bortle_scale",3); conf->setValue("stars/init_bortle_scale",3);
setBortleScale(3); setBortleScale(3);
ok = true; ok = true;
} }
setRelativeStarScale(conf->value("stars/relative_scale",1.0).toDoubl e(&ok)); setRelativeStarScale(conf->value("stars/relative_scale",1.0).toFloat (&ok));
if (!ok) if (!ok)
{ {
conf->setValue("stars/relative_scale",1.0); conf->setValue("stars/relative_scale",1.0);
setRelativeStarScale(1.0); setRelativeStarScale(1.0);
ok = true; ok = true;
} }
setAbsoluteStarScale(conf->value("stars/absolute_scale",1.0).toDoubl e(&ok)); setAbsoluteStarScale(conf->value("stars/absolute_scale",1.0).toFloat (&ok));
if (!ok) if (!ok)
{ {
conf->setValue("stars/absolute_scale",1.0); conf->setValue("stars/absolute_scale",1.0);
setAbsoluteStarScale(1.0); setAbsoluteStarScale(1.0);
ok = true; ok = true;
} }
// Initialize buffers for use by gl vertex array // Initialize buffers for use by gl vertex array
nbPointSources = 0; nbPointSources = 0;
maxPointSources = 1000; maxPointSources = 1000;
skipping to change at line 145 skipping to change at line 145
if (useShader) if (useShader)
{ {
delete starsShaderProgram; delete starsShaderProgram;
} }
} }
// Init parameters from config file // Init parameters from config file
void StelSkyDrawer::init() void StelSkyDrawer::init()
{ {
StelApp::makeMainGLContextCurrent(); StelPainter::makeMainGLContextCurrent();
// Load star texture no mipmap: // Load star texture no mipmap:
texHalo = StelApp::getInstance().getTextureManager().createTexture(" texHalo = StelApp::getInstance().getTextureManager().createTexture("
star16x16.png"); textures/star16x16.png");
texBigHalo = StelApp::getInstance().getTextureManager().createTextur texBigHalo = StelApp::getInstance().getTextureManager().createTextur
e("haloLune.png"); e("textures/haloLune.png");
texSunHalo = StelApp::getInstance().getTextureManager().createTextur texSunHalo = StelApp::getInstance().getTextureManager().createTextur
e("halo.png"); e("textures/halo.png");
useShader = StelApp::getInstance().getUseGLShaders() && (QGLFormat:: openGLVersionFlags().testFlag(QGLFormat::OpenGL_Version_2_1) || QGLFormat:: openGLVersionFlags().testFlag(QGLFormat::OpenGL_ES_Version_2_0)); useShader = StelApp::getInstance().getUseGLShaders();
if (useShader) if (useShader)
{ {
qDebug() << "Use vertex shader for stars rendering"; qDebug() << "Use vertex shader for stars rendering";
QGLShader* vShader = new QGLShader(QGLShader::Vertex); QGLShader* vShader = new QGLShader(QGLShader::Vertex);
vShader->compileSourceCode( vShader->compileSourceCode(
"uniform mediump mat4 projec tionMatrix;\n" "uniform mediump mat4 projec tionMatrix;\n"
"attribute mediump vec2 skyV ertex;\n" "attribute mediump vec2 skyV ertex;\n"
"attribute mediump vec3 star Color;\n" "attribute mediump vec3 star Color;\n"
"attribute mediump vec2 star Size;\n" "attribute mediump vec2 star Size;\n"
"varying mediump vec4 outCol or;\n" "varying mediump vec4 outCol or;\n"
skipping to change at line 207 skipping to change at line 207
if (!starsShaderProgram->log().isEmpty()) if (!starsShaderProgram->log().isEmpty())
{ {
qWarning() << "Warnings while linking shader: " << s tarsShaderProgram->log(); qWarning() << "Warnings while linking shader: " << s tarsShaderProgram->log();
} }
maxPointSources*=6; maxPointSources*=6;
} }
update(0); update(0);
} }
void StelSkyDrawer::update(double deltaTime) void StelSkyDrawer::update(double)
{ {
float fov = core->getMovementMgr()->getCurrentFov(); float fov = core->getMovementMgr()->getCurrentFov();
if (fov > maxAdaptFov) if (fov > maxAdaptFov)
{ {
fov = maxAdaptFov; fov = maxAdaptFov;
} }
else else
{ {
if (fov < minAdaptFov) if (fov < minAdaptFov)
fov = minAdaptFov; fov = minAdaptFov;
} }
// This factor is fully arbitrary. It corresponds to the collecting area x exposure time of the instrument // This factor is fully arbitrary. It corresponds to the collecting area x exposure time of the instrument
// It is based on a power law, so that it varies progressively with the FOV to smoothly switch from human // It is based on a power law, so that it varies progressively with the FOV to smoothly switch from human
// vision to binocculares/telescope. Use a max of 0.7 because after that the atmosphere starts to glow too much! // vision to binocculares/telescope. Use a max of 0.7 because after that the atmosphere starts to glow too much!
float powFactor = std::pow(60./qMax(0.7f,fov), 0.8); float powFactor = std::pow(60.f/qMax(0.7f,fov), 0.8f);
eye->setInputScale(inScale*powFactor); eye->setInputScale(inScale*powFactor);
// Set the fov factor for point source luminance computation // Set the fov factor for point source luminance computation
// the division by powFactor should in principle not be here, but it doesn't look nice if removed // the division by powFactor should in principle not be here, but it doesn't look nice if removed
lnfovFactor = std::log(1./50.*2025000.f* 60.f*60.f / (fov*fov) / (EY E_RESOLUTION*EYE_RESOLUTION)/powFactor/1.4); lnfovFactor = std::log(1.f/50.f*2025000.f* 60.f*60.f / (fov*fov) / ( EYE_RESOLUTION*EYE_RESOLUTION)/powFactor/1.4f);
// Precompute // Precompute
starLinearScale = std::pow(35.f*2.0f*starAbsoluteScaleF, 1.40f/2.f*s tarRelativeScale); starLinearScale = std::pow(35.f*2.0f*starAbsoluteScaleF, 1.40f/2.f*s tarRelativeScale);
// update limit mag // update limit mag
limitMagnitude = computeLimitMagnitude(); limitMagnitude = computeLimitMagnitude();
// update limit luminance // update limit luminance
limitLuminance = computeLimitLuminance(); limitLuminance = computeLimitLuminance();
} }
skipping to change at line 452 skipping to change at line 452
glDrawArrays(GL_TRIANGLES, 0, nbPointSources*6); glDrawArrays(GL_TRIANGLES, 0, nbPointSources*6);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#endif #endif
} }
nbPointSources = 0; nbPointSources = 0;
} }
static Vec3d win; static Vec3f win;
// Draw a point source halo. // Draw a point source halo.
bool StelSkyDrawer::drawPointSource(StelPainter* sPainter, const Vec3d& v, const float rcMag[2], const Vec3f& color, bool checkInScreen) bool StelSkyDrawer::drawPointSource(StelPainter* sPainter, const Vec3f& v, const float rcMag[2], const Vec3f& color, bool checkInScreen)
{ {
Q_ASSERT(sPainter); Q_ASSERT(sPainter);
if (rcMag[0]<=0.f) if (rcMag[0]<=0.f)
return false; return false;
if (!(checkInScreen ? sPainter->getProjector()->projectCheck(v, win) : sPainter->getProjector()->project(v, win))) if (!(checkInScreen ? sPainter->getProjector()->projectCheck(v, win) : sPainter->getProjector()->project(v, win)))
return false; return false;
const double radius = rcMag[0]; const float radius = rcMag[0];
// Random coef for star twinkling // Random coef for star twinkling
const float tw = flagStarTwinkle ? (1.f-twinkleAmount*rand()/RAND_MA X)*rcMag[1] : 1.f*rcMag[1]; const float tw = (flagStarTwinkle && flagHasAtmosphere) ? (1.f-twink leAmount*rand()/RAND_MAX)*rcMag[1] : rcMag[1];
// If the rmag is big, draw a big halo // If the rmag is big, draw a big halo
if (radius>MAX_LINEAR_RADIUS+5.f) if (radius>MAX_LINEAR_RADIUS+5.f)
{ {
float cmag = qMin(rcMag[1],(float)(radius-(MAX_LINEAR_RADIUS +5.))/30.f); float cmag = qMin(rcMag[1],(float)(radius-(MAX_LINEAR_RADIUS +5.f))/30.f);
float rmag = 150.f; float rmag = 150.f;
if (cmag>1.f) if (cmag>1.f)
cmag = 1.f; cmag = 1.f;
texBigHalo->bind(); texBigHalo->bind();
sPainter->enableTexture2d(true); sPainter->enableTexture2d(true);
glBlendFunc(GL_ONE, GL_ONE); glBlendFunc(GL_ONE, GL_ONE);
glEnable(GL_BLEND); glEnable(GL_BLEND);
sPainter->setColor(color[0]*cmag, color[1]*cmag, color[2]*cm ag); sPainter->setColor(color[0]*cmag, color[1]*cmag, color[2]*cm ag);
sPainter->drawSprite2dMode(win[0], win[1], rmag); sPainter->drawSprite2dMode(win[0], win[1], rmag);
} }
#ifndef USE_OPENGL_ES2
if (useShader) if (useShader)
{ {
#endif
// Use point based rendering // Use point based rendering
verticesGrid[nbPointSources].set(win[0], win[1]); verticesGrid[nbPointSources].set(win[0], win[1]);
colorGrid[nbPointSources]=color; colorGrid[nbPointSources].set(color[0]*tw, color[1]*tw, colo
colorGrid[nbPointSources]*=tw; r[2]*tw);
textureGrid[nbPointSources][0]=radius; textureGrid[nbPointSources][0]=radius;
#ifndef USE_OPENGL_ES2
} }
else else
{ {
if (flagPointStar) if (flagPointStar)
{ {
// Draw the star rendered as GLpoint. This may be fa ster but it is not so nice // Draw the star rendered as GLpoint. This may be fa ster but it is not so nice
sPainter->setColor(color[0]*tw, color[1]*tw, color[2 ]*tw); sPainter->setColor(color[0]*tw, color[1]*tw, color[2 ]*tw);
sPainter->drawPoint2d(win[0], win[1]); sPainter->drawPoint2d(win[0], win[1]);
} }
else else
skipping to change at line 522 skipping to change at line 524
win*=tw; win*=tw;
Vec3f* cv = &(colorGrid[nbPointSources*6]); Vec3f* cv = &(colorGrid[nbPointSources*6]);
*cv = win; ++cv; *cv = win; ++cv;
*cv = win; ++cv; *cv = win; ++cv;
*cv = win; ++cv; *cv = win; ++cv;
*cv = win; ++cv; *cv = win; ++cv;
*cv = win; ++cv; *cv = win; ++cv;
*cv = win; ++cv; *cv = win; ++cv;
} }
} }
#endif
++nbPointSources; ++nbPointSources;
if (nbPointSources>=maxPointSources) if (nbPointSources>=maxPointSources)
{ {
// Flush the buffer (draw all buffered stars) // Flush the buffer (draw all buffered stars)
postDrawPointSource(sPainter); postDrawPointSource(sPainter);
} }
return true; return true;
} }
// Terminate drawing of a 3D model, draw the halo // Terminate drawing of a 3D model, draw the halo
void StelSkyDrawer::postDrawSky3dModel(StelPainter* painter, const Vec3d& v , double illuminatedArea, float mag, const Vec3f& color) void StelSkyDrawer::postDrawSky3dModel(StelPainter* painter, const Vec3f& v , float illuminatedArea, float mag, const Vec3f& color)
{ {
const float pixPerRad = painter->getProjector()->getPixelPerRadAtCen ter(); const float pixPerRad = painter->getProjector()->getPixelPerRadAtCen ter();
// Assume a disk shape // Assume a disk shape
float pixRadius = std::sqrt(illuminatedArea/(60.*60.)*M_PI/180.*M_PI /180.*(pixPerRad*pixPerRad))/M_PI; float pixRadius = std::sqrt(illuminatedArea/(60.*60.)*M_PI/180.*M_PI /180.*(pixPerRad*pixPerRad))/M_PI;
bool noStarHalo = false; bool noStarHalo = false;
if (mag<-15.f) if (mag<-15.f)
{ {
// Sun, halo size varies in function of the magnitude becaus e sun as seen from pluto should look dimmer // Sun, halo size varies in function of the magnitude becaus e sun as seen from pluto should look dimmer
skipping to change at line 596 skipping to change at line 599
if (pixRadius>tStart && pixRadius<tStop) if (pixRadius>tStart && pixRadius<tStop)
{ {
rcm[1]=(tStop-pixRadius)/(tStop-tStart); rcm[1]=(tStop-pixRadius)/(tStop-tStart);
} }
if (truncated && flagLuminanceAdaptation) if (truncated && flagLuminanceAdaptation)
{ {
float wl = findWorldLumForMag(mag, rcm[0]); float wl = findWorldLumForMag(mag, rcm[0]);
if (wl>0) if (wl>0)
{ {
const double f = core->getMovementMgr()->getCurrentF const float f = core->getMovementMgr()->getCurrentFo
ov(); v();
reportLuminanceInFov(qMin(700., qMin((double)wl/50, reportLuminanceInFov(qMin(700.f, qMin(wl/50, (60.f*6
(60.*60.)/(f*f)*6.))); 0.f)/(f*f)*6.f)));
} }
} }
if (!noStarHalo) if (!noStarHalo)
{ {
preDrawPointSource(painter); preDrawPointSource(painter);
drawPointSource(painter, v,rcm,color); drawPointSource(painter, v,rcm,color);
postDrawPointSource(painter); postDrawPointSource(painter);
} }
flagStarTwinkle=save; flagStarTwinkle=save;
skipping to change at line 658 skipping to change at line 661
break; break;
} }
} }
eye->setWorldAdaptationLuminance(saveLum); // restore eye->setWorldAdaptationLuminance(saveLum); // restore
return curLum; return curLum;
} }
// Report that an object of luminance lum is currently displayed // Report that an object of luminance lum is currently displayed
void StelSkyDrawer::reportLuminanceInFov(double lum, bool fastAdaptation) void StelSkyDrawer::reportLuminanceInFov(float lum, bool fastAdaptation)
{ {
if (lum > maxLum) if (lum > maxLum)
{ {
if (oldLum<0) if (oldLum<0)
oldLum=lum; oldLum=lum;
// Use a log law for smooth transitions // Use a log law for smooth transitions
if (fastAdaptation==true && lum>oldLum) if (fastAdaptation==true && lum>oldLum)
{ {
maxLum = lum; maxLum = lum;
} }
skipping to change at line 841 skipping to change at line 844
Vec3f(1.000000,0.774609,0.624412), Vec3f(1.000000,0.774609,0.624412),
Vec3f(1.000000,0.774315,0.627647), Vec3f(1.000000,0.774315,0.627647),
Vec3f(1.000000,0.774020,0.630883), Vec3f(1.000000,0.774020,0.630883),
Vec3f(1.000000,0.773726,0.634118), Vec3f(1.000000,0.773726,0.634118),
Vec3f(1.000000,0.773432,0.637353), Vec3f(1.000000,0.773432,0.637353),
Vec3f(1.000000,0.773138,0.640588), Vec3f(1.000000,0.773138,0.640588),
Vec3f(1.000000,0.772843,0.643824), Vec3f(1.000000,0.772843,0.643824),
Vec3f(1.000000,0.772549,0.647059), Vec3f(1.000000,0.772549,0.647059),
}; };
static double Gamma(double gamma,double x) static float Gamma(float gamma, float x)
{ {
return ((x<=0.0) ? 0.0 : exp(gamma*log(x))); return ((x<=0.f) ? 0.f : std::exp(gamma*std::log(x)));
} }
static Vec3f Gamma(double gamma,const Vec3f &x) static Vec3f Gamma(float gamma,const Vec3f &x)
{ {
return Vec3f(Gamma(gamma,x[0]),Gamma(gamma,x[1]),Gamma(gamma,x[2])); return Vec3f(Gamma(gamma,x[0]),Gamma(gamma,x[1]),Gamma(gamma,x[2]));
} }
// Load B-V conversion parameters from config file // Load B-V conversion parameters from config file
void StelSkyDrawer::initColorTableFromConfigFile(QSettings* conf) void StelSkyDrawer::initColorTableFromConfigFile(QSettings* conf)
{ {
std::map<float,Vec3f> color_map; std::map<float,Vec3f> color_map;
for (float bV=-0.5f;bV<=4.0f;bV+=0.01) for (float bV=-0.5f;bV<=4.0f;bV+=0.01)
{ {
 End of changes. 29 change blocks. 
37 lines changed or deleted 41 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/