Skip to content

New rendering for starfield#1952

Closed
375gnu wants to merge 53 commits into
masterfrom
askaniys-stars
Closed

New rendering for starfield#1952
375gnu wants to merge 53 commits into
masterfrom
askaniys-stars

Conversation

@375gnu
Copy link
Copy Markdown
Collaborator

@375gnu 375gnu commented Oct 26, 2023

No description provided.

Comment thread shaders/star_vert.glsl Outdated
Comment thread shaders/star_vert.glsl Outdated
Comment thread shaders/star_vert.glsl Outdated
Comment thread shaders/star_vert.glsl Outdated
Comment thread shaders/star_vert.glsl Outdated
Comment thread shaders/star_vert.glsl Outdated
@sonarqubecloud
Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@375gnu 375gnu changed the title wip New rendering for starfield Nov 5, 2023
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

9 New issues
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@sonarqubecloud
Copy link
Copy Markdown

@Askaniy
Copy link
Copy Markdown
Contributor

Askaniy commented Feb 14, 2025

Let's count current bugs I created and left 🥲
(For rendering box testing, I turned on the red filler at line 47 in star_frag.glsl)

There are two stages of rendering a star, depending on its individual visible brightness: "9 px" mode (3x3 box size) and "glow" mode (variable box size). For simplicity, the separating value is chosen to be 1 Vega brightness at exposure 1. The separation is in star_vert.glsl at line 46.

You can notice that in the glow mode, the glow doesn't completely fill the box. Actually fills, but only in internal Float values. sRGB gamma correction is assumed in the glow design, which will “pull” it to the box edges.

Bug 1

Star field have never been seen using both modes at once, depending on the brightness of a particular star. If you don't change the code (if (all(lessThan(scaled_color, vec3(1.0))))), the glow mode is used. If you change to if (true), the 9 px mode is used.
изображение
That's how 4 px mode looked like. Stars feel square, that's why I moved it to 9 px instead.
изображение

Bug 2

The 9 px mode was broken since my last testing in the summer 2024. When rotating the camera, the 1 pixel stars rarely appear and then disappear again:
изображение

Bug 3

The wrong brightness values are obviously being supplied to the input. The glow mode worked correctly before the exposure transition was made:
Screenshot_20240701_114940

Bug 4

After ruthless code reduction, barycenters began to emit. I'm guessing it was an old optimization whose limits were accidentally removed. I think it's best to find and remove the barycenter glow all the way through.
изображение

Bug 5

Limb darkening was added, but the star surfaces have stopped rendering. It could be a typo or caused by deleting something extra.

Bug 6

There is a small “bug” with exposure setting in the interface: I failed to make integer output when updating a variable, i.e. now Exposure: 16.00 is printed instead of Exposure: 16. I rolled back my experiments

Notes

Based on the Discord discussions, it would be both more realistic and easier to program the overall process of rendering both stars, planets, and spacecraft if they are in point mode. Without special brightness enhancement of planets, for example. For the sake of simplifying visual search, you can set different thresholds for displaying names. Now there are no star styles, which may allow simplifying the logic globally. I also removed the glow and atmosphere of the stars, while adding changes from the limb-darkening branch to optimize the logic of everything planned at once. To keep the Sun looking bright, I suggest increasing the maximum size of the glow to the size of the screen. At typical exposures, only the Sun will be bright, and it will switch to a starry background with no jumps when removed.

Also, maximum glow box size is discussed to be min(min(screen_hight, screen_width), max_point_size), depending on the max point size that openGL supports.

AstroChara added a commit to AstroChara/Celestia that referenced this pull request Jul 24, 2025
Split from CelestiaProject#1952, as suggested by Askaniy themself, allowing this component of that PR to be updated even if the PSF itself remains work in progress.
AstroChara added a commit that referenced this pull request Jul 25, 2025
Split from #1952, as suggested by Askaniy themself, allowing this component of that PR to be updated even if the PSF itself remains work in progress.
@Askaniy
Copy link
Copy Markdown
Contributor

Askaniy commented Jul 26, 2025

