X Tutup
Skip to content

calculate star colors using Planck's law#6210

Merged
sturnclaw merged 6 commits intopioneerspacesim:masterfrom
Mc-Pain:planck-color
Nov 21, 2025
Merged

calculate star colors using Planck's law#6210
sturnclaw merged 6 commits intopioneerspacesim:masterfrom
Mc-Pain:planck-color

Conversation

@Mc-Pain
Copy link
Contributor

@Mc-Pain Mc-Pain commented Sep 15, 2025

Small improvement to derive star colors from temperature

Copy link
Member

@sturnclaw sturnclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two questions:

  1. Is the table comprised of RGB color values or CIE values? I'm seeing a comment in the source shader indicating these values are actually in the CIE colorspace.
  2. Have you considered precomputing a table of color values over the expected temperature range for stars (using perhaps an exponential mapping to preserve detail) rather than fully computing the Planck brightness every time the color of the star is requested?

vector3d( 0.000002f, 0.000001f, 0.000000f ) // 830 nm
};

Color SystemBody::GetColor() const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be computed and cached at body creation time, rather than recomputed (potentially) multiple times every single frame. 48 exp()s and 96 pow()s per call is not cheap enough for the current call frequency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know where all bodies are created

Calling this method each time after initializing body temperature looks ugly for me

@Mc-Pain
Copy link
Contributor Author

Mc-Pain commented Sep 16, 2025

Two questions:

  1. Is the table comprised of RGB color values or CIE values? I'm seeing a comment in the source shader indicating these values are actually in the CIE colorspace.

I just copy-pasted it and it seems to be actually RGB: note the red channel between 370 and 500 nm - it has red because this part of spectrum is bluish-purple

  1. Have you considered precomputing a table of color values over the expected temperature range for stars (using perhaps an exponential mapping to preserve detail) rather than fully computing the Planck brightness every time the color of the star is requested?

Yes, I'll do it soon after fixing step 4 in #6136

@fluffyfreak
Copy link
Contributor

Nice idea I think and I'm interested to see results 👍
If this is too much hassle then don't worry I'll dig into it myself but it would be good to see screenshots of before & after to see how this differs.

@Mc-Pain
Copy link
Contributor Author

Mc-Pain commented Sep 16, 2025

Nice idea I think and I'm interested to see results 👍 If this is too much hassle then don't worry I'll dig into it myself but it would be good to see screenshots of before & after to see how this differs.

I'd expect to see something like this for O-types:
image

@Bodasey
Copy link

Bodasey commented Sep 17, 2025

A little visible test done and I think class M stars look a bit too much yellow?

Please remember that there are no stars in the sky who look really green for the human eye even when the radiation maximum is at green wavelengths.

@Mc-Pain
Copy link
Contributor Author

Mc-Pain commented Sep 17, 2025

there are no stars in the sky who look really green for the human eye even when the radiation maximum is at green wavelengths.

Where did you see green stars?

@impaktor
Copy link
Member

@Mc-Pain Status?
Also, perhaps rebase to master, so we don't have to re-compile every time we switch to this branch.
And squash fix-commits.

@Mc-Pain
Copy link
Contributor Author

Mc-Pain commented Nov 6, 2025

@Mc-Pain Status? Also, perhaps rebase to master, so we don't have to re-compile every time we switch to this branch. And squash fix-commits.

Rebased onto master [9de1f0a]

Tonight I'll collect the color data from different temperatures by aligning Sol's temperature.
In given shadertoy there's a certain post-processing matrix, I'll test it too.

@Mc-Pain
Copy link
Contributor Author

Mc-Pain commented Nov 7, 2025

Made a plot of different temperatures:

X axis - temperature in K
Y axis - log(luminosity)
Color - color of star, normalized to get maximum of 1.0

thin series: original calculation from shadertoy
thick series: color multiplied by xyz2rgb matrix

image

@Mc-Pain
Copy link
Contributor Author

Mc-Pain commented Nov 10, 2025

Mars, Cydonia, Sunrise:

Without matrix

image

With matrix

image

@impaktor
Copy link
Member

@sturnclaw Do you have this in your "ready to review PRs"-queue?

@sturnclaw
Copy link
Member

I do now!

Copy link
Member

@sturnclaw sturnclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very nice, thank you @Mc-Pain! After having tested it, I really like the look of certain bands of star colors (even with our current LDR rendering pipeline), and this is a very nice step towards HDR rendering.

@sturnclaw sturnclaw merged commit d145e18 into pioneerspacesim:master Nov 21, 2025
4 checks passed
@Mc-Pain Mc-Pain deleted the planck-color branch November 24, 2025 08:50
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.

5 participants

X Tutup