Skip to content

Commit

Permalink
labels fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaniy committed Jul 8, 2024
1 parent 7719c66 commit e203600
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion shaders/star_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ void main(void)
// in fragment shader all points have virtual dimension 1x1, so gl_PointCoord has a value from [0; 1]
float offset = length((gl_PointCoord.xy - vec2(0.5)) * pointSize);
float point = (max_theta == -1.0) ? psf_core(offset) : psf_glow(offset);
gl_FragColor = vec4(v_color * point, 1.0); // + vec4(0.1, 0.0, 0.0, 0.0); // square for debugging
gl_FragColor = vec4(v_color * point, 1.0); // + vec4(0.1, 0.0, 0.0, 0.0); // red square for debugging
}
13 changes: 6 additions & 7 deletions shaders/star_vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

const float a = 0.123; // empirical constant

const float degree_per_px = 0.01; // higher value causes blinking due to optimizations in the psf_glow()
const float max_square_size = 256.0; // px
const float max_irradiation = pow((degree_per_px * max_square_size / a), 2.0) / (2.0 * 3.141592653);
const float max_square_size = 512.0; // px
const float glow_scale = 0.123; // empirical constant, deg (not to change)
const float max_irradiation = pow((degree_per_px * max_square_size / glow_scale), 2.0) / (2.0 * 3.141592653);

varying vec3 v_color;
varying float max_theta;
Expand All @@ -25,7 +24,7 @@ attribute float in_PointSize;

const float color_saturation_limit = 0.1; // the ratio of the minimum color component to the maximum

//! Normalizes the color by its green value and corrects extreme saturation
// Normalizes the color by its green value and corrects extreme saturation
vec3 green_normalization(vec3 color)
{
// color /= max(color.r, max(color.g, color.b)); // we do this in XYZRGBConverter::convertUnnormalized()
Expand Down Expand Up @@ -54,8 +53,8 @@ void main(void)
else
{
// Bright light source (glow mode)
float irradiation = atan(in_PointSize / max_irradiation) * max_irradiation; // dimmed brightness
max_theta = 0.123 * sqrt(irradiation); // emperical glow radius
float irradiation = atan(in_PointSize / max_irradiation) * max_irradiation; // dimming
max_theta = glow_scale * sqrt(irradiation);
float half_sq = max_theta / degree_per_px;
pointSize = 2.0 * half_sq - 1.0;
v_color = color;
Expand Down
2 changes: 1 addition & 1 deletion src/celengine/dsorenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void DSORenderer::process(DeepSkyObject* const &dso,
float irradiationEff = astro::magToIrradiance(appMagEff) * exposure;
if (irradiationEff > labelLowestIrradiation)
{
float distr = irradiationEff / labelLowestIrradiation;
float distr = 1.0f - irradiationEff / labelLowestIrradiation;
labelColor.alpha(distr * labelColor.alpha());

renderer->addBackgroundAnnotation(rep,
Expand Down
2 changes: 1 addition & 1 deletion src/celengine/starrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void StarRenderer::process(const Star& star, float distance, float irradiance)
Vector3f starDir = relPos.normalized();
if (starDir.dot(viewNormal) > cosFOV)
{
float distr = labelLowestIrradiation / irradiation;
float distr = 1.0f - labelLowestIrradiation / irradiation;
Color color = Color(Renderer::StarLabelColor, distr * Renderer::StarLabelColor.alpha());
renderer->addBackgroundAnnotation(nullptr,
starDB->getStarName(star, true),
Expand Down

0 comments on commit e203600

Please sign in to comment.