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

Advanced eclipses #395

Open
wants to merge 154 commits into
base: main
Choose a base branch
from
Open

Advanced eclipses #395

wants to merge 154 commits into from

Conversation

Schneegans
Copy link
Member

@Schneegans Schneegans commented Jan 5, 2025

This PR brings two major contributions:

  1. The atmosphere now supports refraction. This deforms the Sun in Earth's atmosphere when it is close to the horizon. When observed from space, the sunset can turn into a glowing red ring around Earth.
  2. Eclipse shadows now consider the atmosphere of the occluder. This is used for Earth and Mars. As light is refracted through the atmosphere, the shadow is not completely dark anymore. Instead, some copper-red light is now shed on the Moon during a lunar eclipse.

Copy link

github-actions bot commented Jan 5, 2025

Pull Request Test Coverage Report for Build 12936162460

Details

  • 0 of 191 (0.0%) changed or added relevant lines in 8 files are covered.
  • 13 unchanged lines in 4 files lost coverage.
  • Overall coverage decreased (-0.004%) to 1.162%

Changes Missing Coverage Covered Lines Changed/Added Lines %
plugins/csp-atmospheres/src/Atmosphere.hpp 0 1 0.0%
plugins/csp-atmospheres/src/models/bruneton/Metadata.cpp 0 1 0.0%
src/cs-core/GraphicsEngine.cpp 0 1 0.0%
plugins/csp-atmospheres/src/Plugin.cpp 0 11 0.0%
src/cs-graphics/TextureLoader.cpp 0 14 0.0%
plugins/csp-atmospheres/src/models/bruneton/Model.cpp 0 23 0.0%
plugins/csp-atmospheres/src/utils.cpp 0 50 0.0%
plugins/csp-atmospheres/src/Atmosphere.cpp 0 90 0.0%
Files with Coverage Reduction New Missed Lines %
plugins/csp-atmospheres/src/models/bruneton/Metadata.cpp 1 0.0%
plugins/csp-atmospheres/src/Plugin.cpp 1 0.0%
plugins/csp-atmospheres/src/Atmosphere.hpp 1 0.0%
plugins/csp-atmospheres/src/Atmosphere.cpp 10 0.0%
Totals Coverage Status
Change from base Build 12930409464: -0.004%
Covered Lines: 193
Relevant Lines: 16605

💛 - Coveralls

@Schneegans Schneegans marked this pull request as ready for review January 17, 2025 19:12
@Schneegans Schneegans requested a review from JonasGilg January 17, 2025 19:12
@Schneegans Schneegans added this to the Version 1.10.0 milestone Jan 22, 2025
Copy link
Member

@JonasGilg JonasGilg left a comment

Choose a reason for hiding this comment

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

Great work, I only found minor code style issues,

Comment on lines +62 to +96
// Computes the refractive index of a gas at a given wavelength (in m), pressure (in Pa), and
// temperature (in K).
double getIoR(GasType type, double lambda, double pressure, double temperature) {
double mu2 = std::pow(lambda * 1e6, -2.0);
double n0 = 1.0;

switch (type) {
// E. R. Peck and B. N. Khanna. Dispersion of nitrogen
case GasType::eNitrogen:
n0 = 1.0 + 6.8552e-5 + 3.243157e-2 / (144 - mu2);
break;

// J. Zhang, Z. H. Lu, and L. J. Wang. Precision refractive index measurements of air, N2, O2,
// Ar, and CO2 with a frequency comb. This is given at 20°C.
case GasType::eOxygen:
n0 = 1.0 + 1.181494e-4 + 9.708931e-3 / (75.4 - mu2);
n0 = 1.0 + (n0 - 1) * 293.15 / 273; // Correct for the actual temperature.
break;

// E. R. Peck and D. J. Fisher. Dispersion of argon
case GasType::eArgon:
n0 = 1.0 + 6.7867e-5 + 3.0182943e-2 / (144 - mu2);
break;

// J. G. Old, K. L. Gentili, and E. R. Peck. Dispersion of Carbon Dioxide
case GasType::eCarbonDioxide:
n0 = 1.0 + 0.00000154489 / (0.0584738 - mu2) + 0.083091927 / (210.9241 - mu2) +
0.0028764190 / (60.122959 - mu2);
break;
}

// The pressure is given in Pa, the temperature in K. The IoR above is measured at STP (273 K,
// 101325 Pa). We need to correct for the actual pressure and temperature.
return 1.0 + (n0 - 1.0) * pressure / temperature * 273 / 101325.0;
}
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be more future proof, to read in the parameters for each gas from config files? This would make adding new gases easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I guess we could do this. But this code is currently not strictly required anyways, as we do not support wavelength-dependent refractive indices. It's just quite cool for future reference, I think.

Comment on lines +229 to +235
bool RefractionSupported() {
#if USE_REFRACTION
return true;
#else
return false;
#endif
}
Copy link
Member

Choose a reason for hiding this comment

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

Why use a function instead of a constant? A function call is more overhead (although the compiler will most likely optimize it away).

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the model shader is linked to the main atmosphere shader which needs to know whether the model supports refraction. I think I cannot read a constant from a linked shader, or can I?


////////////////////////////////////////////////////////////////////////////////////////////////////

std::tuple<GLuint, int32_t, int32_t> read2DTexture(std::string const& path) {
Copy link
Member

Choose a reason for hiding this comment

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

I think a tuple is not a good return type here. Since it is not clear to the caller, what each element is representing. The documentation in the header file also doesn't explain this. Only the return in the implementation can give a glimpse.

I think a better return type would either be a std::pair<GLuint, ivec2> or a custom type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.


////////////////////////////////////////////////////////////////////////////////////////////////////

std::tuple<GLuint, int32_t, int32_t, int32_t> read3DTexture(std::string const& path) {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 16 to 17
std::tuple<GLuint, int32_t, int32_t> read2DTexture(std::string const& path);
std::tuple<GLuint, int32_t, int32_t, int32_t> read3DTexture(std::string const& path);
Copy link
Member

Choose a reason for hiding this comment

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

See CPP file for comment on return types.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

tools/eclipse-shadow-generator/advanced_modes.cu Outdated Show resolved Hide resolved
tools/eclipse-shadow-generator/advanced_modes.cu Outdated Show resolved Hide resolved
tools/eclipse-shadow-generator/advanced_modes.cu Outdated Show resolved Hide resolved
tools/eclipse-shadow-generator/advanced_modes.cu Outdated Show resolved Hide resolved
const float D = 0.20;
const float E = 0.02;
const float F = 0.30;
return ((c * (A * c + C * B) + D * E) / (c * (A * c + B) + D * F)) - E / F;
Copy link
Member

Choose a reason for hiding this comment

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

It is hard to read with having an upper and lower case c in the same equation. Maybe use UVWXYZ or write color instead of c.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@Schneegans Schneegans requested a review from JonasGilg January 23, 2025 19:02
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.

2 participants