Chara updated astronomical constants (#2371) and made Sun white point the default one (#2372), to delineate the branch

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Aug 1, 2025

@sonarqubecloud
Copy link
Copy Markdown

@AstroChara
Copy link
Copy Markdown
Contributor

Since it is somehow attached to this PR, I would like to propose that we cancel the complete deletion of the "Classic" star rendering mode; instead, we recycle its code infrastructure to create a "true colour" mode, where each star type's colour is based on colour from TrueColorTools — so light yellow late M-dwarfs and pink/magenta T-dwarfs, for example.

@AstroChara
Copy link
Copy Markdown
Contributor

On a more general note, we have seen how combining multiple completely different tasks into one creates this mess which is very difficult to understand and by now taking over three years to complete.

I think we should look into taking apart this PR, putting each indivisible component of this PR into their own PR, where they can be debugged and reviewed and incorporated independently. Given the scale of this PR, it would be a lot of effort, but it should make things far easier and far more mobile in the long run.

We can also remove elements already in the program like updating constants or setting default star colour mode.

@375gnu
Copy link
Copy Markdown
Collaborator Author

375gnu commented Feb 3, 2026

@Askaniy do you still have your original python files? it lost them, i'd like to play with them with different exposures.

@Askaniy
Copy link
Copy Markdown
Contributor

Askaniy commented Feb 4, 2026

@375gnu do you mean https://github.com/Askaniy/CelestiaStarRenderer or some older version of it?

@375gnu
Copy link
Copy Markdown
Collaborator Author

375gnu commented Feb 4, 2026

Yes, this one. Thanks!

@ObmijSelaw
Copy link
Copy Markdown

ObmijSelaw commented Feb 6, 2026

greetings, I was recommended on Discord to come here to let you all know about my efforts in getting sRGB gamma correction working in tandem with this new star rendering method

I have been working on it as a "fork", but I am keeping it as closely updated to master upstream so it can be (hopefully) easily integrated when all bugs are squashed and the moment is right

link to my "fork" here on github

thus far, I have integrated code up to commit 2ca7268 from askaniys-stars branch

Now, to recap, @Askaniy said on Discord that this star rendering system should be able to "discriminate" between the 9px rendering mode (i understand this is for low-brightness stars) and glow mode (for brighter stars), however, this is not currently working.

i confirm in my builds that this is indeed broken and seemingly only glow mode works, if the stars get dimmed below a certain brightness threshold, they disappear altogether instead of becoming dim. Only very bright stars are rendered

so far i have not touched the code beyond said commit, so i have not integrated the commits replacing faintest-magnitude with exposure, nor deleting legacy star colors/styles, etc.

I am thinking the priority should be figuring out what's preventing this "dual mode" code from working, what do you say?
Screenshot_20260205_031826
Screenshot_20260205_031807

@Askaniy
Copy link
Copy Markdown
Contributor

Askaniy commented May 8, 2026

I just finished complete redesign of the star rendering method. It's both easier to implement and closer to the original PSF. And has been tested a lot.

Last time, the method required separating the modes within the shader. And that didn't work out. Now there's no need to deal with that: the new method could be split into two separate shaders, one for the point and one for eye PSF. See the general logic in RenderEngine.draw_source()

@AstroChara
Copy link
Copy Markdown
Contributor

AstroChara commented May 11, 2026

I just finished complete redesign of the star rendering method. It's both easier to implement and closer to the original PSF. And has been tested a lot.

Last time, the method required separating the modes within the shader. And that didn't work out. Now there's no need to deal with that: the new method could be split into two separate shaders, one for the point and one for eye PSF. See the general logic in RenderEngine.draw_source()

I wonder if we should just make a new PR, and we can simply reuse the important bits in this PR (like exposure implementation) and discard the outdated stuff like limb darkening or removing legacy colours (whose infrastructure can instead be reused).

@Askaniy
Copy link
Copy Markdown
Contributor

Askaniy commented May 11, 2026

Making a new PR is what I think could work.

we can simply reuse the important bits in this PR (like exposure implementation)

But exposure I implemented is exactly the thing that is broken in this PR.

I propose adding the stars first, and exposure system after. We would need to convert FaintestMag to linear irradiance (maybe it's better to use SI units), and then convert the irradiance to the radiance scale that the shader uses (where radiance=1 is the scale of transition between point and eye PSF modes).

@AstroChara
Copy link
Copy Markdown
Contributor

I propose adding the stars first, and exposure system after. We would need to convert FaintestMag to linear irradiance (maybe it's better to use SI units), and then convert the irradiance to the radiance scale that the shader uses (where radiance=1 is the scale of transition between point and eye PSF modes).

I believe that works. If we add just the PSFs, we will need the star rendering itself, the removal of the current star styles (can we just comment out the infrastructure to be reused later?), and add the conversion of magnitudes to irradiance, as you said.

levinli303 added a commit to celestiamobile/Celestia that referenced this pull request May 27, 2026
Implements a new physically-based star rendering mode based on the
algorithm by Askaniy Anpilogov (CelestiaStarRenderer), as a redesign
of the stalled PR CelestiaProject#1952 adapted to the current sRGB-aware codebase.

Adds a 4th StarStyle::PointSourceFunction alongside the existing
FuzzyPointStars / PointStars / ScaledDiscStars styles. The renderer
emits linear radiance with additive blending and combines two passes:

  * Point mode: a volume-conserving linear cone of fixed pixel radius,
      peakRadiance = exposure * 3 * irradiance / (pi * pointRadius^2)
  * Glow mode: an additive Spencer (1995) photopic eye-PSF approximation
      enabled when peak radiance exceeds 1.

Two user-tunable parameters drive the look:
  StarPointRadius (1..10, default 2)   - cone radius in points
  StarOptimization (0.1..1.0, default 0.1) - glow falloff

Plumbed end-to-end:
  * shaders/psfstar_{vert,frag}.glsl (GLES-safe: precision-qualified
    int uniform, guarded pow(), minimum gl_PointSize)
  * src/celengine/psfstarvertexbuffer.{h,cpp} + Renderer integration
  * StaticShader::PsfStar registration; uses canonical in_Intensity
    attribute binding for per-vertex peak radiance
  * celestia.cfg.in keys with clamping in configfile
  * Qt menu + preferences dialog (radio + two spinboxes, persisted)
  * SDL render dialog (4th radio button)
  * Win32 menu entry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
levinli303 added a commit to celestiamobile/Celestia that referenced this pull request May 27, 2026
Implements a new physically-based star rendering mode based on the
algorithm by Askaniy Anpilogov (CelestiaStarRenderer), as a redesign
of the stalled PR CelestiaProject#1952 adapted to the current sRGB-aware codebase.

Adds a 4th StarStyle::PointSourceFunction alongside the existing
FuzzyPointStars / PointStars / ScaledDiscStars styles. The renderer
emits linear radiance with additive blending and combines two passes:

  * Point mode: a volume-conserving linear cone of fixed pixel radius,
      peakRadiance = exposure * 3 * irradiance / (pi * pointRadius^2)
  * Glow mode: an additive Spencer (1995) photopic eye-PSF approximation
      enabled when peak radiance exceeds 1.

Two user-tunable parameters drive the look:
  StarPointRadius (1..10, default 2)   - cone radius in points
  StarOptimization (0.1..1.0, default 0.1) - glow falloff

Plumbed end-to-end:
  * shaders/psfstar_{vert,frag}.glsl (GLES-safe: precision-qualified
    int uniform, guarded pow(), minimum gl_PointSize)
  * src/celengine/psfstarvertexbuffer.{h,cpp} + Renderer integration
  * StaticShader::PsfStar registration; uses canonical in_Intensity
    attribute binding for per-vertex peak radiance
  * celestia.cfg.in keys with clamping in configfile
  * Qt menu + preferences dialog (radio + two spinboxes, persisted)
  * SDL render dialog (4th radio button)
  * Win32 menu entry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@levinli303 levinli303 closed this May 28, 2026
levinli303 added a commit to celestiamobile/Celestia that referenced this pull request May 31, 2026
Implements a new physically-based star rendering mode based on the
algorithm by Askaniy Anpilogov (CelestiaStarRenderer), as a redesign
of the stalled PR CelestiaProject#1952 adapted to the current sRGB-aware codebase.

Adds a 4th StarStyle::PointSourceFunction alongside the existing
FuzzyPointStars / PointStars / ScaledDiscStars styles. The renderer
emits linear radiance with additive blending and combines two passes:

  * Point mode: a volume-conserving linear cone of fixed pixel radius,
      peakRadiance = exposure * 3 * irradiance / (pi * pointRadius^2)
  * Glow mode: an additive Spencer (1995) photopic eye-PSF approximation
      enabled when peak radiance exceeds 1.

Two user-tunable parameters drive the look:
  StarPointRadius (1..10, default 2)   - cone radius in points
  StarOptimization (0.1..1.0, default 0.1) - glow falloff

Plumbed end-to-end:
  * shaders/psfstar_{vert,frag}.glsl (GLES-safe: precision-qualified
    int uniform, guarded pow(), minimum gl_PointSize)
  * src/celengine/psfstarvertexbuffer.{h,cpp} + Renderer integration
  * StaticShader::PsfStar registration; uses canonical in_Intensity
    attribute binding for per-vertex peak radiance
  * celestia.cfg.in keys with clamping in configfile
  * Qt menu + preferences dialog (radio + two spinboxes, persisted)
  * SDL render dialog (4th radio button)
  * Win32 menu entry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
levinli303 added a commit to celestiamobile/Celestia that referenced this pull request May 31, 2026
Implements a new physically-based star rendering mode based on the
algorithm by Askaniy Anpilogov (CelestiaStarRenderer), as a redesign
of the stalled PR CelestiaProject#1952 adapted to the current sRGB-aware codebase.

Adds a 4th StarStyle::PointSourceFunction alongside the existing
FuzzyPointStars / PointStars / ScaledDiscStars styles. The renderer
emits linear radiance with additive blending and combines two passes:

  * Point mode: a volume-conserving linear cone of fixed pixel radius,
      peakRadiance = exposure * 3 * irradiance / (pi * pointRadius^2)
  * Glow mode: an additive Spencer (1995) photopic eye-PSF approximation
      enabled when peak radiance exceeds 1.

Two user-tunable parameters drive the look:
  StarPointRadius (1..10, default 2)   - cone radius in points
  StarOptimization (0.1..1.0, default 0.1) - glow falloff

Plumbed end-to-end:
  * shaders/psfstar_{vert,frag}.glsl (GLES-safe: precision-qualified
    int uniform, guarded pow(), minimum gl_PointSize)
  * src/celengine/psfstarvertexbuffer.{h,cpp} + Renderer integration
  * StaticShader::PsfStar registration; uses canonical in_Intensity
    attribute binding for per-vertex peak radiance
  * celestia.cfg.in keys with clamping in configfile
  * Qt menu + preferences dialog (radio + two spinboxes, persisted)
  * SDL render dialog (4th radio button)
  * Win32 menu entry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
levinli303 added a commit to celestiamobile/Celestia that referenced this pull request Jun 2, 2026
Implements a new physically-based star rendering mode based on the
algorithm by Askaniy Anpilogov (CelestiaStarRenderer), as a redesign
of the stalled PR CelestiaProject#1952 adapted to the current sRGB-aware codebase.

Adds a 4th StarStyle::PointSourceFunction alongside the existing
FuzzyPointStars / PointStars / ScaledDiscStars styles. The renderer
emits linear radiance with additive blending and combines two passes:

  * Point mode: a volume-conserving linear cone of fixed pixel radius,
      peakRadiance = exposure * 3 * irradiance / (pi * pointRadius^2)
  * Glow mode: an additive Spencer (1995) photopic eye-PSF approximation
      enabled when peak radiance exceeds 1.

Two user-tunable parameters drive the look:
  StarPointRadius (1..10, default 2)   - cone radius in points
  StarOptimization (0.1..1.0, default 0.1) - glow falloff

Plumbed end-to-end:
  * shaders/psfstar_{vert,frag}.glsl (GLES-safe: precision-qualified
    int uniform, guarded pow(), minimum gl_PointSize)
  * src/celengine/psfstarvertexbuffer.{h,cpp} + Renderer integration
  * StaticShader::PsfStar registration; uses canonical in_Intensity
    attribute binding for per-vertex peak radiance
  * celestia.cfg.in keys with clamping in configfile
  * Qt menu + preferences dialog (radio + two spinboxes, persisted)
  * SDL render dialog (4th radio button)
  * Win32 menu entry

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants