X Tutup
Skip to content

General Improvements to star field#5124

Merged
sturnclaw merged 1 commit intopioneerspacesim:masterfrom
tsoj:master
Oct 4, 2021
Merged

General Improvements to star field#5124
sturnclaw merged 1 commit intopioneerspacesim:masterfrom
tsoj:master

Conversation

@tsoj
Copy link
Contributor

@tsoj tsoj commented Jan 21, 2021

screenshot1
Star density at 25%, star size at 70%¹


screenshot2
Star density at 100%, star size at 70%¹


screenshot2
Star density at 50%, star size at 100%¹


¹ Edited: I decreased the maximum possible star size by half, before it was at 35%, 35%, 50% see 302e8b0

  • Added a skybox based on NASA photographs, it has pretty much no license (https://www.nasa.gov/multimedia/guidelines/index.html), but I am no lawyer.
    This skybox will of course not be realistic once you move away from space near our own solar system, but I personally think that this is no big deal, the old version wasn't better in that regard.
    I made two skybox versions, one exactly like the original photo (skybox.dds), the other without stars (skyboxNoStars.dds, default), because I thought that the stars should be generated.
  • I removed unnecessary parameters for the star field generation:
    • brightnessApparentSizeFactor (star size) is now a configurable parameter that can also be changed with a slider in the option-menu
    • brightnessApparentSizeOffset, brightnessColorFactor, brightnessColorOffset made no real difference in appearance
    • brightnessPower is to an extent the same as brightnessApparentSizeFactor, but I am unsure whether it should be a configurable parameter, and if yes where? In GameConifg.cpp or rather like before in Starfield.ini. Same with medianPosition
    • visibleRadiusLy is now computed fully based on the selected star density
  • Fixed hyperspace animation from messy to less messy.
  • The intro/main-menu background now has generated galaxy stars instead of fake ones.² This not only looks nicer, but it is now possible to see the result of the star field density and star size options without having to start a game.

TODO:

  • ² The generated stars for the intro background create some performance penalty at start up, I personally would say it is acceptable. Also, I changed some code bits where I am not sure if it has any side effects

@impaktor
Copy link
Member

You only need to edit en.json, so please remove all other {lang}.json files.

namespace {
static const Uint32 BG_STAR_MAX = 500000;
static const Uint32 BG_STAR_MIN = 50000;
static const Uint32 BG_STAR_MIN = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason this was 50,000 was so that there are always some stars generated. With it at 1 you could literally have a starfield with just 1 star.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe there's someone who wants a pitch black sky :)

@bszlrd
Copy link
Contributor

bszlrd commented Jan 21, 2021

Looks nice!
I'd say don't up the star size to 50% It starts to clash with the UI elements. That was the reason I decreased it.


const double size = 1.0;
const Sint32 visibleRadius = MathUtil::mix(BG_STAR_RADIUS_MIN, Clamp(m_visibleRadiusLy, BG_STAR_RADIUS_MIN, BG_STAR_RADIUS_MAX), Pi::GetAmountBackgroundStars()); // lyrs
constexpr float starsPerSector = 2.0; /* experimentally determined (already ajusted for that we are
Copy link
Contributor

Choose a reason for hiding this comment

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

The potential sectors used are selected in a square, because that was easy, but are then rejected by distance leaving only stars within a spherical region.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also why pick only 2 stars per sectors when we have many more?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem I encountered was that if BG_STAR_RADIUS_MAX was increased we'd run again in the issue that only half of the sky has stars. I also found that we can increase the visibleRadius far over the hard-coded 220 LY when selecting the maximum density, which I thought is nicer than filling up the rest with fake stars.

My idea was that we want to know, how big we need to make the visibleRadius to get approximately the number of stars we want (NUM_BG_STARS).

4/3 * pi * visibleRadius^3 = numSectors * sectorSize^3, i.e. I want the sum of the volume of all sectors be approximately the same as the volume of the sphere with radius visibleRadius. We can the numSectors by experimentally checking how many stars on average are in one sector. And I found that on average there are 2 stars in one sector (or rather 2 solar systems per sector). If we'd change the size of a sector this would break that's why I'm not sure if it's actually ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah no, the fake stars are there because we never want to run the sector generator too much. It's incredibly expensive, so the populated stars are really only a shell close to the player, and anything further away is just ... padding to make it look more believable.

An extension to this idea is to eventually have the stars within jump distance be displayed on the night sky somehow, so again, that's only going to be stars close enough that the ship can jump too them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh ok, didn't think about that. What about if I cap the visible radius after calculating to BG_STAR_RADIUS_MAX or a parameter that can be changed? To be honest it takes on my notebook only half a second to generate the star field at maximum density, but this way will be easy to change it if its performance becomes more important.

@tsoj
Copy link
Contributor Author

tsoj commented Jan 21, 2021

You only need to edit en.json, so please remove all other {lang}.json files.

Won't they then also get deleted here if this pull request would merge?

@The-EG
Copy link
Contributor

The-EG commented Jan 21, 2021

Won't they then also get deleted here if this pull request would merge?

Don't remove the entire files, just your changes to them. In other words, just edit the en.json file and leave the rest unchanged.

@tsoj tsoj marked this pull request as ready for review January 22, 2021 18:32
@tsoj tsoj changed the title WIP: General Improvements to star field General Improvements to star field Jan 23, 2021
@tsoj tsoj marked this pull request as draft January 23, 2021 14:43
@tsoj tsoj marked this pull request as ready for review January 23, 2021 16:10
@sturnclaw
Copy link
Member

@tsoj your credit_for_skybox_source file should be merged into AUTHORS.txt at the root of this repository. At the bare minimum if you think it's important enough to keep it separate, it needs a file extension - Pioneer is cross-platform and not all platforms work correctly with extension-less files.

@bszlrd
Copy link
Contributor

bszlrd commented Feb 3, 2021

Checked the skybox in-game, looks nice.
Shouldn't it be named default.dds?

@tsoj
Copy link
Contributor Author

tsoj commented Feb 3, 2021

Shouldn't it be named default.dds?

@nozmajner That's how it was named before yes, I used the more descriptive name to make it easier for myself. But it doesn't really matter, if it is better I can rename it to default.dds

I think it would be generally a good idea to make the skybox filename not hard coded, at least using come config file or even making it an in-game option, but I think that can be done in another pull request.

@bszlrd
Copy link
Contributor

bszlrd commented Feb 3, 2021

I'm fine with the name, if the game picks it up.

@impaktor
Copy link
Member

impaktor commented Feb 3, 2021

Not having read the code, but if it has a new name, the original could stay, as optional choice, or?

@tsoj
Copy link
Contributor Author

tsoj commented Feb 3, 2021

I removed it, but I'll add it again. However, this doesn't make much sense at the moment, as the filename is hard-coded, so you would need to rename the skybox you want to use to the filename that is in the code.

@impaktor
Copy link
Member

impaktor commented Feb 3, 2021

OK, hold off on any changes, I was just trying out the idea.

@tsoj
Copy link
Contributor Author

tsoj commented Sep 19, 2021

Okay, I think I fixed the conflicts.

@sturnclaw
Copy link
Member

@tsoj sorry this has taken so long to get reviewed and merged. I'd appreciate it if you could do before-and-after profiles of the time taken by the background setup so we can measure what kind of performance impact this has, given that you mentioned it was slower than the current code.
The profile points should be there already in Starfield::Fill, and if you add ProfilerZoneOutput=1 to your config.ini it will generate JSON-format trace files in the profiler/NewGame user data directory when you start a new game - those can be loaded in Speedscope and they'll give you a visual representation of what time is being taken by what step in the new-game startup phase, including background creation.

@tsoj
Copy link
Contributor Author

tsoj commented Sep 20, 2021

@Web-eWorks
Before it takes around 270 ms for Starfield::Fill and now at the highest possible star density (1.0) it takes 600 ms (on my notebook with an i5-8250U). When the star density is set to 0.5 (the current default) it takes 300 ms.

What I could add is another option for the number of real stars that is independent of the star density, which could then be used to adjust the performance. The rest of the stars that would need to be added to reach the chosen star density would be fake stars (randomly generated). Though, I am wondering if that would be really necessary for this kind of performance penalty.

I didn't do proper benchmarks (I had other programs running at the same time, and I didn't run all version of pioneer at the same time), but I think these numbers are roughly correct. For all tests, I did the same thing in-game: launched (a new game) from Mars, flew a bit around, jumped to another system and quit.

By the way, I didn't manage to properly compile pioneer with cmake and make with the option to use the profiler. How is this supposed to be done? I just replace all #ifdef PIONEER_PROFILER with ifndef PIONEER_PROFILER (and ifndef with ifdef) :P.

@sturnclaw
Copy link
Member

Before it takes around 270 ms for Starfield::Fill and now at the highest possible star density (1.0) it takes 600 ms (on my notebook with an i5-8250U). When the star density is set to 0.5 (the current default) it takes 300 ms.

Excellent, thank you! Wanted to get a "real world" example of what kind of performance difference we're talking about here; looks like it's negligible enough to not be a concern.

Regarding building with profiler, ./bootstrap -DPROFILER_ENABLED=1 is the way to go; no source code changes are required.

@sturnclaw sturnclaw merged commit 0a67da4 into pioneerspacesim:master Oct 4, 2021
@sturnclaw
Copy link
Member

Merged! Thank you for the work and the patience with the review process!

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

X Tutup