I am using XHIP database package (extended Hipparcos compilation) - http://cdsarc.u-strasbg.fr/viz-bin/cat/V/137D
I extracted some fields from them like RA, DEC, PLX and CI (color index) and converted RA, DEC and PLX to XYZ coordination in parsec units. Also I have HYG database (http://www.astronexus.com/hyg) as well. Both are designed for 3D starmap coordinates. Many astronomy/space simulators software (Celestia, Orbiter, Space Engine and Gaia Sky) use that in KM units or so. I now have Gaia DR2 database but not implemented yet.
I plan to render millions stars (particles) through GPU processor. Origin is our solar system (Sol system). However I am still using my old routines to render stars below. For new routine, I plan to write shader program to calculate apparent magnitude depending on camera position for brightness and star size (much faster than using CPU space). I calculate star position relative to eye coordination for both star and constellation lines in double precision. Then convert to 32-bit floats for rendering.
I first implemented that routines with legacy OpenGL function calls and they worked fine by displaying stars and constellation lines with earth rendering but can't display varying-size points so that I have to use shader program to display varying-size points.
StarVertex::StarVertex(Scene &scene, int maxStars)
: scene(scene),
ctx(*scene.getContext()),
prm(*scene.getParameter()),
type(useNotUsed),
maxStars(maxStars),
nStars(0), cStars(0),
flagStarted(false)
{
buffer = new starVertex[maxStars];
}
StarVertex::~StarVertex()
{
finish();
if (buffer != nullptr)
delete []buffer;
}
void StarVertex::startSprites()
{
if (pgm == nullptr) {
ShaderManager &smgr = scene.getShaderManager();
pgm = smgr.createShader("star");
vbuf = new VertexBuffer(ctx, 1);
vbuf->createBuffer(VertexBuffer::VBO, 1);
}
pgm->use();
vbuf->bind();
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(starVertex), (void *)0);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(starVertex), (void *)(3 * sizeof(float)));
glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, sizeof(starVertex), (void *)(7 * sizeof(float)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
// cout << "starVertex size: " << sizeof(starVertex) << endl;
// cout << " vec3f_t size: " << sizeof(vec3f_t) << endl;
// cout << " Color size: " << sizeof(Color) << endl;
glEnable(GL_PROGRAM_POINT_SIZE);
mat4f_t mvp = mat4f_t (prm.dmProj * prm.dmView * mat4d_t(1.0));
uint32_t mvpLoc = glGetUniformLocation(pgm->getID(), "mvp");
glUniformMatrix4fv(mvpLoc, 1, GL_FALSE, glm::value_ptr(mvp));
nStars = 0;
cStars = 0;
type = useSprites;
flagStarted = true;
}
void StarVertex::render()
{
if (nStars == 0)
return;
vbuf->assign(VertexBuffer::VBO, buffer, nStars*sizeof(starVertex));
// Now rendering stars
// if (txImage != nullptr)
// txImage->bind();
glDrawArrays(GL_POINTS, 0, nStars);
cStars += nStars;
nStars = 0;
}
void StarVertex::finish()
{
render();
flagStarted = false;
// cout << "Total " << cStars << " rendered stars." << endl;
cStars = 0;
switch (type) {
case useSprites:
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
vbuf->unbind();
glUseProgram(0);
glDisable(GL_PROGRAM_POINT_SIZE);
break;
case usePoints:
default:
break;
}
type = useNotUsed;
}
void StarVertex::addStar(const vec3d_t &pos, const Color &color, double size)
{
if (nStars == maxStars)
render();
buffer[nStars].posStar = pos;
buffer[nStars].color = color;
buffer[nStars].size = size;
nStars++;
}
// ****************************************************************
void StarRenderer::process(const CelestialStar& star, double dist, double appMag) const
{
vec3d_t spos, rpos;
double srad;
double rdist;
double objSize;
double discSize;
double discScale;
double alpha, ptSize;
Color color;
// Calculate relative position between star and camera positions.
spos = star.getPosition(0) * KM_PER_PC;
rpos = spos - cpos;
rdist = glm::length(rpos);
// Calculate apparent size of star in view field
srad = star.getRadius();
// objSize = (srad / (dist * KM_PER_PC)) / pxSize;
objSize = srad / (dist * pxSize * KM_PER_PC);
alpha = faintestMag - appMag;
discSize = baseSize;
if (alpha > 1.0) {
discScale = min(pow(2.0, 0.3 * (saturationMag - appMag)), 100.0);
discSize *= discScale;
alpha = 1.0;
} else if (alpha < 0.0)
alpha = 0.0;
color = starColors->lookup(star.getTemperature());
color.setAlpha(alpha);
// Finally, now display star
starBuffer->addStar(rpos, color, discSize);
}