Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make HDR flare and planet dot sizes configurable #392

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions plugins/csp-trajectories/src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ void from_json(nlohmann::json const& j, Plugin::Settings& o) {
cs::core::Settings::deserialize(j, "enableLDRFlares", o.mEnableLDRFlares);
cs::core::Settings::deserialize(j, "enableHDRFlares", o.mEnableHDRFlares);
cs::core::Settings::deserialize(j, "enablePlanetMarks", o.mEnablePlanetMarks);
cs::core::Settings::deserialize(j, "hdrFlareScale", o.mHDRFlareScale);
cs::core::Settings::deserialize(j, "planetMarkScale", o.mPlanetMarkScale);
}

void to_json(nlohmann::json& j, Plugin::Settings const& o) {
Expand All @@ -85,6 +87,8 @@ void to_json(nlohmann::json& j, Plugin::Settings const& o) {
cs::core::Settings::serialize(j, "enableLDRFlares", o.mEnableLDRFlares);
cs::core::Settings::serialize(j, "enableHDRFlares", o.mEnableHDRFlares);
cs::core::Settings::serialize(j, "enablePlanetMarks", o.mEnablePlanetMarks);
cs::core::Settings::serialize(j, "hdrFlareScale", o.mHDRFlareScale);
cs::core::Settings::serialize(j, "planetMarkScale", o.mPlanetMarkScale);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -180,7 +184,7 @@ void Plugin::update() {
};

// Trajectory dots as well as the HDR flares should be constant in size on screen. Therefore, we
// have to compute thei solid angle based on the current field of view.
// have to compute their solid angle based on the current field of view.
VistaTransformMatrix proj =
GetVistaSystem()->GetDisplayManager()->GetCurrentRenderInfo()->m_matProjection;
float fov2 = std::pow(std::min(std::atan(1.F / proj[1][1]), std::atan(1.F / proj[0][0])), 2.F);
Expand All @@ -189,7 +193,9 @@ void Plugin::update() {
bool dotsEnabled = mPluginSettings->mEnablePlanetMarks.get();
for (auto const& dot : mTrajectoryDots) {
if (updateVisibility(dot, dotsEnabled)) {
dot->pSolidAngle = 0.0002F * fov2;
double dotScale =
mPluginSettings->mPlanetMarkScale.get() * mPluginSettings->mPlanetMarkScale.get();
dot->pSolidAngle = 0.0002F * fov2 * static_cast<float>(dotScale);
}
}

Expand Down Expand Up @@ -237,8 +243,11 @@ void Plugin::update() {
double bodySolidAngle =
4.0 * glm::pi<double>() * std::pow(std::sin(bodyAngularSize * 0.5), 2.0);

double maxSolidAngle = 0.005 * fov2; // The flare will not get larger than this.
double minSolidAngle = 0.00005 * fov2; // The flare will not get smaller than this.
double flareScale =
mPluginSettings->mHDRFlareScale.get() * mPluginSettings->mHDRFlareScale.get();
double maxSolidAngle = 0.005 * fov2 * flareScale; // The flare will not get larger than this.
double minSolidAngle =
0.00005 * fov2 * flareScale; // The flare will not get smaller than this.

// We make the flare a bit larger than the body to ensure that it covers the body completely.
double flareSolidAngle = glm::clamp(bodySolidAngle * 1.2, minSolidAngle, maxSolidAngle);
Expand All @@ -249,7 +258,7 @@ void Plugin::update() {
// out between fadeEndSolidAngle and maxSolidAngle.
if (object->getIsBodyVisible()) {
// The flare is faded out between fadeEndSolidAngle and maxSolidAngle.
double fadeEndSolidAngle = 0.0005 * fov2;
double fadeEndSolidAngle = 0.0005 * fov2 * flareScale;

alpha = glm::clamp(
1.0 - (flareSolidAngle - fadeEndSolidAngle) / (maxSolidAngle - fadeEndSolidAngle), 0.0,
Expand Down
6 changes: 6 additions & 0 deletions plugins/csp-trajectories/src/Plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class Plugin : public cs::core::PluginBase {

/// Toggles dots at runtime.
cs::utils::DefaultProperty<bool> mEnablePlanetMarks{true};

/// Scaling factor for HDR flares.
cs::utils::DefaultProperty<double> mHDRFlareScale{1.0};

/// Scaling factor for dots.
cs::utils::DefaultProperty<double> mPlanetMarkScale{1.0};
};

void init() override;
Expand Down
Loading