Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rendering for starfield #1952

Draft
wants to merge 48 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
3a112ab
wip
375gnu Oct 24, 2023
7e49d11
Update shaders/star_vert.glsl
375gnu Oct 27, 2023
791a109
[skip ci] Merge branch 'master' into askaniys-stars
375gnu Oct 27, 2023
6036e69
wip
375gnu Oct 24, 2023
11ed2a0
wip
375gnu Jan 28, 2024
6cbd344
use br in psf instead of br0, fix point size
375gnu Jan 29, 2024
70890c8
wip
375gnu Jan 29, 2024
60e7495
Merge branch 'master' into askaniys-stars
375gnu Jun 25, 2024
3d78893
Merge branch 'askaniys-stars' of github.com:CelestiaProject/Celestia …
375gnu Jun 25, 2024
b2d23fb
New code for dim stars, clean-up
Askaniy Jun 30, 2024
2ca7268
Update PSF core
Askaniy Jul 2, 2024
f2fd102
Remove AutoMag and replace faintest magnitude with exposure (wip)
Askaniy Jul 2, 2024
e92bc38
More transition to the exposure system (wip)
Askaniy Jul 2, 2024
3daa0ba
Added getFluxInVegas
Askaniy Jul 3, 2024
5d472cc
Continuing the transition to the exposure system
Askaniy Jul 3, 2024
da37d6f
fixes
375gnu Jul 4, 2024
dc57069
Clear irradiance-irradiation system, fixes
Askaniy Jul 4, 2024
f9bc0ed
missing declaration fix
Askaniy Jul 4, 2024
08f22f9
wip
Askaniy Jul 4, 2024
4474b4a
wip
Askaniy Jul 5, 2024
25052db
wip
Askaniy Jul 5, 2024
1b7a795
wip
Askaniy Jul 5, 2024
84e6b43
wip
Askaniy Jul 5, 2024
462c18d
wip
Askaniy Jul 5, 2024
7d9332a
wip
Askaniy Jul 5, 2024
66b7031
Controls update (all languages)
Askaniy Jul 5, 2024
f613993
Start deleting star styles
Askaniy Jul 5, 2024
32b64ce
Delete star styles and legacy star colors, set solar whitepoint by de…
Askaniy Jul 5, 2024
317f973
fixes
Askaniy Jul 5, 2024
85ee257
New label brightness formula
Askaniy Jul 6, 2024
be3cc07
wip
Askaniy Jul 6, 2024
197b77b
Simpler fragment shader for 9 px mode
Askaniy Jul 6, 2024
cbd67e6
Deleting as much legacy stellar code as possible
Askaniy Jul 6, 2024
be55064
Merge the limb-darkening branch
Askaniy Jul 6, 2024
cb13c27
Copyright updates
Askaniy Jul 6, 2024
98ee734
Update astro constants with actual standards
Askaniy Jul 6, 2024
34e8927
clarification
Askaniy Jul 6, 2024
73281f2
clarification
Askaniy Jul 6, 2024
2bd203f
fixes
Askaniy Jul 6, 2024
7719c66
(semi)fixes
375gnu Jul 7, 2024
e203600
labels fixing
Askaniy Jul 8, 2024
1050ea2
Revert the computation of LN_MAG
Askaniy Jul 16, 2024
264fc23
Merge branch 'master' into askaniys-stars
ajtribick Jul 23, 2024
345adf3
Some random fixes
375gnu Jul 24, 2024
ec70d89
Merge branch 'master' into askaniys-stars
375gnu Oct 9, 2024
7bf6254
Merge branch 'master' into askaniys-stars
375gnu Nov 13, 2024
d18896f
Merge branch 'master' into askaniys-stars
375gnu Dec 31, 2024
8430822
fix merge issues
375gnu Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions shaders/star_frag.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,59 @@
uniform sampler2D starTex;
varying vec4 color;
const float degree_per_px = 0.05;
const float br_limit = 1.0 / (255.0 * 12.92);

varying vec3 v_color;
varying vec3 v_max_tetha_hk;
varying float pointSize;

float psf_square(float theta, float min_theta, float max_theta, float h, float k, float b)
{
// Human eye's point source function, optimized to fit a square.
// Lower limit on brightness and angular size: 1 Vega and 0.05 degrees per pixel.
// No upper limits.

if (theta < min_theta)
return 1.0; // overexposed

if (theta < max_theta)
{
float brackets = b / (theta - h) - 1.0;
return brackets * brackets / k;
}

return 0.0; // after max_theta function starts to grow again
}

