mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-04 01:39:47 -05:00
Added Eclipses for NewAtmosphere (Missing change spaces for precision).
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*****************************************************************************************
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
@@ -59,6 +59,7 @@
|
||||
*/
|
||||
|
||||
#include <modules/atmosphere/rendering/atmospheredeferredcaster.h>
|
||||
#include <modules/atmosphere/rendering/renderableatmosphere.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/opengl/ghoul_gl.h>
|
||||
@@ -150,9 +151,10 @@ AtmosphereDeferredcaster::AtmosphereDeferredcaster()
|
||||
, _exposureConstant(0.4f)
|
||||
, _exposureBackgroundConstant(1.8f)
|
||||
, _gammaConstant(1.8f)
|
||||
, _hardShadowsEnabled(false)
|
||||
, _renderableClass(NoRenderableClass)
|
||||
, _calculationTextureScale(1.0)
|
||||
, _saveCalculationTextures(false)
|
||||
, _saveCalculationTextures(false)
|
||||
|
||||
|
||||
{}
|
||||
@@ -240,6 +242,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, const De
|
||||
// Object Space
|
||||
glm::dmat4 inverseModelMatrix = glm::inverse(_modelTransform);
|
||||
program.setUniform("dInverseModelTransformMatrix", inverseModelMatrix);
|
||||
program.setUniform("dModelTransformMatrix", _modelTransform);
|
||||
|
||||
// The following scale comes from PSC transformations.
|
||||
float fScaleFactor = renderData.camera.scaling().x * pow(10.0, renderData.camera.scaling().y);
|
||||
@@ -288,6 +291,82 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, const De
|
||||
program.setUniform("sunDirectionObj", glm::normalize(glm::dvec3(sunPosObj)));
|
||||
|
||||
program.setUniform("ellipsoidRadii", _ellipsoidRadii);
|
||||
|
||||
// Shadow calculations..
|
||||
if (!_shadowConfArray.empty()) {
|
||||
std::vector<ShadowRenderingStruct> shadowDataArray;
|
||||
shadowDataArray.reserve(_shadowConfArray.size());
|
||||
|
||||
for (const auto & shadowConf : _shadowConfArray) {
|
||||
// TO REMEMBER: all distances and lengths in world coordinates are in meters!!! We need to move this to view space...
|
||||
// Getting source and caster:
|
||||
glm::dvec3 sourcePos = SpiceManager::ref().targetPosition(shadowConf.source.first, "SUN", "GALACTIC", {}, _time, lt);
|
||||
sourcePos *= 1000.0; // converting to meters
|
||||
glm::dvec3 casterPos = SpiceManager::ref().targetPosition(shadowConf.caster.first, "SUN", "GALACTIC", {}, _time, lt);
|
||||
casterPos *= 1000.0; // converting to meters
|
||||
psc caster_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(casterPos.x, casterPos.y, casterPos.z);
|
||||
|
||||
|
||||
// First we determine if the caster is shadowing the current planet (all calculations in World Coordinates):
|
||||
glm::vec3 planetCasterVec = (caster_pos - renderData.position).vec3();
|
||||
glm::vec3 sourceCasterVec = glm::vec3(casterPos - sourcePos);
|
||||
float sc_length = glm::length(sourceCasterVec);
|
||||
glm::vec3 planetCaster_proj = (glm::dot(planetCasterVec, sourceCasterVec) / (sc_length*sc_length)) * sourceCasterVec;
|
||||
float d_test = glm::length(planetCasterVec - planetCaster_proj);
|
||||
float xp_test = shadowConf.caster.second * sc_length / (shadowConf.source.second + shadowConf.caster.second);
|
||||
float rp_test = shadowConf.caster.second * (glm::length(planetCaster_proj) + xp_test) / xp_test;
|
||||
|
||||
float casterDistSun = glm::length(casterPos);
|
||||
float planetDistSun = glm::length(renderData.position.vec3());
|
||||
|
||||
ShadowRenderingStruct shadowData;
|
||||
shadowData.isShadowing = false;
|
||||
|
||||
if (((d_test - rp_test) < (_atmospherePlanetRadius * 1000.0)) &&
|
||||
//if (((d_test - rp_test) < (_atmosphereRadius * 1000.0)) &&
|
||||
(casterDistSun < planetDistSun)) {
|
||||
// The current caster is shadowing the current planet
|
||||
shadowData.isShadowing = true;
|
||||
shadowData.rs = shadowConf.source.second;
|
||||
shadowData.rc = shadowConf.caster.second;
|
||||
shadowData.sourceCasterVec = sourceCasterVec;
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu = shadowData.rc * sc_length / (shadowData.rs - shadowData.rc);
|
||||
shadowData.casterPositionVec = glm::vec3(casterPos);
|
||||
}
|
||||
shadowDataArray.push_back(shadowData);
|
||||
}
|
||||
|
||||
const std::string uniformVarName("shadowDataArray[");
|
||||
unsigned int counter = 0;
|
||||
for (const auto & sd : shadowDataArray) {
|
||||
std::stringstream ss;
|
||||
ss << uniformVarName << counter << "].isShadowing";
|
||||
program.setUniform(ss.str(), sd.isShadowing);
|
||||
if (sd.isShadowing) {
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].xp";
|
||||
program.setUniform(ss.str(), sd.xp);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].xu";
|
||||
program.setUniform(ss.str(), sd.xu);
|
||||
/*ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].rs";
|
||||
program.setUniform(ss.str(), sd.rs);*/
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].rc";
|
||||
program.setUniform(ss.str(), sd.rc);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].sourceCasterVec";
|
||||
program.setUniform(ss.str(), sd.sourceCasterVec);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].casterPositionVec";
|
||||
program.setUniform(ss.str(), sd.casterPositionVec);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
program.setUniform("hardShadows", _hardShadowsEnabled);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -411,6 +490,15 @@ void AtmosphereDeferredcaster::setRenderableClass(const AtmosphereDeferredcaster
|
||||
_renderableClass = rc;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setHardShadows(const bool enabled) {
|
||||
_hardShadowsEnabled = enabled;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setShadowConfigArray(
|
||||
const std::vector<ShadowConfiguration>& shadowConfigArray) {
|
||||
_shadowConfArray = shadowConfigArray;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::enableSunFollowing(const bool enable) {
|
||||
_sunFollowingCameraEnabled = enable;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*****************************************************************************************
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <openspace/rendering/deferredcaster.h>
|
||||
#include <ghoul/opengl/textureunit.h>
|
||||
|
||||
//#include <ghoul/opengl/textureunit.h>
|
||||
//#include <modules/atmosphere/rendering/renderableatmosphere.h>
|
||||
|
||||
namespace ghoul::opengl {
|
||||
class Texture;
|
||||
@@ -43,6 +43,7 @@ namespace openspace {
|
||||
|
||||
struct RenderData;
|
||||
struct DeferredcastData;
|
||||
struct ShadowConfiguration;
|
||||
|
||||
class AtmosphereDeferredcaster : public Deferredcaster {
|
||||
public:
|
||||
@@ -89,6 +90,8 @@ public:
|
||||
void setMieExtinctionCoefficients(const glm::vec3 & mieExtCoeff);
|
||||
void setEllipsoidRadii(const glm::dvec3 & radii);
|
||||
void setRenderableClass(const AtmosphereDeferredcaster::AtmospherRenderableClass rc);
|
||||
void setShadowConfigArray(const std::vector<ShadowConfiguration>& shadowConfigArray);
|
||||
void setHardShadows(const bool enabled);
|
||||
void enableSunFollowing(const bool enable);
|
||||
|
||||
void setPrecalculationTextureScale(const float _preCalculatedTexturesScale);
|
||||
@@ -192,6 +195,10 @@ private:
|
||||
float _stepSize;
|
||||
double _time;
|
||||
|
||||
// Eclipse Shadows
|
||||
std::vector<ShadowConfiguration> _shadowConfArray;
|
||||
bool _hardShadowsEnabled;
|
||||
|
||||
// Atmosphere Debugging
|
||||
float _calculationTextureScale;
|
||||
bool _saveCalculationTextures;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*****************************************************************************************
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
@@ -215,6 +215,12 @@ namespace {
|
||||
"Enable Sun On Camera Position",
|
||||
"" // @TODO Missing documentation
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo EclipseHardShadowsInfo = {
|
||||
"EclipseHardShadowsInfo",
|
||||
"Enable Hard Shadows for Eclipses",
|
||||
"" // @TODO Missing documentation
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -268,6 +274,7 @@ namespace openspace {
|
||||
, _hdrExpositionP(AtmosphereExposureInfo, 0.4f, 0.01f, 5.0f)
|
||||
, _gammaConstantP(AtmosphereGammaInfo, 1.8f, 0.1f, 3.0f)
|
||||
, _sunFollowingCameraEnabledP(EnableSunOnCameraPositionInfo, false)
|
||||
, _hardShadowsEnabledP(EclipseHardShadowsInfo, false)
|
||||
, _atmosphereEnabled(false)
|
||||
, _ozoneLayerEnabled(false)
|
||||
, _sunFollowingCameraEnabled(false)
|
||||
@@ -289,6 +296,7 @@ namespace openspace {
|
||||
, _saveCalculationsToTexture(false)
|
||||
, _preCalculatedTexturesScale(1.0)
|
||||
, _shadowEnabled(false)
|
||||
, _hardShadows(false)
|
||||
, _time(0.f)
|
||||
{
|
||||
ghoul_precondition(
|
||||
@@ -312,7 +320,7 @@ namespace openspace {
|
||||
bool disableShadows = false;
|
||||
if (success) {
|
||||
std::vector<std::pair<std::string, float>> sourceArray;
|
||||
unsigned int sourceCounter = 1;
|
||||
unsigned int sourceCounter = 1;
|
||||
while (success) {
|
||||
std::string sourceName;
|
||||
success = shadowDictionary.getValue(keyShadowSource +
|
||||
@@ -618,6 +626,12 @@ namespace openspace {
|
||||
_sunFollowingCameraEnabledP = _sunFollowingCameraEnabled;
|
||||
_sunFollowingCameraEnabledP.onChange([this](){ updateAtmosphereParameters(); });
|
||||
addProperty(_sunFollowingCameraEnabledP);
|
||||
|
||||
_hardShadowsEnabledP = _hardShadows;
|
||||
_hardShadowsEnabledP.onChange([this]() { updateAtmosphereParameters(); });
|
||||
if (_shadowEnabled) {
|
||||
addProperty(_hardShadowsEnabledP);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -653,6 +667,11 @@ namespace openspace {
|
||||
if (_saveCalculationsToTexture)
|
||||
_deferredcaster->enablePrecalculationTexturesSaving();
|
||||
|
||||
if (_shadowEnabled) {
|
||||
_deferredcaster->setShadowConfigArray(_shadowConfArray);
|
||||
_deferredcaster->setHardShadows(_hardShadows);
|
||||
}
|
||||
|
||||
_deferredcaster->initialize();
|
||||
}
|
||||
|
||||
@@ -720,7 +739,8 @@ namespace openspace {
|
||||
_hdrConstant != _hdrExpositionP ||
|
||||
_exposureBackgroundConstant != OsEng.renderEngine().renderer()->hdrBackground() ||
|
||||
_gammaConstant != _gammaConstantP ||
|
||||
_sunFollowingCameraEnabled != _sunFollowingCameraEnabledP) {
|
||||
_sunFollowingCameraEnabled != _sunFollowingCameraEnabledP ||
|
||||
_hardShadows != _hardShadowsEnabledP) {
|
||||
executeComputation = false;
|
||||
}
|
||||
|
||||
@@ -745,6 +765,7 @@ namespace openspace {
|
||||
_exposureBackgroundConstant = OsEng.renderEngine().renderer()->hdrBackground();
|
||||
_gammaConstant = _gammaConstantP;
|
||||
_sunFollowingCameraEnabled = _sunFollowingCameraEnabledP;
|
||||
_hardShadows = _hardShadowsEnabledP;
|
||||
|
||||
|
||||
if (_deferredcaster) {
|
||||
@@ -767,8 +788,13 @@ namespace openspace {
|
||||
_deferredcaster->setRenderableClass(_atmosphereType);
|
||||
_deferredcaster->enableSunFollowing(_sunFollowingCameraEnabled);
|
||||
//_deferredcaster->setEllipsoidRadii(_ellipsoid.radii());
|
||||
|
||||
if (_shadowEnabled) {
|
||||
_deferredcaster->setHardShadows(_hardShadows);
|
||||
}
|
||||
|
||||
if (executeComputation)
|
||||
_deferredcaster->preCalculateAtmosphereParam();
|
||||
}
|
||||
}
|
||||
} // namespace openspace
|
||||
} // namespace openspace
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*****************************************************************************************
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
@@ -52,6 +52,22 @@ class AtmosphereDeferredcaster;
|
||||
|
||||
struct TransformData;
|
||||
|
||||
// Shadow structure
|
||||
struct ShadowConfiguration {
|
||||
std::pair<std::string, float> source;
|
||||
std::pair<std::string, float> caster;
|
||||
};
|
||||
|
||||
struct ShadowRenderingStruct {
|
||||
float xu,
|
||||
xp;
|
||||
float rs,
|
||||
rc;
|
||||
glm::vec3 sourceCasterVec;
|
||||
glm::vec3 casterPositionVec;
|
||||
bool isShadowing;
|
||||
};
|
||||
|
||||
namespace planetgeometry {
|
||||
class PlanetGeometry;
|
||||
}
|
||||
@@ -60,22 +76,7 @@ namespace documentation { struct Documentation; }
|
||||
namespace planetgeometry { class PlanetGeometry; }
|
||||
|
||||
class RenderableAtmosphere : public Renderable {
|
||||
public:
|
||||
// Shadow structure
|
||||
struct ShadowConfiguration {
|
||||
std::pair<std::string, float> source;
|
||||
std::pair<std::string, float> caster;
|
||||
};
|
||||
|
||||
struct ShadowRenderingStruct {
|
||||
float xu,
|
||||
xp;
|
||||
float rs,
|
||||
rc;
|
||||
glm::vec3 sourceCasterVec;
|
||||
glm::vec3 casterPositionVec;
|
||||
bool isShadowing;
|
||||
};
|
||||
public:
|
||||
|
||||
RenderableAtmosphere(const ghoul::Dictionary& dictionary);
|
||||
|
||||
@@ -115,10 +116,11 @@ private:
|
||||
properties::FloatProperty _hdrExpositionP;
|
||||
properties::FloatProperty _gammaConstantP;
|
||||
properties::BoolProperty _sunFollowingCameraEnabledP;
|
||||
properties::BoolProperty _hardShadowsEnabledP;
|
||||
|
||||
bool _atmosphereEnabled;
|
||||
bool _ozoneLayerEnabled;
|
||||
bool _sunFollowingCameraEnabled;
|
||||
bool _sunFollowingCameraEnabled;
|
||||
float _atmosphereRadius;
|
||||
float _atmospherePlanetRadius;
|
||||
float _planetAverageGroundReflectance;
|
||||
@@ -143,6 +145,7 @@ private:
|
||||
std::unique_ptr<AtmosphereDeferredcaster> _deferredcaster;
|
||||
|
||||
bool _shadowEnabled;
|
||||
bool _hardShadows;
|
||||
double _time;
|
||||
|
||||
glm::dmat3 _stateMatrix;
|
||||
|
||||
Reference in New Issue
Block a user