new-stars-v2
Hleb Valoshka 2021-03-13 18:40:12 +02:00
parent 1748e3466b
commit c5f40088d1
5 changed files with 20 additions and 10 deletions

View File

@ -10,8 +10,8 @@ varying highp float brightness;
/*uniform*/ const float sigma2 = 0.35; /*uniform*/ const float sigma2 = 0.35;
/*uniform highp*/ const float glareFalloff = 1.0 / 15.0; /*uniform highp*/ const float glareFalloff = 1.0 / 15.0;
/*uniform highp*/ const float glareBrightness = 0.003; /*uniform highp*/ const float glareBrightness = 0.003;
/*uniform*/ const float diffSpikeBrightness = 0.3; /*uniform*/ const float diffSpikeBrightness = 0.9;
/*uniform*/ const float exposure = 21.72534925735687; uniform /*const*/ float exposure/* = 21.72534925735687|74.430977*/;
mediump vec3 linearToSRGB(mediump vec3 c) mediump vec3 linearToSRGB(mediump vec3 c)
{ {
@ -31,5 +31,5 @@ void main()
float spikes = (max(0.0, 1.0 - abs(offset.x + offset.y)) + max(0.0, 1.0 - abs(offset.x - offset.y))) * diffSpikeBrightness; float spikes = (max(0.0, 1.0 - abs(offset.x + offset.y)) + max(0.0, 1.0 - abs(offset.x - offset.y))) * diffSpikeBrightness;
b += glareBrightness / (glareFalloff * pow(r2, 1.5) + 1.0) * (spikes + 0.5); b += glareBrightness / (glareFalloff * pow(r2, 1.5) + 1.0) * (spikes + 0.5);
#endif #endif
gl_FragColor = vec4(linearToSRGB(b * exposure * color.rgb * brightness), 1.0); gl_FragColor = vec4(linearToSRGB(b * exposure * color.rgb * brightness * 5.0), 1.0);
} }

View File

@ -11,12 +11,12 @@ attribute vec4 in_Color;
uniform vec2 viewportSize; uniform vec2 viewportSize;
uniform vec2 viewportCoord; uniform vec2 viewportCoord;
/*uniform*/ const float magScale = 1.3369011415551906; uniform /*const*/ float magScale/* = 1.3369011415551906*/;
/*uniform*/ const float sigma2 = 0.35; /*uniform*/ const float sigma2 = 0.35;
/*uniform highp*/ const float glareFalloff = 1.0 / 15.0; /*uniform highp*/ const float glareFalloff = 1.0 / 15.0;
/*uniform highp*/ const float glareBrightness = 0.003; /*uniform highp*/ const float glareBrightness = 0.003;
/*uniform*/ const float exposure = 21.72534925735687; uniform /*const*/ float exposure /*= 21.72534925735687|74.430977*/;
/*uniform*/ const float thresholdBrightness = 1.0 / 255.0; uniform /*const*/ float thresholdBrightness/* = 1.0 / 255.0*/;
varying vec2 pointCenter; varying vec2 pointCenter;
varying vec4 color; varying vec4 color;

View File

@ -31,10 +31,11 @@ PointStarVertexBuffer::~PointStarVertexBuffer()
delete[] vertices; delete[] vertices;
} }
void PointStarVertexBuffer::startSprites() void PointStarVertexBuffer::startSprites(float _limitingMagnitude)
{ {
program = renderer.getShaderManager().getShader("star_new"); program = renderer.getShaderManager().getShader("star_new");
pointSizeFromVertex = true; pointSizeFromVertex = true;
limitingMagnitude = _limitingMagnitude;
} }
void PointStarVertexBuffer::startBasicPoints() void PointStarVertexBuffer::startBasicPoints()
@ -82,6 +83,14 @@ void PointStarVertexBuffer::makeCurrent()
renderer.getViewport(viewport); renderer.getViewport(viewport);
program->vec2Param("viewportSize") = Eigen::Vector2f(viewport[2], viewport[3]); program->vec2Param("viewportSize") = Eigen::Vector2f(viewport[2], viewport[3]);
program->vec2Param("viewportCoord") = Eigen::Vector2f(viewport[0], viewport[1]); program->vec2Param("viewportCoord") = Eigen::Vector2f(viewport[0], viewport[1]);
float visibilityThreshold = 1.0f / 255.0f;
float logMVisThreshold = log(visibilityThreshold) / log(2.512f);
float saturationMag = limitingMagnitude - 4.5f; //+ logMVisThreshold;
float magScale = (logMVisThreshold) / (saturationMag - limitingMagnitude);
program->floatParam("thresholdBrightness") = visibilityThreshold;
program->floatParam("exposure") = pow(2.512f, magScale * saturationMag);
program->floatParam("magScale") = magScale;
if (pointSizeFromVertex) if (pointSizeFromVertex)
{ {
program->samplerParam("starTex") = 0; program->samplerParam("starTex") = 0;

View File

@ -32,7 +32,7 @@ public:
PointStarVertexBuffer& operator=(PointStarVertexBuffer&&) = delete; PointStarVertexBuffer& operator=(PointStarVertexBuffer&&) = delete;
void startBasicPoints(); void startBasicPoints();
void startSprites(); void startSprites(float);
void render(); void render();
void finish(); void finish();
inline void addStar(const Eigen::Vector3f& pos, const Color&, float); inline void addStar(const Eigen::Vector3f& pos, const Color&, float);
@ -59,6 +59,7 @@ private:
Texture* texture { nullptr }; Texture* texture { nullptr };
bool pointSizeFromVertex { false }; bool pointSizeFromVertex { false };
float pointScale { 1.0f }; float pointScale { 1.0f };
float limitingMagnitude { 7.0f };
CelestiaGLProgram* program { nullptr }; CelestiaGLProgram* program { nullptr };
static PointStarVertexBuffer* current; static PointStarVertexBuffer* current;

View File

@ -4649,11 +4649,11 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
starRenderer.glareVertexBuffer->setPointScale(screenDpi / 96.0f); starRenderer.glareVertexBuffer->setPointScale(screenDpi / 96.0f);
PointStarVertexBuffer::enable(); PointStarVertexBuffer::enable();
starRenderer.glareVertexBuffer->startSprites(); starRenderer.glareVertexBuffer->startSprites(faintestMag);
if (starStyle == PointStars) if (starStyle == PointStars)
starRenderer.starVertexBuffer->startBasicPoints(); starRenderer.starVertexBuffer->startBasicPoints();
else else
starRenderer.starVertexBuffer->startSprites(); starRenderer.starVertexBuffer->startSprites(faintestMag);
#ifdef OCTREE_DEBUG #ifdef OCTREE_DEBUG
m_starProcStats.nodes = 0; m_starProcStats.nodes = 0;