/*
float psf_fullscreen(float theta, float min_theta):
{
// Human eye's point source function, optimized to be a full-screen shader.
// The price to pay for simplification is a brightness reduction compared to the original PSF.

if (theta2 < min_theta)
return 1; // overexposed

return 4.43366571e-6 / theta;
}
*/

void main(void)
{
gl_FragColor = texture2D(starTex, gl_PointCoord) * color;
float max_theta = v_max_tetha_hk.x;
if (max_theta == -1.0)
{
gl_FragColor = vec4(v_color, 1.0);
}
else
{
float h = v_max_tetha_hk.y;
float k = v_max_tetha_hk.z;

float b = max_theta - h;
float min_theta = h + b / (sqrt(k) + 1.0);

vec2 offset = (gl_PointCoord.xy - vec2(0.5)) * pointSize;
float theta = length(offset) * degree_per_px;

gl_FragColor = vec4(v_color * psf_square(theta, min_theta, max_theta, h, k, b), 1.0);
}
}
48 changes: 41 additions & 7 deletions shaders/star_vert.glsl
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
attribute vec3 in_Position;
attribute vec4 in_Color;
attribute float in_PointSize;
varying vec4 color;

const float degree_per_px = 0.05;
const float br_limit = 1.0 / (255.0 * 12.92);

varying vec3 v_color; // 12
varying vec3 v_max_tetha_hk; // 24
varying float pointSize; // 28

uniform vec2 viewportSize;

attribute vec4 in_Position;
attribute vec3 in_Color;
attribute float in_PointSize; // scaled brightness measured in Vegas

float psf_max_theta(float br)
375gnu marked this conversation as resolved.
Show resolved Hide resolved
{
return 0.012 + 1.488 / (sqrt(br_limit * 1000000.0 / (11.0 * br)) + 1.0);
}
375gnu marked this conversation as resolved.
Show resolved Hide resolved

void main(void)
{
gl_PointSize = in_PointSize;
color = in_Color;
set_vp(vec4(in_Position, 1.0));
float linearBr = pow(10.0, 0.4f * in_PointSize) * br_limit;
vec3 color0 = in_Color * (linearBr / in_Color.g); // scaling on brightness and normalizing by green channel

vec3 check_vec = step(vec3(1.0), color0); // step(edge, x) - For element i of the return value, 0.0 is returned if x[i] < edge[i], and 1.0 is returned otherwise.
float check = check_vec.x + check_vec.y + check_vec.z;
if (check == 0.0)
{
pointSize = 1.0;
v_max_tetha_hk = vec3(-1.0);
}
else
{
float max_theta = 0.33435822702992773 * sqrt(max(color0.r, max(color0.g, color0.b))); // glare radius
pointSize = 2.0 * ceil(max_theta / degree_per_px);

float h = 0.0082234880783653 * pow(max_theta, 0.7369983254906639); // h, k, b - common constants, depending originally on star brightness
float k = 38581.577272697796 * pow(max_theta, 2.368787717957141);
v_max_tetha_hk = vec3(max_theta, h, k);
}

gl_PointSize = pointSize;
v_color = color0;
set_vp(in_Position);
}
20 changes: 7 additions & 13 deletions src/celengine/pointstarrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
#include <celengine/starcolors.h>
#include <celengine/star.h>
#include <celengine/univcoord.h>
#include <cmath>
#include "pointstarvertexbuffer.h"
#include "render.h"
#include "pointstarrenderer.h"

#include <fmt/format.h>

using namespace std;
using namespace Eigen;

