Change how the game renders the world backdrops

This commit is contained in:
Kae 2023-06-30 08:37:27 +10:00
parent b43c59e828
commit 204d449dda
3 changed files with 36 additions and 13 deletions

View File

@ -60,12 +60,17 @@ void TitleScreen::render() {
float pixelRatio = m_guiContext->interfaceScale();
Vec2F screenSize = Vec2F(m_guiContext->windowSize());
auto skyRenderData = m_skyBackdrop->renderData();
m_environmentPainter->renderStars(pixelRatio, screenSize, skyRenderData);
m_environmentPainter->renderDebrisFields(pixelRatio, screenSize, skyRenderData);
m_environmentPainter->renderBackOrbiters(pixelRatio, screenSize, skyRenderData);
m_environmentPainter->renderPlanetHorizon(pixelRatio, screenSize, skyRenderData);
m_environmentPainter->renderFrontOrbiters(pixelRatio, screenSize, skyRenderData);
float pixelRatioBasis = screenSize[1] / 1080.0f;
float starAndDebrisRatio = lerp(0.0625f, pixelRatioBasis * 2.0f, pixelRatio);
float orbiterAndPlanetRatio = lerp(0.125f, pixelRatioBasis * 3.0f, pixelRatio);
m_environmentPainter->renderStars(starAndDebrisRatio, screenSize, skyRenderData);
m_environmentPainter->renderDebrisFields(starAndDebrisRatio, screenSize, skyRenderData);
m_environmentPainter->renderBackOrbiters(orbiterAndPlanetRatio, screenSize, skyRenderData);
m_environmentPainter->renderPlanetHorizon(orbiterAndPlanetRatio, screenSize, skyRenderData);
m_environmentPainter->renderSky(screenSize, skyRenderData);
m_environmentPainter->renderFrontOrbiters(orbiterAndPlanetRatio, screenSize, skyRenderData);
m_renderer->flush();

View File

@ -14,7 +14,7 @@ float const EnvironmentPainter::SunFadeRate = 0.07f;
float const EnvironmentPainter::MaxFade = 0.3f;
float const EnvironmentPainter::RayPerlinFrequency = 0.005f; // Arbitrary, part of using the Perlin as a PRNG
float const EnvironmentPainter::RayPerlinAmplitude = 2;
int const EnvironmentPainter::RayCount = 60;
int const EnvironmentPainter::RayCount = 60;
float const EnvironmentPainter::RayMinWidth = 0.8f; // % of its sector
float const EnvironmentPainter::RayWidthVariance = 5.0265f; // % of its sector
float const EnvironmentPainter::RayAngleVariance = 6.2832f; // Radians
@ -125,7 +125,7 @@ void EnvironmentPainter::renderDebrisFields(float pixelRatio, Vec2F const& scree
biggest = biggest.piecewiseMax(texture->size());
}
float screenBuffer = ceil((float)biggest.max() * (float)Constants::sqrt2) * 2.0f;
float screenBuffer = ceil((float)biggest.max() * (float)Constants::sqrt2);
PolyF field = PolyF(RectF::withSize(viewMin + velocityOffset, viewSize).padded(screenBuffer));
Vec2F debrisAngularVelocityRange = jsonToVec2F(debrisField.query("angularVelocityRange"));
@ -400,7 +400,20 @@ void EnvironmentPainter::drawRay(float pixelRatio,
void EnvironmentPainter::drawOrbiter(float pixelRatio, Vec2F const& screenSize, SkyRenderData const& sky, SkyOrbiter const& orbiter) {
float alpha = 1.0f;
Vec2F position = orbiter.position * pixelRatio;
Vec2F position;
// The way Starbound positions these is weird.
// It's a random point on a 400 by 400 area from the bottom left of the screen.
// That origin point is then multiplied by the zoom level.
// This does not intuitively scale with higher-resolution monitors, so lets fix that.
if (orbiter.type == SkyOrbiterType::Moon) {
const Vec2F correctionOrigin = { 320, 180 };
// correctionOrigin is 1920x1080 / default zoom level / 2, the most likely dev setup at the time.
Vec2F offset = orbiter.position - correctionOrigin;
position = (screenSize / 2) + offset * pixelRatio;
}
else
position = orbiter.position * pixelRatio;
if (orbiter.type == SkyOrbiterType::Sun) {
alpha = sky.dayLevel;

View File

@ -57,12 +57,17 @@ void WorldPainter::render(WorldRenderData& renderData, function<void()> lightWai
// Stars, Debris Fields, Sky, and Orbiters
m_environmentPainter->renderStars(m_camera.pixelRatio(), Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_environmentPainter->renderDebrisFields(m_camera.pixelRatio(), Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_environmentPainter->renderBackOrbiters(m_camera.pixelRatio(), Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_environmentPainter->renderPlanetHorizon(m_camera.pixelRatio(), Vec2F(m_camera.screenSize()), renderData.skyRenderData);
// Use a fixed pixel ratio for certain things.
float pixelRatioBasis = m_camera.screenSize()[1] / 1080.0f;
float starAndDebrisRatio = lerp(0.0625f, pixelRatioBasis * 2.0f, m_camera.pixelRatio());
float orbiterAndPlanetRatio = lerp(0.125f, pixelRatioBasis * 3.0f, m_camera.pixelRatio());
m_environmentPainter->renderStars(starAndDebrisRatio, Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_environmentPainter->renderDebrisFields(starAndDebrisRatio, Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_environmentPainter->renderBackOrbiters(orbiterAndPlanetRatio, Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_environmentPainter->renderPlanetHorizon(orbiterAndPlanetRatio, Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_environmentPainter->renderSky(Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_environmentPainter->renderFrontOrbiters(m_camera.pixelRatio(), Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_environmentPainter->renderFrontOrbiters(orbiterAndPlanetRatio, Vec2F(m_camera.screenSize()), renderData.skyRenderData);
if (lightWaiter) {
int64_t start = Time::monotonicMilliseconds();