Merge pull request #25 from N1ffe/dynamic-sun-image

Dynamic sun image
This commit is contained in:
Kae 2024-03-02 14:58:30 +11:00 committed by GitHub
commit 9ae14a3d0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 55 additions and 9 deletions

View File

@ -0,0 +1,23 @@
{
"sun" : {
"rayColor" : [255, 255, 200],
"scale" : 0.7, // base scale, dynamic scaling aplies after it (sun image appears to have a higher scale in osb client?)
"dynamicImage" : {
"enabled" : true,
"images" : {
"whitestar" : "/sky/orbitals/whitestar.png",
"orangestar" : "/sky/orbitals/orangestar.png",
"yellowstar" : "/sky/orbitals/yellowstar.png",
"bluestar" : "/sky/orbitals/bluestar.png",
"redstar" : "/sky/orbitals/redstar.png"
},
"rayColors" : {
"whitestar" : [199, 245, 255],
"orangestar" : [255, 227, 199],
"yellowstar" : [245, 255, 199],
"bluestar" : [199, 199, 255],
"redstar" : [255, 213, 199]
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -16,6 +16,7 @@ SkyParameters::SkyParameters(CelestialCoordinate const& coordinate, CelestialDat
auto params = celestialDatabase->parameters(coordinate);
if (!params)
return;
auto systemParams = celestialDatabase->parameters(coordinate.system());
seed = staticRandomU64(params->seed(), "SkySeed");
// Gather up all the CelestialParameters and scales for all the celestial
@ -50,6 +51,8 @@ SkyParameters::SkyParameters(CelestialCoordinate const& coordinate, CelestialDat
horizonImages = CelestialGraphics::worldHorizonImages(*params);
readVisitableParameters(params->visitableParameters());
sunType = systemParams->getParameter("typeName").toString();
}
SkyParameters::SkyParameters(SkyParameters const& oldSkyParameters, VisitableWorldParametersConstPtr newVisitableParameters) : SkyParameters() {
@ -108,6 +111,8 @@ SkyParameters::SkyParameters(Json const& config) : SkyParameters() {
spaceLevel = config.optFloat("spaceLevel");
surfaceLevel = config.optFloat("surfaceLevel");
sunType = config.getString("sunType", "");
}
Json SkyParameters::toJson() const {
@ -149,6 +154,7 @@ Json SkyParameters::toJson() const {
{"ambientLightLevel", jsonFromMaybe<Color>(skyColoring.maybeRight(), [](Color c) { return jsonFromColor(c); })},
{"spaceLevel", jsonFromMaybe<float>(spaceLevel)},
{"surfaceLevel", jsonFromMaybe<float>(surfaceLevel)},
{"sunType", sunType},
};
}
@ -163,6 +169,7 @@ void SkyParameters::read(DataStream& ds) {
ds >> skyColoring;
ds >> spaceLevel;
ds >> surfaceLevel;
ds >> sunType;
}
void SkyParameters::write(DataStream& ds) const {
@ -176,6 +183,7 @@ void SkyParameters::write(DataStream& ds) const {
ds << skyColoring;
ds << spaceLevel;
ds << surfaceLevel;
ds << sunType;
}
void SkyParameters::readVisitableParameters(VisitableWorldParametersConstPtr visitableParameters) {

View File

@ -44,6 +44,7 @@ struct SkyParameters {
Either<SkyColoring, Color> skyColoring;
Maybe<float> spaceLevel;
Maybe<float> surfaceLevel;
String sunType;
};
DataStream& operator>>(DataStream& ds, SkyParameters& sky);

View File

@ -95,10 +95,15 @@ List<SkyOrbiter> SkyRenderData::frontOrbiters(Vec2F const& viewSize) const {
List<SkyOrbiter> orbiters;
if (type == SkyType::Atmospheric || type == SkyType::Atmosphereless) {
String image;
if (settings.queryBool("sun.dynamicImage.enabled", false) && !skyParameters.sunType.empty())
image = settings.queryString("sun.dynamicImage.images." + skyParameters.sunType, settings.queryString("sun.image"));
else
image = settings.queryString("sun.image");
orbiters.append({SkyOrbiterType::Sun,
1.0f,
settings.queryFloat("sun.scale", 1.0f),
0.0f,
settings.queryString("sun.image"),
image,
Vec2F::withAngle(orbitAngle, settings.queryFloat("sun.radius")) + viewSize / 2});
} else if (type == SkyType::Orbital) {
auto planetCenter = Vec2F(viewSize[0] / 2, 0)

View File

@ -380,21 +380,27 @@ void EnvironmentPainter::drawRay(float pixelRatio,
// Sum is used to vary the ray intensity based on sky color
// Rays show up more on darker backgrounds, so this scales to remove that
float sum = std::pow((color[0] + color[1]) * RayColorDependenceScale, RayColorDependenceLevel);
Vec3B rayColor;
if (sky.settings.queryBool("sun.dynamicImage.enabled", false) && !sky.skyParameters.sunType.empty())
rayColor = jsonToVec3B(sky.settings.query("sun.dynamicImage.rayColors." + sky.skyParameters.sunType, sky.settings.query("sun.rayColor", JsonArray{RayColor[0], RayColor[1], RayColor[2]})));
else
rayColor = jsonToVec3B(sky.settings.query("sun.rayColor", JsonArray{RayColor[0], RayColor[1], RayColor[2]}));
float sunScale = sky.settings.queryFloat("sun.scale", 1.0f);
m_renderer->immediatePrimitives().emplace_back(std::in_place_type_t<RenderQuad>(), TexturePtr(),
RenderVertex{start + Vec2F(std::cos(angle + width), std::sin(angle + width)) * length, {}, Vec4B(RayColor, 0), 0.0f},
RenderVertex{start + Vec2F(std::cos(angle + width), std::sin(angle + width)) * SunRadius * pixelRatio,
RenderVertex{start + Vec2F(std::cos(angle + width), std::sin(angle + width)) * length, {}, Vec4B(rayColor, 0), 0.0f},
RenderVertex{start + Vec2F(std::cos(angle + width), std::sin(angle + width)) * SunRadius * sunScale * pixelRatio,
{},
Vec4B(RayColor,
Vec4B(rayColor,
(int)(RayMinUnscaledAlpha + std::abs(m_rayPerlin.get(angle * 896 + time * 30) * RayUnscaledAlphaVariance))
* sum
* alpha), 0.0f},
RenderVertex{start + Vec2F(std::cos(angle), std::sin(angle)) * SunRadius * pixelRatio,
RenderVertex{start + Vec2F(std::cos(angle), std::sin(angle)) * SunRadius * sunScale * pixelRatio,
{},
Vec4B(RayColor,
Vec4B(rayColor,
(int)(RayMinUnscaledAlpha + std::abs(m_rayPerlin.get(angle * 626 + time * 30) * RayUnscaledAlphaVariance))
* sum
* alpha), 0.0f},
RenderVertex{start + Vec2F(std::cos(angle), std::sin(angle)) * length, {}, Vec4B(RayColor, 0), 0.0f});
RenderVertex{start + Vec2F(std::cos(angle), std::sin(angle)) * length, {}, Vec4B(rayColor, 0), 0.0f});
}
void EnvironmentPainter::drawOrbiter(float pixelRatio, Vec2F const& screenSize, SkyRenderData const& sky, SkyOrbiter const& orbiter) {

View File

@ -66,10 +66,13 @@ void WorldPainter::render(WorldRenderData& renderData, function<void()> lightWai
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);
if (renderData.skyRenderData.type != SkyType::Atmosphereless)
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(orbiterAndPlanetRatio, Vec2F(m_camera.screenSize()), renderData.skyRenderData);
if (renderData.skyRenderData.type == SkyType::Atmosphereless)
m_environmentPainter->renderBackOrbiters(orbiterAndPlanetRatio, Vec2F(m_camera.screenSize()), renderData.skyRenderData);
m_renderer->flush();