Expand Down Expand Up @@ -95,19 +98,10 @@ void PointStarRenderer::process(const Star& star, float distance, float appMag)
// planets.
if (distance > SolarSystemMaxDistance)
{
float pointSize, alpha, glareSize, glareAlpha;
float size = BaseStarDiscSize * static_cast<float>(renderer->getScreenDpi()) / 96.0f;
renderer->calculatePointSize(appMag,
size,
pointSize,
alpha,
glareSize,
glareAlpha);

if (glareSize != 0.0f)
glareVertexBuffer->addStar(relPos, Color(starColor, glareAlpha), glareSize);
if (pointSize != 0.0f)
starVertexBuffer->addStar(relPos, Color(starColor, alpha), pointSize);
if (appMag < faintestMag)
{
starVertexBuffer->addStar(relPos, starColor, faintestMag - appMag);
}

// Place labels for stars brighter than the specified label threshold brightness
if (((labelMode & Renderer::StarLabels) != 0) && appMag < labelThresholdMag)
Expand Down
7 changes: 5 additions & 2 deletions src/celengine/pointstarvertexbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void PointStarVertexBuffer::startBasicPoints()

void PointStarVertexBuffer::render()
{
if (m_nStars != 0)
if (m_nStars != 0 && m_prog != nullptr)
{
makeCurrent();

Expand All @@ -69,7 +69,7 @@ void PointStarVertexBuffer::render()

void PointStarVertexBuffer::makeCurrent()
{
if (current == this || m_prog == nullptr)
if (current == this)
return;

if (current != nullptr)
Expand All @@ -79,6 +79,9 @@ void PointStarVertexBuffer::makeCurrent()

m_prog->use();
m_prog->setMVPMatrices(m_renderer.getCurrentProjectionMatrix(), m_renderer.getCurrentModelViewMatrix());
int x, y, w, h;
m_renderer.getViewport(&x, &y, &w, &h);
m_prog->vec2Param("viewportSize") = Eigen::Vector2f(w-x, h-y);
if (m_pointSizeFromVertex)
{
m_prog->samplerParam("starTex") = 0;
Expand Down
22 changes: 12 additions & 10 deletions src/celengine/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ Renderer::Renderer() :

{
pointStarVertexBuffer = new PointStarVertexBuffer(*this, 2048);
glareVertexBuffer = new PointStarVertexBuffer(*this, 2048);
//glareVertexBuffer = new PointStarVertexBuffer(*this, 2048);

for (int i = 0; i < (int) FontCount; i++)
{
Expand All @@ -282,7 +282,7 @@ Renderer::Renderer() :
Renderer::~Renderer()
{
delete pointStarVertexBuffer;
delete glareVertexBuffer;
//delete glareVertexBuffer;
delete shaderManager;

m_atmosphereRenderer->deinitGL();
Expand Down Expand Up @@ -1806,8 +1806,10 @@ void Renderer::renderObjectAsPoint(const Vector3f& position,
gaussianGlareTex->bind();
if (glareSize > gl::maxPointSize)
m_largeStarRenderer->render(center, {color, glareAlpha}, glareSize, mvp);
/*
else
glareVertexBuffer->addStar(center, {color, glareAlpha}, glareSize);
*/
}
}
}
Expand Down Expand Up @@ -3829,7 +3831,7 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
starRenderer.viewNormal = getCameraOrientationf().conjugate() * -Vector3f::UnitZ();
starRenderer.renderList = &renderList;
starRenderer.starVertexBuffer = pointStarVertexBuffer;
starRenderer.glareVertexBuffer = glareVertexBuffer;
//starRenderer.glareVertexBuffer = glareVertexBuffer;
starRenderer.fov = fov;
starRenderer.cosFOV = (float) cos(degToRad(calcMaxFOV(fov, getAspectRatio())) / 2.0f);

Expand All @@ -3848,11 +3850,11 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
gaussianDiscTex->bind();
starRenderer.starVertexBuffer->setTexture(gaussianDiscTex);
starRenderer.starVertexBuffer->setPointScale(screenDpi / 96.0f);
starRenderer.glareVertexBuffer->setTexture(gaussianGlareTex);
starRenderer.glareVertexBuffer->setPointScale(screenDpi / 96.0f);
//starRenderer.glareVertexBuffer->setTexture(gaussianGlareTex);
//starRenderer.glareVertexBuffer->setPointScale(screenDpi / 96.0f);

PointStarVertexBuffer::enable();
starRenderer.glareVertexBuffer->startSprites();
//starRenderer.glareVertexBuffer->startSprites();
if (starStyle == PointStars)
starRenderer.starVertexBuffer->startBasicPoints();
else
Expand Down Expand Up @@ -3881,7 +3883,7 @@ void Renderer::renderPointStars(const StarDatabase& starDB,
#endif

starRenderer.starVertexBuffer->finish();
starRenderer.glareVertexBuffer->finish();
//starRenderer.glareVertexBuffer->finish();
PointStarVertexBuffer::disable();

#ifndef GL_ES
Expand Down Expand Up @@ -5366,9 +5368,9 @@ Renderer::renderSolarSystemObjects(const Observer &observer,
setPipelineState(ps);

PointStarVertexBuffer::enable();
glareVertexBuffer->startSprites();
glareVertexBuffer->render();
glareVertexBuffer->finish();
//glareVertexBuffer->startSprites();
//glareVertexBuffer->render();
//glareVertexBuffer->finish();
if (starStyle == PointStars)
pointStarVertexBuffer->startBasicPoints();
else
Expand Down