mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-12 22:50:13 -06:00
569 lines
27 KiB
C++
569 lines
27 KiB
C++
/*****************************************************************************************
|
|
* *
|
|
* OpenSpace *
|
|
* *
|
|
* Copyright (c) 2014-2017 *
|
|
* *
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
|
* software and associated documentation files (the "Software"), to deal in the Software *
|
|
* without restriction, including without limitation the rights to use, copy, modify, *
|
|
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
|
* permit persons to whom the Software is furnished to do so, subject to the following *
|
|
* conditions: *
|
|
* *
|
|
* The above copyright notice and this permission notice shall be included in all copies *
|
|
* or substantial portions of the Software. *
|
|
* *
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
|
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
|
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
****************************************************************************************/
|
|
|
|
#include <modules/globebrowsing/globes/renderableglobe.h>
|
|
|
|
#include <modules/debugging/rendering/debugrenderer.h>
|
|
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
|
|
#include <modules/globebrowsing/rendering/layer/layermanager.h>
|
|
|
|
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
|
|
#include <openspace/rendering/deferredcastermanager.h>
|
|
#include <modules/atmosphere/rendering/atmospheredeferredcaster.h>
|
|
#include <openspace/engine/configurationmanager.h>
|
|
#include <openspace/engine/openspaceengine.h>
|
|
#include <openspace/rendering/renderengine.h>
|
|
#endif
|
|
|
|
namespace {
|
|
const char* keyFrame = "Frame";
|
|
const char* keyRadii = "Radii";
|
|
const char* keyInteractionDepthBelowEllipsoid = "InteractionDepthBelowEllipsoid";
|
|
const char* keyCameraMinHeight = "CameraMinHeight";
|
|
const char* keySegmentsPerPatch = "SegmentsPerPatch";
|
|
const char* keyLayers = "Layers";
|
|
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
|
|
const std::string keyATMDebug = "Debug";
|
|
const std::string keyTextureScale = "PreCalculatedTextureScale";
|
|
const std::string keySaveTextures = "SaveCalculatedTextures";
|
|
const std::string keyAtmosphere = "Atmosphere";
|
|
const std::string keyAtmosphereRadius = "AtmoshereRadius";
|
|
const std::string keyPlanetRadius = "PlanetRadius";
|
|
const std::string keyAverageGroundReflectance = "PlanetAverageGroundReflectance";
|
|
const std::string keyRayleigh = "Rayleigh";
|
|
const std::string keyRayleighHeightScale = "H_R";
|
|
const std::string keyMie = "Mie";
|
|
const std::string keyMieHeightScale = "H_M";
|
|
const std::string keyMiePhaseConstant = "G";
|
|
#endif
|
|
}
|
|
|
|
namespace openspace {
|
|
|
|
using namespace properties;
|
|
|
|
namespace globebrowsing {
|
|
|
|
RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
|
|
: _debugProperties({
|
|
BoolProperty("saveOrThrowCamera", "save or throw camera", false),
|
|
BoolProperty("showChunkEdges", "show chunk edges", false),
|
|
BoolProperty("showChunkBounds", "show chunk bounds", false),
|
|
BoolProperty("showChunkAABB", "show chunk AABB", false),
|
|
BoolProperty("showHeightResolution", "show height resolution", false),
|
|
BoolProperty("showHeightIntensities", "show height intensities", false),
|
|
BoolProperty("performFrustumCulling", "perform frustum culling", true),
|
|
BoolProperty("performHorizonCulling", "perform horizon culling", true),
|
|
BoolProperty("levelByProjectedAreaElseDistance", "level by projected area (else distance)", true),
|
|
BoolProperty("resetTileProviders", "reset tile providers", false),
|
|
BoolProperty("toggleEnabledEveryFrame", "toggle enabled every frame", false),
|
|
BoolProperty("collectStats", "collect stats", false),
|
|
BoolProperty("limitLevelByAvailableData", "Limit level by available data", true),
|
|
IntProperty("modelSpaceRenderingCutoffLevel", "Model Space Rendering Cutoff Level", 10, 1, 22)
|
|
})
|
|
, _generalProperties({
|
|
BoolProperty("enabled", "Enabled", true),
|
|
BoolProperty("performShading", "perform shading", true),
|
|
BoolProperty("atmosphere", "atmosphere", false),
|
|
FloatProperty("lodScaleFactor", "lodScaleFactor",10.0f, 1.0f, 50.0f),
|
|
FloatProperty("cameraMinHeight", "cameraMinHeight", 100.0f, 0.0f, 1000.0f)
|
|
})
|
|
, _debugPropertyOwner("Debug")
|
|
, _texturePropertyOwner("Textures")
|
|
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
|
|
, _atmosphereProperties({
|
|
FloatProperty("atmmosphereHeight", "Atmosphere Height (KM)", 60.0f, 0.1f, 99.0f),
|
|
FloatProperty("averageGroundReflectance", "Average Ground Reflectance (%)", 0.1f, 0.0f, 1.0f),
|
|
FloatProperty("rayleighHeightScale", "Rayleigh Height Scale (KM)", 8.0f, 0.1f, 20.0f),
|
|
FloatProperty("rayleighScatteringCoeffX", "Rayleigh Scattering Coeff X (x10e-3)", 1.0f, 0.01f, 100.0f),
|
|
FloatProperty("rayleighScatteringCoeffY", "Rayleigh Scattering Coeff Y (x10e-3)", 1.0f, 0.01f, 100.0f),
|
|
FloatProperty("rayleighScatteringCoeffZ", "Rayleigh Scattering Coeff Z (x10e-3)", 1.0f, 0.01f, 100.0f),
|
|
FloatProperty("mieHeightScale", "Mie Height Scale (KM)", 1.2f, 0.1f, 20.0f),
|
|
FloatProperty("mieScatteringCoefficient", "Mie Scattering Coefficient (x10e-3)", 4.0f, 0.01f, 1000.0f),
|
|
FloatProperty("mieScatteringExtinctionPropCoefficient",
|
|
"Mie Scattering/Extinction Proportion Coefficient (%)", 0.9f, 0.01f, 1.0f),
|
|
FloatProperty("mieAsymmetricFactorG", "Mie Asymmetric Factor G", 0.85f, -1.0f, 1.0f),
|
|
FloatProperty("sunIntensity", "Sun Intensity", 50.0f, 0.1f, 1000.0f),
|
|
FloatProperty("hdrExposition", "HDR", 0.4f, 0.01f, 5.0f)
|
|
})
|
|
, _atmospherePropertyOwner("Atmosphere")
|
|
, _atmosphereRadius(0.f)
|
|
, _atmospherePlanetRadius(0.f)
|
|
, _planetAverageGroundReflectance(0.f)
|
|
, _rayleighHeightScale(0.f)
|
|
, _mieHeightScale(0.f)
|
|
, _miePhaseConstant(0.f)
|
|
, _mieExtinctionCoeff(glm::vec3(0.f))
|
|
, _rayleighScatteringCoeff(glm::vec3(0.f))
|
|
, _mieScatteringCoeff(glm::vec3(0.f))
|
|
, _sunRadianceIntensity(50.0f)
|
|
, _hdrConstant(0.4f)
|
|
, _atmosphereEnabled(false)
|
|
, _saveCalculationsToTexture(false)
|
|
, _preCalculatedTexturesScale(1.0)
|
|
#endif
|
|
{
|
|
setName("RenderableGlobe");
|
|
|
|
dictionary.getValue(keyFrame, _frame);
|
|
|
|
// Read the radii in to its own dictionary
|
|
glm::dvec3 radii;
|
|
dictionary.getValue(keyRadii, radii);
|
|
_ellipsoid = Ellipsoid(radii);
|
|
setBoundingSphere(_ellipsoid.averageRadius());
|
|
|
|
// Ghoul can't read ints from lua dictionaries...
|
|
double patchSegmentsd;
|
|
dictionary.getValue(keySegmentsPerPatch, patchSegmentsd);
|
|
int patchSegments = patchSegmentsd;
|
|
|
|
if (!dictionary.getValue(keyInteractionDepthBelowEllipsoid,
|
|
_interactionDepthBelowEllipsoid)) {
|
|
_interactionDepthBelowEllipsoid = 0;
|
|
}
|
|
|
|
float cameraMinHeight;
|
|
dictionary.getValue(keyCameraMinHeight, cameraMinHeight);
|
|
_generalProperties.cameraMinHeight.set(cameraMinHeight);
|
|
|
|
// Init layer manager
|
|
ghoul::Dictionary layersDictionary;
|
|
if (!dictionary.getValue(keyLayers, layersDictionary)) {
|
|
throw ghoul::RuntimeError(
|
|
std::string(keyLayers) + " must be specified specified!");
|
|
}
|
|
|
|
_layerManager = std::make_shared<LayerManager>(layersDictionary);
|
|
|
|
_chunkedLodGlobe = std::make_shared<ChunkedLodGlobe>(
|
|
*this, patchSegments, _layerManager);
|
|
|
|
// This distance will be enough to render the globe as one pixel if the field of
|
|
// view is 'fov' radians and the screen resolution is 'res' pixels.
|
|
double fov = 2 * glm::pi<double>() / 6; // 60 degrees
|
|
int res = 2880;
|
|
double distance = res * _ellipsoid.maximumRadius() / tan(fov / 2);
|
|
_distanceSwitch.addSwitchValue(_chunkedLodGlobe, distance);
|
|
|
|
addProperty(_generalProperties.isEnabled);
|
|
addProperty(_generalProperties.atmosphereEnabled);
|
|
addProperty(_generalProperties.performShading);
|
|
addProperty(_generalProperties.lodScaleFactor);
|
|
addProperty(_generalProperties.cameraMinHeight);
|
|
|
|
_debugPropertyOwner.addProperty(_debugProperties.saveOrThrowCamera);
|
|
_debugPropertyOwner.addProperty(_debugProperties.showChunkEdges);
|
|
_debugPropertyOwner.addProperty(_debugProperties.showChunkBounds);
|
|
_debugPropertyOwner.addProperty(_debugProperties.showChunkAABB);
|
|
_debugPropertyOwner.addProperty(_debugProperties.showHeightResolution);
|
|
_debugPropertyOwner.addProperty(_debugProperties.showHeightIntensities);
|
|
_debugPropertyOwner.addProperty(_debugProperties.performFrustumCulling);
|
|
_debugPropertyOwner.addProperty(_debugProperties.performHorizonCulling);
|
|
_debugPropertyOwner.addProperty(
|
|
_debugProperties.levelByProjectedAreaElseDistance
|
|
);
|
|
_debugPropertyOwner.addProperty(_debugProperties.resetTileProviders);
|
|
_debugPropertyOwner.addProperty(_debugProperties.toggleEnabledEveryFrame);
|
|
_debugPropertyOwner.addProperty(_debugProperties.collectStats);
|
|
_debugPropertyOwner.addProperty(_debugProperties.limitLevelByAvailableData);
|
|
_debugPropertyOwner.addProperty(_debugProperties.modelSpaceRenderingCutoffLevel);
|
|
|
|
addPropertySubOwner(_debugPropertyOwner);
|
|
addPropertySubOwner(_layerManager.get());
|
|
|
|
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
|
|
//================================================================
|
|
//========== Reads Atmosphere Entries from mod file ==============
|
|
//================================================================
|
|
bool errorReadingAtmosphereData = false;
|
|
ghoul::Dictionary atmosphereDictionary;
|
|
bool success = dictionary.getValue(keyAtmosphere, atmosphereDictionary);
|
|
if (success) {
|
|
if (!atmosphereDictionary.getValue(keyAtmosphereRadius, _atmosphereRadius)) {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Atmosphere Radius value expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
|
|
if (!atmosphereDictionary.getValue(keyPlanetRadius, _atmospherePlanetRadius)) {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Planet Radius value expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
|
|
if (!atmosphereDictionary.getValue(keyAverageGroundReflectance, _planetAverageGroundReflectance)) {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Average Atmosphere Ground Reflectance value expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
|
|
ghoul::Dictionary rayleighDictionary;
|
|
success = atmosphereDictionary.getValue(keyRayleigh, rayleighDictionary);
|
|
|
|
if (success) {
|
|
// Not using right now.
|
|
glm::vec3 rayleighWavelengths;
|
|
success = rayleighDictionary.getValue("Coefficients.Wavelengths", rayleighWavelengths);
|
|
|
|
if (!rayleighDictionary.getValue("Coefficients.Scattering", _rayleighScatteringCoeff)) {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Rayleigh Scattering parameters expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
|
|
if (!rayleighDictionary.getValue(keyRayleighHeightScale, _rayleighHeightScale)) {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Rayleigh Height Scale value expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
}
|
|
else {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Rayleigh parameters expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
|
|
ghoul::Dictionary mieDictionary;
|
|
success = atmosphereDictionary.getValue(keyMie, mieDictionary);
|
|
if (success) {
|
|
if (!mieDictionary.getValue(keyMieHeightScale, _mieHeightScale)) {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Mie Height Scale value expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
|
|
if (!mieDictionary.getValue("Coefficients.Scattering", _mieScatteringCoeff)) {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Mie Scattering parameters expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
|
|
if (!mieDictionary.getValue("Coefficients.Extinction", _mieExtinctionCoeff)) {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Mie Extinction parameters expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
|
|
if (!mieDictionary.getValue(keyMiePhaseConstant, _miePhaseConstant)) {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Mie Phase Constant value expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
}
|
|
else {
|
|
errorReadingAtmosphereData = true;
|
|
//LWARNING("No Mie parameters expecified for Atmosphere Effects of "
|
|
// << name << " planet.\nDisabling atmosphere effects for this planet.");
|
|
}
|
|
|
|
ghoul::Dictionary debugATMDictionary;
|
|
success = atmosphereDictionary.getValue(keyATMDebug, debugATMDictionary);
|
|
if (success) {
|
|
if (debugATMDictionary.getValue(keyTextureScale, _preCalculatedTexturesScale)) {
|
|
//LDEBUG("Atmosphere Texture Scaled to " << _preCalculatedTexturesScale);
|
|
}
|
|
|
|
if (debugATMDictionary.getValue(keySaveTextures, _saveCalculationsToTexture)) {
|
|
//LDEBUG("Saving Precalculated Atmosphere Textures.");
|
|
}
|
|
|
|
}
|
|
|
|
if (!errorReadingAtmosphereData) {
|
|
_atmosphereEnabled = true;
|
|
|
|
//========================================================
|
|
//============== Atmosphere Properties ===================
|
|
//========================================================
|
|
|
|
_atmosphereProperties.atmosphereHeightP.set(_atmosphereRadius - _atmospherePlanetRadius);
|
|
_atmosphereProperties.atmosphereHeightP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.atmosphereHeightP);
|
|
|
|
_atmosphereProperties.groundAverageReflectanceP.set(_planetAverageGroundReflectance);
|
|
_atmosphereProperties.groundAverageReflectanceP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.groundAverageReflectanceP);
|
|
|
|
_atmosphereProperties.rayleighHeightScaleP.set(_rayleighHeightScale);
|
|
_atmosphereProperties.rayleighHeightScaleP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.rayleighHeightScaleP);
|
|
|
|
_atmosphereProperties.rayleighScatteringCoeffXP.set(_rayleighScatteringCoeff.x * 1000.0f);
|
|
_atmosphereProperties.rayleighScatteringCoeffXP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.rayleighScatteringCoeffXP);
|
|
|
|
_atmosphereProperties.rayleighScatteringCoeffYP.set(_rayleighScatteringCoeff.y * 1000.0f);
|
|
_atmosphereProperties.rayleighScatteringCoeffYP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.rayleighScatteringCoeffYP);
|
|
|
|
_atmosphereProperties.rayleighScatteringCoeffZP.set(_rayleighScatteringCoeff.z * 1000.0f);
|
|
_atmosphereProperties.rayleighScatteringCoeffZP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.rayleighScatteringCoeffZP);
|
|
|
|
_atmosphereProperties.mieHeightScaleP.set(_mieHeightScale);
|
|
_atmosphereProperties.mieHeightScaleP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.mieHeightScaleP);
|
|
|
|
_atmosphereProperties.mieScatteringCoefficientP.set(_mieScatteringCoeff.r * 1000.0f);
|
|
_atmosphereProperties.mieScatteringCoefficientP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.mieScatteringCoefficientP);
|
|
|
|
_atmosphereProperties.mieScatteringExtinctionPropCoefficientP.set(_mieScatteringCoeff.r / _mieExtinctionCoeff.r);
|
|
_atmosphereProperties.mieScatteringExtinctionPropCoefficientP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.mieScatteringExtinctionPropCoefficientP);
|
|
|
|
_atmosphereProperties.mieAsymmetricFactorGP.set(_miePhaseConstant);
|
|
_atmosphereProperties.mieAsymmetricFactorGP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.mieAsymmetricFactorGP);
|
|
|
|
_atmosphereProperties.sunIntensityP.set(_sunRadianceIntensity);
|
|
_atmosphereProperties.sunIntensityP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.sunIntensityP);
|
|
|
|
_atmosphereProperties.hdrExpositionP.set(_hdrConstant);
|
|
_atmosphereProperties.hdrExpositionP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
|
|
_atmospherePropertyOwner.addProperty(_atmosphereProperties.hdrExpositionP);
|
|
|
|
addPropertySubOwner(_atmospherePropertyOwner);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
bool RenderableGlobe::initialize() {
|
|
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
|
|
if (_atmosphereEnabled) {
|
|
_deferredcaster = std::make_unique<AtmosphereDeferredcaster>();
|
|
if (_deferredcaster) {
|
|
_deferredcaster->setAtmosphereRadius(_atmosphereRadius);
|
|
_deferredcaster->setPlanetRadius(_atmospherePlanetRadius);
|
|
_deferredcaster->setPlanetAverageGroundReflectance(_planetAverageGroundReflectance);
|
|
_deferredcaster->setRayleighHeightScale(_rayleighHeightScale);
|
|
_deferredcaster->setMieHeightScale(_mieHeightScale);
|
|
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
|
|
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
|
|
_deferredcaster->setHDRConstant(_hdrConstant);
|
|
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
|
|
_deferredcaster->setMieScatteringCoefficients(_mieScatteringCoeff);
|
|
_deferredcaster->setMieExtinctionCoefficients(_mieExtinctionCoeff);
|
|
_deferredcaster->setEllipsoidRadii(_ellipsoid.radii());
|
|
_deferredcaster->setRenderableClass(AtmosphereDeferredcaster::RenderableGlobe);
|
|
|
|
_deferredcaster->setPrecalculationTextureScale(_preCalculatedTexturesScale);
|
|
if (_saveCalculationsToTexture)
|
|
_deferredcaster->enablePrecalculationTexturesSaving();
|
|
|
|
_deferredcaster->initialize();
|
|
}
|
|
|
|
OsEng.renderEngine().deferredcasterManager().attachDeferredcaster(*_deferredcaster.get());
|
|
|
|
std::function<void(bool)> onChange = [&](bool enabled) {
|
|
if (enabled) {
|
|
OsEng.renderEngine().deferredcasterManager().attachDeferredcaster(*_deferredcaster.get());
|
|
}
|
|
else {
|
|
OsEng.renderEngine().deferredcasterManager().detachDeferredcaster(*_deferredcaster.get());
|
|
}
|
|
};
|
|
|
|
onEnabledChange(onChange);
|
|
}
|
|
#endif
|
|
|
|
return _distanceSwitch.initialize();
|
|
}
|
|
|
|
bool RenderableGlobe::deinitialize() {
|
|
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
|
|
if (_deferredcaster) {
|
|
OsEng.renderEngine().deferredcasterManager().detachDeferredcaster(*_deferredcaster.get());
|
|
_deferredcaster = nullptr;
|
|
}
|
|
#endif
|
|
|
|
return _distanceSwitch.deinitialize();
|
|
}
|
|
|
|
bool RenderableGlobe::isReady() const {
|
|
return true;
|
|
}
|
|
|
|
void RenderableGlobe::render(const RenderData& data, RendererTasks& tasks) {
|
|
bool statsEnabled = _debugProperties.collectStats.value();
|
|
_chunkedLodGlobe->stats.setEnabled(statsEnabled);
|
|
|
|
if (_debugProperties.toggleEnabledEveryFrame.value()) {
|
|
_generalProperties.isEnabled.setValue(
|
|
!_generalProperties.isEnabled.value()
|
|
);
|
|
}
|
|
if (_generalProperties.isEnabled.value()) {
|
|
if (_debugProperties.saveOrThrowCamera.value()) {
|
|
_debugProperties.saveOrThrowCamera.setValue(false);
|
|
|
|
if (savedCamera() == nullptr) { // save camera
|
|
setSaveCamera(std::make_shared<Camera>(data.camera));
|
|
}
|
|
else { // throw camera
|
|
setSaveCamera(nullptr);
|
|
}
|
|
}
|
|
_distanceSwitch.render(data);
|
|
}
|
|
if (_savedCamera != nullptr) {
|
|
DebugRenderer::ref().renderCameraFrustum(data, *_savedCamera);
|
|
}
|
|
|
|
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
|
|
if (_atmosphereEnabled) {
|
|
DeferredcasterTask task{ _deferredcaster.get(), data };
|
|
tasks.deferredcasterTasks.push_back(task);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void RenderableGlobe::update(const UpdateData& data) {
|
|
_time = data.time.j2000Seconds();
|
|
_distanceSwitch.update(data);
|
|
|
|
glm::dmat4 translation =
|
|
glm::translate(glm::dmat4(1.0), data.modelTransform.translation);
|
|
glm::dmat4 rotation = glm::dmat4(data.modelTransform.rotation);
|
|
glm::dmat4 scaling =
|
|
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale,
|
|
data.modelTransform.scale, data.modelTransform.scale));
|
|
|
|
_cachedModelTransform = translation * rotation * scaling;
|
|
_cachedInverseModelTransform = glm::inverse(_cachedModelTransform);
|
|
|
|
if (_debugProperties.resetTileProviders) {
|
|
_layerManager->reset();
|
|
_debugProperties.resetTileProviders = false;
|
|
}
|
|
_layerManager->update();
|
|
_chunkedLodGlobe->update(data);
|
|
|
|
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
|
|
if (_deferredcaster) {
|
|
_deferredcaster->setTime(data.time.j2000Seconds());
|
|
_deferredcaster->setModelTransform(_cachedModelTransform);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
glm::dvec3 RenderableGlobe::projectOnEllipsoid(glm::dvec3 position) {
|
|
return _ellipsoid.geodeticSurfaceProjection(position);
|
|
}
|
|
|
|
float RenderableGlobe::getHeight(glm::dvec3 position) {
|
|
if (_chunkedLodGlobe) {
|
|
return _chunkedLodGlobe->getHeight(position);
|
|
}
|
|
else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
std::shared_ptr<ChunkedLodGlobe> RenderableGlobe::chunkedLodGlobe() const{
|
|
return _chunkedLodGlobe;
|
|
}
|
|
|
|
const Ellipsoid& RenderableGlobe::ellipsoid() const{
|
|
return _ellipsoid;
|
|
}
|
|
|
|
const glm::dmat4& RenderableGlobe::modelTransform() const{
|
|
return _cachedModelTransform;
|
|
}
|
|
|
|
const glm::dmat4& RenderableGlobe::inverseModelTransform() const{
|
|
return _cachedInverseModelTransform;
|
|
}
|
|
|
|
const RenderableGlobe::DebugProperties&
|
|
RenderableGlobe::debugProperties() const{
|
|
return _debugProperties;
|
|
}
|
|
|
|
const RenderableGlobe::GeneralProperties&
|
|
RenderableGlobe::generalProperties() const{
|
|
return _generalProperties;
|
|
}
|
|
|
|
const std::shared_ptr<const Camera> RenderableGlobe::savedCamera() const {
|
|
return _savedCamera;
|
|
}
|
|
|
|
double RenderableGlobe::interactionDepthBelowEllipsoid() {
|
|
return _interactionDepthBelowEllipsoid;
|
|
}
|
|
|
|
void RenderableGlobe::setSaveCamera(std::shared_ptr<Camera> camera) {
|
|
_savedCamera = camera;
|
|
}
|
|
|
|
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
|
|
void RenderableGlobe::updateAtmosphereParameters() {
|
|
bool executeComputation = true;
|
|
if (_sunRadianceIntensity != _atmosphereProperties.sunIntensityP.value() ||
|
|
_hdrConstant != _atmosphereProperties.hdrExpositionP.value())
|
|
executeComputation = false;
|
|
_atmosphereRadius = _atmospherePlanetRadius + _atmosphereProperties.atmosphereHeightP.value();
|
|
_planetAverageGroundReflectance = _atmosphereProperties.groundAverageReflectanceP.value();
|
|
_rayleighHeightScale = _atmosphereProperties.rayleighHeightScaleP.value();
|
|
_rayleighScatteringCoeff = glm::vec3(_atmosphereProperties.rayleighScatteringCoeffXP.value() * 0.001f,
|
|
_atmosphereProperties.rayleighScatteringCoeffYP.value() * 0.001f,
|
|
_atmosphereProperties.rayleighScatteringCoeffZP.value() * 0.001f);
|
|
_mieHeightScale = _atmosphereProperties.mieHeightScaleP.value();
|
|
_mieScatteringCoeff = glm::vec3(_atmosphereProperties.mieScatteringCoefficientP.value() * 0.001f);
|
|
_mieExtinctionCoeff = _mieScatteringCoeff * (1.0f / static_cast<float>(_atmosphereProperties.mieScatteringExtinctionPropCoefficientP.value()));
|
|
_miePhaseConstant = _atmosphereProperties.mieAsymmetricFactorGP.value();
|
|
_sunRadianceIntensity = _atmosphereProperties.sunIntensityP.value();
|
|
_hdrConstant = _atmosphereProperties.hdrExpositionP.value();
|
|
|
|
if (_deferredcaster) {
|
|
_deferredcaster->setAtmosphereRadius(_atmosphereRadius);
|
|
_deferredcaster->setPlanetRadius(_atmospherePlanetRadius);
|
|
_deferredcaster->setPlanetAverageGroundReflectance(_planetAverageGroundReflectance);
|
|
_deferredcaster->setRayleighHeightScale(_rayleighHeightScale);
|
|
_deferredcaster->setMieHeightScale(_mieHeightScale);
|
|
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
|
|
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
|
|
_deferredcaster->setHDRConstant(_hdrConstant);
|
|
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
|
|
_deferredcaster->setMieScatteringCoefficients(_mieScatteringCoeff);
|
|
_deferredcaster->setMieExtinctionCoefficients(_mieExtinctionCoeff);
|
|
_deferredcaster->setRenderableClass(AtmosphereDeferredcaster::RenderableGlobe);
|
|
|
|
if (executeComputation)
|
|
_deferredcaster->preCalculateAtmosphereParam();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
} // namespace globebrowsing
|
|
} // namespace openspace
|