Compare commits
5 Commits
spacecruft
...
new-stars-
Author | SHA1 | Date |
---|---|---|
Hleb Valoshka | edbc16417d | |
Hleb Valoshka | 3a9a19ca52 | |
Hleb Valoshka | c5f40088d1 | |
Hleb Valoshka | 1748e3466b | |
Hleb Valoshka | 74bbe9fd1c |
|
@ -0,0 +1,35 @@
|
|||
#ifndef GL_ES
|
||||
#define highp
|
||||
#define mediump
|
||||
#define lowp
|
||||
#endif
|
||||
|
||||
varying lowp vec4 color;
|
||||
varying highp vec2 pointCenter;
|
||||
varying highp float brightness;
|
||||
/*uniform*/ const float sigma2 = 0.35;
|
||||
/*uniform highp*/ const float glareFalloff = 1.0 / 15.0;
|
||||
/*uniform highp*/ const float glareBrightness = 0.003;
|
||||
/*uniform*/ const float diffSpikeBrightness = 0.9;
|
||||
uniform float exposure;
|
||||
|
||||
mediump vec3 linearToSRGB(mediump vec3 c)
|
||||
{
|
||||
mediump vec3 linear = 12.92 * c;
|
||||
mediump vec3 nonlinear = (1.0 + 0.055) * pow(c, vec3(1.0 / 2.4)) - vec3(0.055);
|
||||
return mix(linear, nonlinear, step(vec3(0.0031308), c));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
highp vec2 offset = gl_FragCoord.xy - pointCenter;
|
||||
highp float r2 = dot(offset, offset);
|
||||
highp float b = exp(-r2 / (2.0 * sigma2));
|
||||
#if 0
|
||||
b += glareBrightness / (glareFalloff * pow(r2, 1.5) + 1.0) * 0.5;
|
||||
#else
|
||||
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);
|
||||
#endif
|
||||
gl_FragColor = vec4(linearToSRGB(b * min(500.0, exposure) * color.rgb * brightness * 5.0), 1.0);
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef GL_ES
|
||||
#define highp
|
||||
#define mediump
|
||||
#define lowp
|
||||
#endif
|
||||
|
||||
attribute vec3 in_Position;
|
||||
attribute float in_PointSize;
|
||||
attribute vec4 in_Color;
|
||||
|
||||
uniform vec2 viewportSize;
|
||||
uniform vec2 viewportCoord;
|
||||
|
||||
uniform float magScale;
|
||||
/*uniform*/ const float sigma2 = 0.35;
|
||||
/*uniform highp*/ const float glareFalloff = 1.0 / 15.0;
|
||||
/*uniform highp*/ const float glareBrightness = 0.003;
|
||||
uniform float exposure;
|
||||
uniform float thresholdBrightness;
|
||||
|
||||
varying vec2 pointCenter;
|
||||
varying vec4 color;
|
||||
varying float brightness;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = vec4(in_Position, 1.0);
|
||||
float appMag = in_PointSize;
|
||||
|
||||
vec4 projectedPosition = MVPMatrix * position;
|
||||
vec2 devicePosition = projectedPosition.xy / projectedPosition.w;
|
||||
pointCenter = (devicePosition * 0.5 + vec2(0.5, 0.5)) * viewportSize + viewportCoord;
|
||||
color = in_Color;
|
||||
float b = pow(2.512, -appMag * magScale);
|
||||
float r2 = -log(thresholdBrightness / (exposure * b)) * 2.0 * sigma2;
|
||||
float rGlare2 = (exposure * glareBrightness * b / thresholdBrightness - 1.0) / glareFalloff;
|
||||
gl_PointSize = 2.0 * sqrt(max(r2, rGlare2));
|
||||
|
||||
brightness = b;
|
||||
gl_Position = projectedPosition;
|
||||
}
|
|
@ -87,6 +87,24 @@ FloatShaderParameter::operator=(float f)
|
|||
}
|
||||
|
||||
|
||||
Vec2ShaderParameter::Vec2ShaderParameter() :
|
||||
slot(-1)
|
||||
{
|
||||
}
|
||||
|
||||
Vec2ShaderParameter::Vec2ShaderParameter(GLuint obj, const char* name)
|
||||
{
|
||||
slot = glGetUniformLocation(obj, name);
|
||||
}
|
||||
|
||||
Vec2ShaderParameter&
|
||||
Vec2ShaderParameter::operator=(const Eigen::Vector2f& v)
|
||||
{
|
||||
if (slot != -1)
|
||||
glUniform2fv(slot, 1, v.data());
|
||||
return *this;
|
||||
}
|
||||
|
||||
Vec3ShaderParameter::Vec3ShaderParameter() :
|
||||
slot(-1)
|
||||
{
|
||||
|
|
|
@ -98,6 +98,18 @@ class FloatShaderParameter
|
|||
};
|
||||
|
||||
|
||||
class Vec2ShaderParameter
|
||||
{
|
||||
public:
|
||||
Vec2ShaderParameter();
|
||||
Vec2ShaderParameter(GLuint obj, const char* name);
|
||||
|
||||
Vec2ShaderParameter& operator=(const Eigen::Vector2f&);
|
||||
|
||||
private:
|
||||
int slot;
|
||||
};
|
||||
|
||||
class Vec3ShaderParameter
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -69,7 +69,7 @@ void PointStarRenderer::process(const Star& star, float distance, float appMag)
|
|||
if (hasOrbit)
|
||||
orbitSizeInPixels = orbitalRadius / (distance * pixelSize);
|
||||
|
||||
// Special handling for stars less than one light year away . . .
|
||||
// Special handling for stars less than SolarSystemMaxDistance away
|
||||
// We can't just go ahead and render a nearby star in the usual way
|
||||
// for two reasons:
|
||||
// * It may be clipped by the near plane
|
||||
|
@ -79,7 +79,7 @@ void PointStarRenderer::process(const Star& star, float distance, float appMag)
|
|||
// further than one light year away if the star is huge, the fov is
|
||||
// very small and the resolution is high. We'll ignore this for now
|
||||
// and use the most inexpensive test possible . . .
|
||||
if (distance < 1.0f || orbitSizeInPixels > 1.0f)
|
||||
if (distance < SolarSystemMaxDistance || orbitSizeInPixels > 1.0f)
|
||||
{
|
||||
// Compute the position of the observer relative to the star.
|
||||
// This is a much more accurate (and expensive) distance
|
||||
|
@ -155,7 +155,7 @@ void PointStarRenderer::process(const Star& star, float distance, float appMag)
|
|||
|
||||
alpha = 1.0f;
|
||||
}
|
||||
starVertexBuffer->addStar(relPos, Color(starColor, alpha), discSize);
|
||||
starVertexBuffer->addStar(relPos, Color(starColor, alpha), /*discSize*/appMag);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -31,10 +31,11 @@ PointStarVertexBuffer::~PointStarVertexBuffer()
|
|||
delete[] vertices;
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::startSprites()
|
||||
void PointStarVertexBuffer::startSprites(float _limitingMagnitude)
|
||||
{
|
||||
program = renderer.getShaderManager().getShader("star");
|
||||
program = renderer.getShaderManager().getShader("star_new");
|
||||
pointSizeFromVertex = true;
|
||||
limitingMagnitude = _limitingMagnitude;
|
||||
}
|
||||
|
||||
void PointStarVertexBuffer::startBasicPoints()
|
||||
|
@ -78,6 +79,18 @@ void PointStarVertexBuffer::makeCurrent()
|
|||
|
||||
program->use();
|
||||
program->setMVPMatrices(renderer.getProjectionMatrix(), renderer.getModelViewMatrix());
|
||||
std::array<int, 4> viewport;
|
||||
renderer.getViewport(viewport);
|
||||
program->vec2Param("viewportSize") = Eigen::Vector2f(viewport[2], viewport[3]);
|
||||
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)
|
||||
{
|
||||
program->samplerParam("starTex") = 0;
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
PointStarVertexBuffer& operator=(PointStarVertexBuffer&&) = delete;
|
||||
|
||||
void startBasicPoints();
|
||||
void startSprites();
|
||||
void startSprites(float);
|
||||
void render();
|
||||
void finish();
|
||||
inline void addStar(const Eigen::Vector3f& pos, const Color&, float);
|
||||
|
@ -59,6 +59,7 @@ private:
|
|||
Texture* texture { nullptr };
|
||||
bool pointSizeFromVertex { false };
|
||||
float pointScale { 1.0f };
|
||||
float limitingMagnitude { 7.0f };
|
||||
CelestiaGLProgram* program { nullptr };
|
||||
|
||||
static PointStarVertexBuffer* current;
|
||||
|
|
|
@ -4649,11 +4649,11 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
|
|||
starRenderer.glareVertexBuffer->setPointScale(screenDpi / 96.0f);
|
||||
|
||||
PointStarVertexBuffer::enable();
|
||||
starRenderer.glareVertexBuffer->startSprites();
|
||||
starRenderer.glareVertexBuffer->startSprites(faintestMag);
|
||||
if (starStyle == PointStars)
|
||||
starRenderer.starVertexBuffer->startBasicPoints();
|
||||
else
|
||||
starRenderer.starVertexBuffer->startSprites();
|
||||
starRenderer.starVertexBuffer->startSprites(faintestMag);
|
||||
|
||||
#ifdef OCTREE_DEBUG
|
||||
m_starProcStats.nodes = 0;
|
||||
|
|
|
@ -3495,6 +3495,12 @@ CelestiaGLProgram::samplerParam(const string& paramName)
|
|||
}
|
||||
|
||||
|
||||
Vec2ShaderParameter
|
||||
CelestiaGLProgram::vec2Param(const string& paramName)
|
||||
{
|
||||
return Vec2ShaderParameter(program->getID(), paramName.c_str());
|
||||
}
|
||||
|
||||
Vec3ShaderParameter
|
||||
CelestiaGLProgram::vec3Param(const string& paramName)
|
||||
{
|
||||
|
|
|
@ -278,6 +278,7 @@ class CelestiaGLProgram
|
|||
FloatShaderParameter floatParam(const std::string&);
|
||||
IntegerShaderParameter intParam(const std::string&);
|
||||
IntegerShaderParameter samplerParam(const std::string&);
|
||||
Vec2ShaderParameter vec2Param(const std::string&);
|
||||
Vec3ShaderParameter vec3Param(const std::string&);
|
||||
Vec4ShaderParameter vec4Param(const std::string&);
|
||||
Mat3ShaderParameter mat3Param(const std::string&);
|
||||
|
|
Loading…
Reference in New Issue