MilkyWay.cpp   MilkyWay.cpp 
/* /*
* Stellarium * Stellarium
* Copyright (C) 2002 Fabien Chereau * Copyright (C) 2002 Fabien Chereau
* Copyright (C) 2014 Georg Zotti (extinction parts)
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 61 skipping to change at line 62
delete vertexArray; delete vertexArray;
vertexArray = NULL; vertexArray = NULL;
} }
void MilkyWay::init() void MilkyWay::init()
{ {
QSettings* conf = StelApp::getInstance().getSettings(); QSettings* conf = StelApp::getInstance().getSettings();
Q_ASSERT(conf); Q_ASSERT(conf);
tex = StelApp::getInstance().getTextureManager().createTexture(StelF ileMgr::getInstallationDir()+"/textures/milkyway.png"); tex = StelApp::getInstance().getTextureManager().createTexture(StelF ileMgr::getInstallationDir()+"/textures/milkyway_2048.png");
setFlagShow(conf->value("astro/flag_milky_way").toBool()); setFlagShow(conf->value("astro/flag_milky_way").toBool());
setIntensity(conf->value("astro/milky_way_intensity",1.f).toFloat()) ; setIntensity(conf->value("astro/milky_way_intensity",1.f).toFloat()) ;
vertexArray = new StelVertexArray(StelPainter::computeSphereNoLight( // A new texture was provided by Fabien. Better resolution, but in e
1.f,1.f,20,20,1)); quatorial coordinates. I had to enhance it a bit, and shift it by 90 degree
s.
vertexArray = new StelVertexArray(StelPainter::computeSphereNoLight(
1.f,1.f,45,15,1, true)); // GZ orig: slices=stacks=20.
vertexArray->colors.resize(vertexArray->vertex.length());
vertexArray->colors.fill(Vec3f(1.0, 0.3, 0.9));
} }
void MilkyWay::update(double deltaTime) {fader->update((int)(deltaTime*1000 void MilkyWay::update(double deltaTime)
));} {
fader->update((int)(deltaTime*1000));
}
void MilkyWay::setFlagShow(bool b){*fader = b;} void MilkyWay::setFlagShow(bool b){*fader = b;}
bool MilkyWay::getFlagShow() const {return *fader;} bool MilkyWay::getFlagShow() const {return *fader;}
void MilkyWay::draw(StelCore* core) void MilkyWay::draw(StelCore* core)
{ {
if (!getFlagShow()) if (!getFlagShow())
return; return;
StelProjector::ModelViewTranformP transfo = core->getJ2000ModelViewT ransform(); StelProjector::ModelViewTranformP transfo = core->getJ2000ModelViewT ransform();
transfo->combine(Mat4d::xrotation(M_PI/180.*23.)*
Mat4d::yrotation(M_PI/180.*120.)*
Mat4d::zrotation(M_PI/180.*7.));
const StelProjectorP prj = core->getProjection(transfo); const StelProjectorP prj = core->getProjection(transfo); // GZ: Mayb e this can now be simplified?
StelToneReproducer* eye = core->getToneReproducer(); StelToneReproducer* eye = core->getToneReproducer();
Q_ASSERT(tex); // A texture must be loaded before calling this Q_ASSERT(tex); // A texture must be loaded before calling this
// This RGB color corresponds to the night blue scotopic color = 0.2 5, 0.25 in xyY mode. // This RGB color corresponds to the night blue scotopic color = 0.2 5, 0.25 in xyY mode.
// since milky way is always seen white RGB value in the texture (1. 0,1.0,1.0) // since milky way is always seen white RGB value in the texture (1. 0,1.0,1.0)
Vec3f c = Vec3f(0.34165f, 0.429666f, 0.63586f); // Vec3f c = Vec3f(0.34165f, 0.429666f, 0.63586f);
// This is the same color, just brighter to have Blue=1.
//Vec3f c = Vec3f(0.53730381f, .675724216f, 1.0f);
// The new texture (V0.13.1) is quite blue to start with. It is bett
er to apply white color for it.
Vec3f c = Vec3f(1.0f, 1.0f, 1.0f);
float lum = core->getSkyDrawer()->surfacebrightnessToLuminance(13.5f ); float lum = core->getSkyDrawer()->surfacebrightnessToLuminance(11.5f ); // Source? How to calibrate the new texture?
// Get the luminance scaled between 0 and 1 // Get the luminance scaled between 0 and 1
float aLum =eye->adaptLuminanceScaled(lum*fader->getInterstate()); float aLum =eye->adaptLuminanceScaled(lum*fader->getInterstate());
// Bound a maximum luminance // Bound a maximum luminance. GZ: Is there any reference/reason, or just trial and error?
aLum = qMin(0.38f, aLum*2.f); aLum = qMin(0.38f, aLum*2.f);
// We must also adjust milky way to light pollution.
// Is there any way to calibrate this?
int bortle=core->getSkyDrawer()->getBortleScaleIndex();
aLum*=(11.0f-bortle)*0.1f;
// intensity of 1.0 is "proper", but allow boost for dim screens // intensity of 1.0 is "proper", but allow boost for dim screens
c*=aLum*intensity; c*=aLum*intensity;
if (c[0]<0) c[0]=0; if (c[0]<0) c[0]=0;
if (c[1]<0) c[1]=0; if (c[1]<0) c[1]=0;
if (c[2]<0) c[2]=0; if (c[2]<0) c[2]=0;
const bool withExtinction=(core->getSkyDrawer()->getFlagHasAtmospher
e() && core->getSkyDrawer()->getExtinction().getExtinctionCoefficient()>=0.
01f);
if (withExtinction)
{
// We must process the vertices to find geometric altitudes
in order to compute vertex colors.
// Note that there is a visible boost of extinction for high
er Bortle indices. I must reflect that as well.
Extinction extinction=core->getSkyDrawer()->getExtinction();
vertexArray->colors.clear();
for (int i=0; i<vertexArray->vertex.size(); ++i)
{
Vec3d vertAltAz=core->j2000ToAltAz(vertexArray->vert
ex.at(i), StelCore::RefractionOn);
Q_ASSERT(fabs(vertAltAz.lengthSquared()-1.0) < 0.001
);
float oneMag=0.0f;
extinction.forward(vertAltAz, &oneMag);
float extinctionFactor=std::pow(0.4f , oneMag) * (1.
1f-bortle*0.1f); // drop of one magnitude: factor 2.5 or 40%
Vec3f thisColor=Vec3f(c[0]*extinctionFactor, c[1]*ex
tinctionFactor, c[2]*extinctionFactor);
vertexArray->colors.append(thisColor);
}
}
else
vertexArray->colors.fill(Vec3f(c[0], c[1], c[2]));
StelPainter sPainter(prj); StelPainter sPainter(prj);
sPainter.setColor(c[0],c[1],c[2]);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
sPainter.enableTexture2d(true); sPainter.enableTexture2d(true);
glDisable(GL_BLEND); glDisable(GL_BLEND);
tex->bind(); tex->bind();
sPainter.drawStelVertexArray(*vertexArray); sPainter.drawStelVertexArray(*vertexArray);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
} }
 End of changes. 12 change blocks. 
13 lines changed or deleted 59 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/