Atmosphere is now a separated node in OS. Removed ATM code from renderableglobe and renderableplanet.

This commit is contained in:
Jonathas Costa
2017-07-24 17:05:30 -04:00
parent eb87fa4390
commit 7096aeb9dd
10 changed files with 179 additions and 1130 deletions

View File

@@ -42,12 +42,32 @@ return {
Color = "textures/earth_bluemarble.jpg",
Night = "textures/earth_night.jpg",
Height = "textures/earth_bluemarble_height.jpg"
},
},
Tag = {"planet_solarSystem", "planet_terrestrial"},
Transform = {
Rotation = {
Type = "SpiceRotation",
SourceFrame = "IAU_EARTH",
DestinationFrame = "GALACTIC",
},
Atmosphere = {
Scale = {
Type = "StaticScale",
Scale = 1,
},
},
GuiName = "/Solar/Planets/Earth"
},
-- Earth Atmosphere
{
Name = "EarthAtmosphere",
Parent = "Earth",
Renderable = {
Type = "RenderableAtmosphere",
Atmosphere = {
Type = "RenderablePlanet",
-- Atmosphere radius in Km
--AtmoshereRadius = 6450,
--AtmoshereRadius = 6420.0,
AtmoshereRadius = 6447.0,
AtmosphereRadius = 6447.0,
--PlanetRadius = 6378.137,
PlanetRadius = 6356.752,
--PlanetRadius = 6360.0,
@@ -86,24 +106,6 @@ return {
-- Mie Phase Function Value (G e [-1.0, 1.0]. If G = 1.0, Mie phase function = Rayleigh Phase Function)
G = 0.85
},
-- Clear Sky
-- Mie = {
-- Coefficients = {
-- Scattering = {20e-3, 20e-3, 20e-3},
-- Extinction = 1.0/0.9,
-- }
-- H_M = 1.2,
-- G = 0.76,
-- },
-- Cloudy
-- Mie = {
-- Coefficients = {
-- Scattering = {3e-3, 3e-3, 3e-3},
-- Extinction = 1.0/0.9,
-- }
-- H_M = 3.0,
-- G = 0.65,
-- },
Image = {
ToneMapping = jToneMapping,
Exposure = 0.4,
@@ -114,21 +116,8 @@ return {
PreCalculatedTextureScale = 1.0,
SaveCalculatedTextures = false,
},
},
},
Tag = {"planet_solarSystem", "planet_terrestrial"},
Transform = {
Rotation = {
Type = "SpiceRotation",
SourceFrame = "IAU_EARTH",
DestinationFrame = "GALACTIC",
},
Scale = {
Type = "StaticScale",
Scale = 1,
},
},
GuiName = "/Solar/Planets/Earth"
},
},
},
-- EarthTrail module
{

View File

@@ -64,80 +64,7 @@ return {
Renderable = {
Type = "RenderableGlobe",
Radii = earthEllipsoid,
SegmentsPerPatch = 64,
Atmosphere = {
-- Atmosphere radius in Km
--AtmosphereRadius = 6450,
--AtmosphereRadius = 6420.0,
AtmosphereRadius = 6447.0,
--PlanetRadius = 6378.137,
PlanetRadius = 6377.0,
--PlanetRadius = 6360.0,
PlanetAverageGroundReflectance = 0.1,
Rayleigh = {
Coefficients = {
-- Wavelengths are given in 10^-9m
Wavelengths = {680, 550, 440},
-- Reflection coefficients are given in km^-1
Scattering = {5.8E-3, 13.5E-3, 33.1E-3},
-- In Rayleigh scattering, the coefficients of absorption and scattering are the same.
},
-- Thichkness of atmosphere if its density were uniform, in Km
H_R = 8.0,
},
--[[
Ozone = {
Coefficients = {
-- Extinction coefficients
Extinction = {3.426, 8.298, 0.356}
},
H_O = 8.0,
},
]]
-- Default
Mie = {
Coefficients = {
-- Reflection coefficients are given in km^-1
Scattering = {4.0e-3, 4.0e-3, 4.0e-3},
--Scattering = {2.0e-5, 2.0e-5, 2.0e-5},
-- Extinction coefficients are a fraction of the Mie coefficients
Extinction = {4.0e-3/0.9, 4.0e-3/0.9, 4.0e-3/0.9}
},
-- Height scale (atmosphere thickness for constant density) in Km
H_M = 1.2,
-- Mie Phase Function Value (G e [-1.0, 1.0]. If G = 1.0, Mie phase function = Rayleigh Phase Function)
G = 0.85
},
-- Clear Sky
-- Mie = {
-- Coefficients = {
-- Scattering = {20e-3, 20e-3, 20e-3},
-- Extinction = 1.0/0.9,
-- }
-- H_M = 1.2,
-- G = 0.76,
-- },
-- Cloudy
-- Mie = {
-- Coefficients = {
-- Scattering = {3e-3, 3e-3, 3e-3},
-- Extinction = 1.0/0.9,
-- }
-- H_M = 3.0,
-- G = 0.65,
-- },
Image = {
ToneMapping = jToneMapping,
Exposure = 0.4,
Background = 1.8,
Gamma = 1.85,
},
Debug = {
-- PreCalculatedTextureScale is a float from 1.0 to N, with N > 0.0 and N in Naturals (i.e., 1, 2, 3, 4, 5....)
PreCalculatedTextureScale = 1.0,
SaveCalculatedTextures = false,
},
},
SegmentsPerPatch = 128,
Layers = {
ColorLayers = {
{
@@ -262,4 +189,86 @@ return {
},
}
},
-- Earth Atmosphere
{
Name = "EarthAtmosphere",
Parent = "Earth",
Renderable = {
Type = "RenderableAtmosphere",
Atmosphere = {
Type = "RenderableGlobe",
-- Atmosphere radius in Km
--AtmosphereRadius = 6450,
--AtmosphereRadius = 6420.0,
AtmosphereRadius = 6447.0,
--PlanetRadius = 6378.137,
PlanetRadius = 6377.0,
--PlanetRadius = 6360.0,
PlanetAverageGroundReflectance = 0.1,
Rayleigh = {
Coefficients = {
-- Wavelengths are given in 10^-9m
Wavelengths = {680, 550, 440},
-- Reflection coefficients are given in km^-1
Scattering = {5.8E-3, 13.5E-3, 33.1E-3},
-- In Rayleigh scattering, the coefficients of absorption and scattering are the same.
},
-- Thichkness of atmosphere if its density were uniform, in Km
H_R = 8.0,
},
--[[
Ozone = {
Coefficients = {
-- Extinction coefficients
Extinction = {3.426, 8.298, 0.356}
},
H_O = 8.0,
},
]]
-- Default
Mie = {
Coefficients = {
-- Reflection coefficients are given in km^-1
Scattering = {4.0e-3, 4.0e-3, 4.0e-3},
--Scattering = {2.0e-5, 2.0e-5, 2.0e-5},
-- Extinction coefficients are a fraction of the Mie coefficients
Extinction = {4.0e-3/0.9, 4.0e-3/0.9, 4.0e-3/0.9}
},
-- Height scale (atmosphere thickness for constant density) in Km
H_M = 1.2,
-- Mie Phase Function Value (G e [-1.0, 1.0]. If G = 1.0, Mie phase function = Rayleigh Phase Function)
G = 0.85
},
-- Clear Sky
-- Mie = {
-- Coefficients = {
-- Scattering = {20e-3, 20e-3, 20e-3},
-- Extinction = 1.0/0.9,
-- }
-- H_M = 1.2,
-- G = 0.76,
-- },
-- Cloudy
-- Mie = {
-- Coefficients = {
-- Scattering = {3e-3, 3e-3, 3e-3},
-- Extinction = 1.0/0.9,
-- }
-- H_M = 3.0,
-- G = 0.65,
-- },
Image = {
ToneMapping = jToneMapping,
Exposure = 0.4,
Background = 1.8,
Gamma = 1.85,
},
Debug = {
-- PreCalculatedTextureScale is a float from 1.0 to N, with N > 0.0 and N in Naturals (i.e., 1, 2, 3, 4, 5....)
PreCalculatedTextureScale = 1.0,
SaveCalculatedTextures = false,
},
},
},
},
}

View File

@@ -123,51 +123,9 @@ return {
Renderable = {
Type = "RenderableGlobe",
Radii = marsEllipsoid,
SegmentsPerPatch = 90,
-- Allows camera to go down 10000 meters below the reference ellipsoid InteractionDepthBelowEllipsoid = 10000, -- Useful when having negative height map values
Atmosphere = {
-- Atmosphere radius in Km
AtmosphereRadius = 3463.17495,
--PlanetRadius = 3396.19,
--PlanetRadius = 3393.0,
PlanetRadius = 3386.190,
PlanetAverageGroundReflectance = 0.1,
Rayleigh = {
Coefficients = {
-- Wavelengths are given in 10^-9m
Wavelengths = {680, 550, 440},
-- Reflection coefficients are given in km^-1
Scattering = {19.918E-3, 13.57E-3, 5.75E-3},
-- In Rayleigh scattering, the coefficients of absorption and scattering are the same.
},
-- Thichkness of atmosphere if its density were uniform, in Km
H_R = 10.43979,
},
-- Default
Mie = {
Coefficients = {
-- Reflection coefficients are given in km^-1
Scattering = {53.61771e-3, 53.61771e-3, 53.61771e-3},
-- Extinction coefficients are a fraction of the Scattering coefficients
Extinction = {53.61771e-3/0.98979, 53.61771e-3/0.98979, 53.61771e-3/0.98979}
},
-- Mie Height scale (atmosphere thickness for constant density) in Km
H_M = 3.09526,
-- Mie Phase Function Value (G e [-1.0, 1.0]. If G = 1.0, Mie phase function = Rayleigh Phase Function)
G = 0.85,
},
Image = {
ToneMapping = jToneMapping,
Exposure = 0.4,
Background = 1.8,
Gamma = 1.85,
},
Debug = {
-- PreCalculatedTextureScale is a float from 1.0 to N, with N > 0.0 and N in Naturals (i.e., 1, 2, 3, 4, 5....)
PreCalculatedTextureScale = 1.0,
SaveCalculatedTextures = false,
},
},
SegmentsPerPatch = 128,
-- Allows camera to go down 10000 meters below the reference ellipsoid InteractionDepthBelowEllipsoid = 10000,
-- Useful when having negative height map values
Layers = {
ColorLayers = {
{
@@ -287,9 +245,62 @@ return {
FilePath = "map_datasets/HiRISE/Part_of_Area_Traversed_by_the_Mars_Exploration_Rover_Heightmap.vrt",
},]]--
},
}, -- Layers
}, -- Renderable
}, -- Renderable Globe
-- Mars Atmosphere
{
Name = "MarsAtmosphere",
Parent = "Mars",
Renderable = {
Type = "RenderableAtmosphere",
Atmosphere = {
Type = "RenderableGlobe",
-- Atmosphere radius in Km
AtmosphereRadius = 3463.17495,
--PlanetRadius = 3396.19,
--PlanetRadius = 3393.0,
PlanetRadius = 3386.190,
PlanetAverageGroundReflectance = 0.1,
Rayleigh = {
Coefficients = {
-- Wavelengths are given in 10^-9m
Wavelengths = {680, 550, 440},
-- Reflection coefficients are given in km^-1
Scattering = {19.918E-3, 13.57E-3, 5.75E-3},
-- In Rayleigh scattering, the coefficients of absorption and scattering are the same.
},
}
},
-- Thichkness of atmosphere if its density were uniform, in Km
H_R = 10.43979,
},
-- Default
Mie = {
Coefficients = {
-- Reflection coefficients are given in km^-1
Scattering = {53.61771e-3, 53.61771e-3, 53.61771e-3},
-- Extinction coefficients are a fraction of the Scattering coefficients
Extinction = {53.61771e-3/0.98979, 53.61771e-3/0.98979, 53.61771e-3/0.98979}
},
-- Mie Height scale (atmosphere thickness for constant density) in Km
H_M = 3.09526,
-- Mie Phase Function Value (G e [-1.0, 1.0]. If G = 1.0, Mie phase function = Rayleigh Phase Function)
G = 0.85,
},
Image = {
ToneMapping = jToneMapping,
Exposure = 0.4,
Background = 1.8,
Gamma = 1.85,
},
Debug = {
-- PreCalculatedTextureScale is a float from 1.0 to N, with N > 0.0 and N in Naturals (i.e., 1, 2, 3, 4, 5....)
PreCalculatedTextureScale = 1.0,
SaveCalculatedTextures = false,
},
},
},
},
-- Trail module
{
Name = "MarsTrail",

View File

@@ -26,11 +26,13 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake)
set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/atmospheredeferredcaster.h
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableatmosphere.h
)
source_group("Header Files" FILES ${HEADER_FILES})
set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/atmospheredeferredcaster.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableatmosphere.cpp
)
source_group("Source Files" FILES ${SOURCE_FILES})

View File

@@ -28,7 +28,7 @@
#include <openspace/rendering/renderable.h>
//#include <modules/atmosphere/rendering/renderableplanetatmosphere.h>
#include <modules/atmosphere/rendering/renderableatmosphere.h>
namespace openspace {
@@ -39,7 +39,7 @@ AtmosphereModule::AtmosphereModule() :
void AtmosphereModule::internalInitialize() {
auto fRenderable = FactoryManager::ref().factory<Renderable>();
ghoul_assert(fRenderable, "No renderable factory existed");
//fRenderable->registerClass<RenderablePlanetAtmosphere>("RenderablePlanetAtmosphere");
fRenderable->registerClass<RenderableAtmosphere>("RenderableAtmosphere");
}
} // namespace openspace

View File

@@ -29,16 +29,6 @@
#include <modules/globebrowsing/globes/pointglobe.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>
#include <openspace/rendering/renderer.h>
#endif
namespace {
const char* keyFrame = "Frame";
const char* keyRadii = "Radii";
@@ -47,27 +37,6 @@ namespace {
const char* keyShadowGroup = "Shadow_Group";
const char* keyShadowSource = "Source";
const char* keyShadowCaster = "Caster";
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
const char* keyATMDebug = "Debug";
const char* keyTextureScale = "PreCalculatedTextureScale";
const char* keySaveTextures = "SaveCalculatedTextures";
const char* keyAtmosphere = "Atmosphere";
const char* keyAtmosphereRadius = "AtmosphereRadius";
const char* keyPlanetRadius = "PlanetRadius";
const char* keyAverageGroundReflectance = "PlanetAverageGroundReflectance";
const char* keyRayleigh = "Rayleigh";
const char* keyRayleighHeightScale = "H_R";
const char* keyOzone = "Ozone";
const char* keyOzoneHeightScale = "H_O";
const char* keyMie = "Mie";
const char* keyMieHeightScale = "H_M";
const char* keyMiePhaseConstant = "G";
const char* keyImage = "Image";
const char* keyToneMappingOp = "ToneMapping";
const char* keyExposure = "Exposure";
const char* keyBackground = "Background";
const char* keyGamma = "Gamma";
#endif
} // namespace
using namespace openspace::properties;
@@ -103,50 +72,6 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
, _debugPropertyOwner("Debug")
, _texturePropertyOwner("Textures")
, _shadowEnabled(false)
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
, _atmosphereProperties({
FloatProperty("atmosphereHeight", "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("ozoneLayerHeightScale", "Ozone Height Scale (KM)", 8.0f, 0.1f, 20.0f),
FloatProperty("ozoneLayerCoeffX", "Ozone Layer Extinction Coeff X", 3.426f, 0.01f, 100.0f),
FloatProperty("ozoneLayerCoeffY", "Ozone Layer Extinction Coeff Y", 8.298f, 0.01f, 100.0f),
FloatProperty("ozoneLayerCoeffZ", "Ozone Layer Extinction Coeff Z", 0.356f, 0.01f, 100.0f),
FloatProperty("mieHeightScale", "Mie Height Scale (KM)", 1.2f, 0.1f, 20.0f),
FloatProperty("mieScatteringCoeffX", "Mie Scattering Coeff X (x10e-3)", 4.0f, 0.01f, 1000.0f),
FloatProperty("mieScatteringCoeffY", "Mie Scattering Coeff Y (x10e-3)", 4.0f, 0.01f, 1000.0f),
FloatProperty("mieScatteringCoeffZ", "Mie Scattering Coeff Z (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 Exposition", 0.4f, 0.01f, 5.0f),
FloatProperty("gamma", "Gamma Correction", 1.8f, 0.1f, 3.0f ),
BoolProperty("ozone", "Ozone Layer Enabled", true)
})
, _atmospherePropertyOwner("Atmosphere")
, _atmosphereRadius(0.f)
, _atmospherePlanetRadius(0.f)
, _planetAverageGroundReflectance(0.f)
, _rayleighHeightScale(0.f)
, _ozoneLayerHeightScale(0.f)
, _mieHeightScale(0.f)
, _miePhaseConstant(0.f)
, _rayleighScatteringCoeff(glm::vec3(0.f))
, _ozoneLayerExtinctionCoeff(glm::vec3(0.f))
, _mieScatteringCoeff(glm::vec3(0.f))
, _mieExtinctionCoeff(glm::vec3(0.f))
, _sunRadianceIntensity(50.0f)
, _exposureConstant(0.4f)
, _exposureBackgroundConstant(2.8f)
, _gammaConstant(1.8f)
, _atmosphereEnabled(false)
, _saveCalculationsToTexture(false)
, _preCalculatedTexturesScale(1.0)
#endif
{
setName("RenderableGlobe");
@@ -295,291 +220,14 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary)
}
}
}
#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 ozoneDictionary;
success = atmosphereDictionary.getValue(keyOzone, ozoneDictionary);
if (success) {
_ozoneLayerEnabled = true;
if (!ozoneDictionary.getValue(keyOzoneHeightScale, _ozoneLayerHeightScale)) {
_ozoneLayerEnabled = false;
}
if (!ozoneDictionary.getValue("Coefficients.Extinction", _ozoneLayerExtinctionCoeff)) {
_ozoneLayerEnabled = false;
}
}
else {
_ozoneLayerEnabled = false;
}
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 ImageDictionary;
success = atmosphereDictionary.getValue(keyImage, ImageDictionary);
if (success) {
if (ImageDictionary.getValue(keyToneMappingOp, _preCalculatedTexturesScale)) {
//LDEBUG("Atmosphere Texture Scaled to " << _preCalculatedTexturesScale);
}
if (ImageDictionary.getValue(keyExposure, _exposureConstant)) {
//LDEBUG("Saving Precalculated Atmosphere Textures.");
}
if (ImageDictionary.getValue(keyBackground, _exposureBackgroundConstant)) {
//LDEBUG("Saving Precalculated Atmosphere Textures.");
}
if (ImageDictionary.getValue(keyGamma, _gammaConstant)) {
//LDEBUG("Saving Precalculated Atmosphere Textures.");
}
}
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.ozoneLayerEnabledP.set(_ozoneLayerEnabled);
_atmosphereProperties.ozoneLayerEnabledP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.ozoneLayerEnabledP);
_atmosphereProperties.ozoneHeightScaleP.set(_ozoneLayerHeightScale);
_atmosphereProperties.ozoneHeightScaleP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.ozoneHeightScaleP);
_atmosphereProperties.ozoneLayerExtinctionCoeffXP.set(_ozoneLayerExtinctionCoeff.x);
_atmosphereProperties.ozoneLayerExtinctionCoeffXP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.ozoneLayerExtinctionCoeffXP);
_atmosphereProperties.ozoneLayerExtinctionCoeffYP.set(_ozoneLayerExtinctionCoeff.y);
_atmosphereProperties.ozoneLayerExtinctionCoeffYP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.ozoneLayerExtinctionCoeffYP);
_atmosphereProperties.ozoneLayerExtinctionCoeffZP.set(_ozoneLayerExtinctionCoeff.z);
_atmosphereProperties.ozoneLayerExtinctionCoeffZP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.ozoneLayerExtinctionCoeffZP);
_atmosphereProperties.mieHeightScaleP.set(_mieHeightScale);
_atmosphereProperties.mieHeightScaleP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.mieHeightScaleP);
_atmosphereProperties.mieScatteringCoeffXP.set(_mieScatteringCoeff.x * 1000.0f);
_atmosphereProperties.mieScatteringCoeffXP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.mieScatteringCoeffXP);
_atmosphereProperties.mieScatteringCoeffYP.set(_mieScatteringCoeff.y * 1000.0f);
_atmosphereProperties.mieScatteringCoeffYP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.mieScatteringCoeffYP);
_atmosphereProperties.mieScatteringCoeffZP.set(_mieScatteringCoeff.z * 1000.0f);
_atmosphereProperties.mieScatteringCoeffZP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.mieScatteringCoeffZP);
_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(_exposureConstant);
_atmosphereProperties.hdrExpositionP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.hdrExpositionP);
_atmosphereProperties.gammaConstantP.set(_gammaConstant);
_atmosphereProperties.gammaConstantP.onChange(std::bind(&RenderableGlobe::updateAtmosphereParameters, this));
_atmospherePropertyOwner.addProperty(_atmosphereProperties.gammaConstantP);
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->enableOzone(_ozoneLayerEnabled);
_deferredcaster->setOzoneHeightScale(_ozoneLayerHeightScale);
_deferredcaster->setMieHeightScale(_mieHeightScale);
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
_deferredcaster->setHDRConstant(_exposureConstant);
_deferredcaster->setBackgroundConstant(_exposureBackgroundConstant);
_deferredcaster->setGammaConstant(_gammaConstant);
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
_deferredcaster->setOzoneExtinctionCoefficients(_ozoneLayerExtinctionCoeff);
_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();
}
@@ -613,13 +261,6 @@ void RenderableGlobe::render(const RenderData& data, RendererTasks& renderTask)
if (_savedCamera != nullptr) {
DebugRenderer::ref().renderCameraFrustum(data, *_savedCamera);
}
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
if (_atmosphereEnabled) {
DeferredcasterTask task{ _deferredcaster.get(), data };
renderTask.deferredcasterTasks.push_back(task);
}
#endif
}
void RenderableGlobe::update(const UpdateData& data) {
@@ -642,16 +283,6 @@ void RenderableGlobe::update(const UpdateData& data) {
}
_layerManager->update();
_chunkedLodGlobe->update(data);
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
if (_deferredcaster) {
_deferredcaster->setTime(data.time.j2000Seconds());
_deferredcaster->setModelTransform(_cachedModelTransform);
if (_exposureBackgroundConstant != OsEng.renderEngine().renderer()->hdrBackground())
updateAtmosphereParameters();
}
#endif
}
glm::dvec3 RenderableGlobe::projectOnEllipsoid(glm::dvec3 position) {
@@ -734,60 +365,4 @@ 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() ||
_exposureConstant != _atmosphereProperties.hdrExpositionP.value() ||
_exposureBackgroundConstant != OsEng.renderEngine().renderer()->hdrBackground() ||
_gammaConstant != _atmosphereProperties.gammaConstantP.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);
_ozoneLayerEnabled = _atmosphereProperties.ozoneLayerEnabledP.value();
_ozoneLayerHeightScale = _atmosphereProperties.ozoneHeightScaleP.value();
_ozoneLayerExtinctionCoeff = glm::vec3(_atmosphereProperties.ozoneLayerExtinctionCoeffXP.value(),
_atmosphereProperties.ozoneLayerExtinctionCoeffYP.value(),
_atmosphereProperties.ozoneLayerExtinctionCoeffZP.value());
_mieHeightScale = _atmosphereProperties.mieHeightScaleP.value();
_mieScatteringCoeff = glm::vec3(_atmosphereProperties.mieScatteringCoeffXP.value() * 0.001f,
_atmosphereProperties.mieScatteringCoeffYP.value() * 0.001f,
_atmosphereProperties.mieScatteringCoeffZP.value() * 0.001f);
_mieExtinctionCoeff = _mieScatteringCoeff * (1.0f / static_cast<float>(_atmosphereProperties.mieScatteringExtinctionPropCoefficientP.value()));
_miePhaseConstant = _atmosphereProperties.mieAsymmetricFactorGP.value();
_sunRadianceIntensity = _atmosphereProperties.sunIntensityP.value();
_exposureConstant = _atmosphereProperties.hdrExpositionP.value();
_exposureBackgroundConstant = OsEng.renderEngine().renderer()->hdrBackground();
_gammaConstant = _atmosphereProperties.gammaConstantP.value();
if (_deferredcaster) {
_deferredcaster->setAtmosphereRadius(_atmosphereRadius);
_deferredcaster->setPlanetRadius(_atmospherePlanetRadius);
_deferredcaster->setPlanetAverageGroundReflectance(_planetAverageGroundReflectance);
_deferredcaster->setRayleighHeightScale(_rayleighHeightScale);
_deferredcaster->enableOzone(_ozoneLayerEnabled);
_deferredcaster->setOzoneHeightScale(_ozoneLayerHeightScale);
_deferredcaster->setMieHeightScale(_mieHeightScale);
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
_deferredcaster->setHDRConstant(_exposureConstant);
_deferredcaster->setBackgroundConstant(_exposureBackgroundConstant);
_deferredcaster->setGammaConstant(_gammaConstant);
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
_deferredcaster->setOzoneExtinctionCoefficients(_ozoneLayerExtinctionCoeff);
_deferredcaster->setMieScatteringCoefficients(_mieScatteringCoeff);
_deferredcaster->setMieExtinctionCoefficients(_mieExtinctionCoeff);
_deferredcaster->setRenderableClass(AtmosphereDeferredcaster::RenderableGlobe);
if (executeComputation)
_deferredcaster->preCalculateAtmosphereParam();
}
}
#endif
} // namespace openspace::globebrowsing

View File

@@ -99,33 +99,6 @@ public:
glm::vec3 casterPositionVec;
bool isShadowing;
};
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
struct AtmosphereProperties {
properties::FloatProperty atmosphereHeightP;
properties::FloatProperty groundAverageReflectanceP;
properties::FloatProperty rayleighHeightScaleP;
properties::FloatProperty rayleighScatteringCoeffXP;
properties::FloatProperty rayleighScatteringCoeffYP;
properties::FloatProperty rayleighScatteringCoeffZP;
properties::FloatProperty ozoneHeightScaleP;
properties::FloatProperty ozoneLayerExtinctionCoeffXP;
properties::FloatProperty ozoneLayerExtinctionCoeffYP;
properties::FloatProperty ozoneLayerExtinctionCoeffZP;
properties::FloatProperty mieHeightScaleP;
properties::FloatProperty mieScatteringCoeffXP;
properties::FloatProperty mieScatteringCoeffYP;
properties::FloatProperty mieScatteringCoeffZP;
properties::FloatProperty mieScatteringExtinctionPropCoefficientP;
properties::FloatProperty mieAsymmetricFactorGP;
properties::FloatProperty sunIntensityP;
properties::FloatProperty hdrExpositionP;
properties::FloatProperty gammaConstantP;
properties::BoolProperty ozoneLayerEnabledP;
};
const AtmosphereProperties& atmosphereProperties() const;
#endif
RenderableGlobe(const ghoul::Dictionary& dictionary);
~RenderableGlobe() = default;
@@ -184,43 +157,6 @@ private:
// Shadow
bool _shadowEnabled;
std::vector< ShadowConf > _shadowConfArray;
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
// Atmosphere Data
bool _atmosphereEnabled;
bool _ozoneLayerEnabled;
float _atmosphereRadius;
float _atmospherePlanetRadius;
float _planetAverageGroundReflectance;
float _rayleighHeightScale;
float _ozoneLayerHeightScale;
float _mieHeightScale;
float _miePhaseConstant;
float _sunRadianceIntensity;
float _exposureConstant;
float _exposureBackgroundConstant;
float _gammaConstant;
glm::vec3 _rayleighScatteringCoeff;
glm::vec3 _ozoneLayerExtinctionCoeff;
glm::vec3 _mieScatteringCoeff;
glm::vec3 _mieExtinctionCoeff;
// Atmosphere Debug
bool _saveCalculationsToTexture;
float _preCalculatedTexturesScale;
AtmosphereProperties _atmosphereProperties;
properties::PropertyOwner _atmospherePropertyOwner;
// Deferred ATM Rendering
std::unique_ptr<AtmosphereDeferredcaster> _deferredcaster;
#endif
private:
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
void updateAtmosphereParameters();
#endif
};
} // namespace openspace::globebrowsing

View File

@@ -31,6 +31,8 @@
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/misc/assert.h>
@@ -40,14 +42,6 @@
#include <ghoul/opengl/textureunit.h>
#include <ghoul/misc/invariants.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
#include <memory>
#include <fstream>
@@ -71,27 +65,6 @@ namespace {
const char* keyShadowCaster = "Caster";
const char* keyBody = "Body";
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
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 keyOzone = "Ozone";
const std::string keyOzoneHeightScale = "H_O";
const std::string keyMie = "Mie";
const std::string keyMieHeightScale = "H_M";
const std::string keyMiePhaseConstant = "G";
const std::string keyImage = "Image";
const std::string keyToneMappingOp = "ToneMapping";
const std::string keyExposure = "Exposure";
const std::string keyBackground = "Background";
const std::string keyGamma = "Gamma";
const std::string keyATMDebug = "Debug";
const std::string keyTextureScale = "PreCalculatedTextureScale";
const std::string keySaveTextures = "SaveCalculatedTextures";
#endif
} // namespace
namespace openspace {
@@ -158,47 +131,6 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
, _nightTexture(nullptr)
, _heightMapTexture(nullptr)
, _geometry(nullptr)
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
, _atmosphereHeightP("atmmosphereHeight", "Atmosphere Height (KM)", 60.0f, 0.1f, 99.0f)
, _groundAverageReflectanceP("averageGroundReflectance", "Average Ground Reflectance (%)", 0.1f, 0.0f, 1.0f)
, _rayleighHeightScaleP("rayleighHeightScale", "Rayleigh Height Scale (KM)", 8.0f, 0.1f, 20.0f)
, _rayleighScatteringCoeffXP("rayleighScatteringCoeffX", "Rayleigh Scattering Coeff X (x10e-3)", 1.0f, 0.01f, 100.0f)
, _rayleighScatteringCoeffYP("rayleighScatteringCoeffY", "Rayleigh Scattering Coeff Y (x10e-3)", 1.0f, 0.01f, 100.0f)
, _rayleighScatteringCoeffZP("rayleighScatteringCoeffZ", "Rayleigh Scattering Coeff Z (x10e-3)", 1.0f, 0.01f, 100.0f)
, _ozoneEnabledP("ozone", "Ozone Layer Enabled", true)
, _ozoneHeightScaleP("ozoneLayerHeightScale", "Ozone Height Scale (KM)", 8.0f, 0.1f, 20.0f)
, _ozoneCoeffXP("ozoneLayerCoeffX", "Ozone Layer Extinction Coeff X (x10e-5)", 3.426f, 0.01f, 100.0f)
, _ozoneCoeffYP("ozoneLayerCoeffY", "Ozone Layer Extinction Coeff Y (x10e-5)", 8.298f, 0.01f, 100.0f)
, _ozoneCoeffZP("ozoneLayerCoeffZ", "Ozone Layer Extinction Coeff Z (x10e-5)", 0.356f, 0.01f, 100.0f)
, _mieHeightScaleP("mieHeightScale", "Mie Height Scale (KM)", 1.2f, 0.1f, 20.0f)
, _mieScatteringCoefficientP("mieScatteringCoefficient", "Mie Scattering Coefficient (x10e-3)", 4.0f, 0.01f, 1000.0f)
, _mieScatteringExtinctionPropCoefficientP("mieScatteringExtinctionPropCoefficient",
"Mie Scattering/Extinction Proportion Coefficient (%)", 0.9f, 0.01f, 1.0f)
, _mieAsymmetricFactorGP("mieAsymmetricFactorG", "Mie Asymmetric Factor G", 0.85f, -1.0f, 1.0f)
, _sunIntensityP("sunIntensity", "Sun Intensity", 50.0f, 0.1f, 1000.0f)
, _hdrExpositionP("hdrExposition", "HDR", 0.4f, 0.01f, 5.0f)
, _backgroundExposureP("backgroundExposition", "Background Exposition", 1.8f, 0.01f, 10.0f)
, _gammaConstantP("gamma", "Gamma Correction", 1.8f, 0.1f, 3.0f)
, _atmosphereEnabled(false)
, _ozoneLayerEnabled(false)
, _atmosphereRadius(0.f)
, _atmospherePlanetRadius(0.f)
, _planetAverageGroundReflectance(0.f)
, _rayleighHeightScale(0.f)
, _ozoneHeightScale(0.f)
, _mieHeightScale(0.f)
, _miePhaseConstant(0.f)
, _sunRadianceIntensity(50.f)
, _hdrConstant(0.f)
, _exposureBackgroundConstant(1.8f)
, _gammaConstant(1.8f)
, _mieExtinctionCoeff(glm::vec3(0.f))
, _rayleighScatteringCoeff(glm::vec3(0.f))
, _ozoneExtinctionCoeff(glm::vec3(0.f))
, _mieScatteringCoeff(glm::vec3(0.f))
, _saveCalculationsToTexture(false)
, _preCalculatedTexturesScale(1.0)
#endif
, _alpha(1.f)
, _planetRadius(0.f)
, _hasNightTexture(false)
@@ -350,222 +282,6 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
}
}
}
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
//================================================================
//========== Reads Atmosphere Entries from mod file ==============
//================================================================
bool errorReadingAtmosphereData = false;
ghoul::Dictionary atmosphereDictionary;
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 ozoneDictionary;
success = atmosphereDictionary.getValue(keyOzone, ozoneDictionary);
if (success) {
_ozoneLayerEnabled = true;
if (!ozoneDictionary.getValue(keyOzoneHeightScale, _ozoneHeightScale)) {
_ozoneLayerEnabled = false;
}
if (!ozoneDictionary.getValue("Coefficients.Extinction", _ozoneExtinctionCoeff)) {
_ozoneLayerEnabled = false;
}
}
else {
_ozoneLayerEnabled = false;
}
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 ImageDictionary;
success = atmosphereDictionary.getValue(keyImage, ImageDictionary);
if (success) {
if (ImageDictionary.getValue(keyToneMappingOp, _preCalculatedTexturesScale)) {
LDEBUG("Atmosphere Texture Scaled to " << _preCalculatedTexturesScale);
}
if (ImageDictionary.getValue(keyExposure, _hdrConstant)) {
LDEBUG("Saving Precalculated Atmosphere Textures.");
}
if (ImageDictionary.getValue(keyGamma, _gammaConstant)) {
LDEBUG("Saving Precalculated Atmosphere Textures.");
}
}
ghoul::Dictionary debugDictionary;
success = atmosphereDictionary.getValue(keyATMDebug, debugDictionary);
if (success) {
if (debugDictionary.getValue(keyTextureScale, _preCalculatedTexturesScale)) {
LDEBUG("Atmosphere Texture Scaled to " << _preCalculatedTexturesScale);
}
if (debugDictionary.getValue(keySaveTextures, _saveCalculationsToTexture)) {
LDEBUG("Saving Precalculated Atmosphere Textures.");
}
}
if (!errorReadingAtmosphereData) {
_atmosphereEnabled = true;
//========================================================
//============== Atmosphere Properties ===================
//========================================================
_atmosphereHeightP.set(_atmosphereRadius - _atmospherePlanetRadius);
_atmosphereHeightP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_atmosphereHeightP);
_groundAverageReflectanceP.set(_planetAverageGroundReflectance);
_groundAverageReflectanceP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_groundAverageReflectanceP);
_rayleighHeightScaleP.set(_rayleighHeightScale);
_rayleighHeightScaleP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_rayleighHeightScaleP);
_rayleighScatteringCoeffXP.set(_rayleighScatteringCoeff.x * 1000.0f);
_rayleighScatteringCoeffXP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_rayleighScatteringCoeffXP);
_rayleighScatteringCoeffYP.set(_rayleighScatteringCoeff.y * 1000.0f);
_rayleighScatteringCoeffYP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_rayleighScatteringCoeffYP);
_rayleighScatteringCoeffZP.set(_rayleighScatteringCoeff.z * 1000.0f);
_rayleighScatteringCoeffZP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_rayleighScatteringCoeffZP);
_ozoneEnabledP.set(_ozoneLayerEnabled);
_ozoneEnabledP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_ozoneEnabledP);
_ozoneHeightScaleP.set(_ozoneHeightScale);
_ozoneHeightScaleP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_ozoneHeightScaleP);
_ozoneCoeffXP.set(_ozoneExtinctionCoeff.x * 100000.0f);
_ozoneCoeffXP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_ozoneCoeffXP);
_ozoneCoeffYP.set(_ozoneExtinctionCoeff.y * 100000.0f);
_ozoneCoeffYP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_ozoneCoeffYP);
_ozoneCoeffZP.set(_ozoneExtinctionCoeff.z * 100000.0f);
_ozoneCoeffZP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_ozoneCoeffZP);
_mieHeightScaleP.set(_mieHeightScale);
_mieHeightScaleP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_mieHeightScaleP);
_mieScatteringCoefficientP.set(_mieScatteringCoeff.r * 1000.0f);
_mieScatteringCoefficientP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_mieScatteringCoefficientP);
_mieScatteringExtinctionPropCoefficientP.set(_mieScatteringCoeff.r / _mieExtinctionCoeff.r);
_mieScatteringExtinctionPropCoefficientP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_mieScatteringExtinctionPropCoefficientP);
_mieAsymmetricFactorGP.set(_miePhaseConstant);
_mieAsymmetricFactorGP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_mieAsymmetricFactorGP);
_sunIntensityP.set(_sunRadianceIntensity);
_sunIntensityP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_sunIntensityP);
_hdrExpositionP.set(_hdrConstant);
_hdrExpositionP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_hdrExpositionP);
_backgroundExposureP.set(_exposureBackgroundConstant);
_backgroundExposureP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_backgroundExposureP);
_gammaConstantP.set(_gammaConstant);
_gammaConstantP.onChange(std::bind(&RenderablePlanet::updateAtmosphereParameters, this));
addProperty(_gammaConstantP);
}
}
#endif
}
bool RenderablePlanet::initialize() {
@@ -615,52 +331,6 @@ bool RenderablePlanet::initialize() {
loadTexture();
#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->enableOzone(_ozoneLayerEnabled);
_deferredcaster->setOzoneHeightScale(_ozoneHeightScale);
_deferredcaster->setMieHeightScale(_mieHeightScale);
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
_deferredcaster->setHDRConstant(_hdrConstant);
_deferredcaster->setBackgroundConstant(_exposureBackgroundConstant);
_deferredcaster->setGammaConstant(_gammaConstant);
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
_deferredcaster->setOzoneExtinctionCoefficients(_ozoneExtinctionCoeff);
_deferredcaster->setMieScatteringCoefficients(_mieScatteringCoeff);
_deferredcaster->setMieExtinctionCoefficients(_mieExtinctionCoeff);
// TODO: Fix the ellipsoid nature of the renderable globe (JCC)
//_deferredcaster->setEllipsoidRadii(_ellipsoid.radii());
_deferredcaster->setRenderableClass(AtmosphereDeferredcaster::RenderablePlanet);
_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 isReady();
}
@@ -680,13 +350,6 @@ bool RenderablePlanet::deinitialize() {
_texture = nullptr;
_nightTexture = nullptr;
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
if (_deferredcaster) {
OsEng.renderEngine().deferredcasterManager().detachDeferredcaster(*_deferredcaster.get());
_deferredcaster = nullptr;
}
#endif
return true;
}
@@ -728,15 +391,6 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks& renderTask)
);
_programObject->setUniform("ModelTransform", glm::mat4(modelTransform));
// Normal Transformation
/*glm::mat4 translateObjTrans = glm::translate(glm::mat4(1.0), data.position.vec3());
glm::mat4 translateCamTrans = glm::translate(glm::mat4(1.0), -data.camera.positionVec3());
float scaleFactor = data.camera.scaling().x * powf(10.0, data.camera.scaling().y);
glm::mat4 scaleCamTrans = glm::scale(glm::mat4(1.0), glm::vec3(scaleFactor));*/
// glm::mat4 ModelViewTrans = data.camera.viewMatrix() * scaleCamTrans *
// translateCamTrans * translateObjTrans * glm::mat4(modelTransform);
setPscUniforms(*_programObject.get(), data.camera, data.position);
_programObject->setUniform("_performShading", _performShading);
@@ -851,32 +505,15 @@ void RenderablePlanet::render(const RenderData& data, RendererTasks& renderTask)
// disable shader
_programObject->deactivate();
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
if (_atmosphereEnabled) {
DeferredcasterTask task{ _deferredcaster.get(), data };
renderTask.deferredcasterTasks.push_back(task);
}
#endif
}
void RenderablePlanet::update(const UpdateData& data) {
// set spice-orientation in accordance to timestamp
_stateMatrix = data.modelTransform.rotation;
//_stateMatrix = SpiceManager::ref().positionTransformMatrix(_frame, "GALACTIC", data.time);
_time = data.time.j2000Seconds();
if (_programObject && _programObject->isDirty())
_programObject->rebuildFromFile();
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
if (_deferredcaster) {
_deferredcaster->setTime(data.time.j2000Seconds());
glm::dmat4 modelTransform;
computeModelTransformMatrix(data.modelTransform, &modelTransform);
_deferredcaster->setModelTransform(modelTransform);
}
#endif
}
void RenderablePlanet::loadTexture() {
@@ -924,59 +561,4 @@ void RenderablePlanet::loadTexture() {
}
}
}
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
void RenderablePlanet::updateAtmosphereParameters() {
bool executeComputation = true;
if (_sunRadianceIntensity != _sunIntensityP ||
_hdrConstant != _hdrExpositionP ||
_exposureBackgroundConstant != _backgroundExposureP ||
_gammaConstant != _gammaConstantP)
executeComputation = false;
_atmosphereRadius = _atmospherePlanetRadius + _atmosphereHeightP;
_planetAverageGroundReflectance = _groundAverageReflectanceP;
_rayleighHeightScale = _rayleighHeightScaleP;
_rayleighScatteringCoeff = glm::vec3(_rayleighScatteringCoeffXP * 0.001f, _rayleighScatteringCoeffYP * 0.001f,
_rayleighScatteringCoeffZP * 0.001f);
_ozoneLayerEnabled = _ozoneEnabledP.value();
_ozoneHeightScale = _ozoneHeightScaleP.value();
_ozoneExtinctionCoeff = glm::vec3(_ozoneCoeffXP.value() * 0.00001f,
_ozoneCoeffYP.value() * 0.00001f,
_ozoneCoeffZP.value() * 0.00001f);
_mieHeightScale = _mieHeightScaleP;
_mieScatteringCoeff = glm::vec3(_mieScatteringCoefficientP * 0.001f);
_mieExtinctionCoeff = _mieScatteringCoeff * (1.0f / static_cast<float>(_mieScatteringExtinctionPropCoefficientP));
_miePhaseConstant = _mieAsymmetricFactorGP;
_sunRadianceIntensity = _sunIntensityP;
_hdrConstant = _hdrExpositionP;
_exposureBackgroundConstant = _backgroundExposureP;
_gammaConstant = _gammaConstantP.value();
if (_deferredcaster) {
_deferredcaster->setAtmosphereRadius(_atmosphereRadius);
_deferredcaster->setPlanetRadius(_atmospherePlanetRadius);
_deferredcaster->setPlanetAverageGroundReflectance(_planetAverageGroundReflectance);
_deferredcaster->setRayleighHeightScale(_rayleighHeightScale);
_deferredcaster->enableOzone(_ozoneLayerEnabled);
_deferredcaster->setOzoneHeightScale(_ozoneHeightScale);
_deferredcaster->setMieHeightScale(_mieHeightScale);
_deferredcaster->setMiePhaseConstant(_miePhaseConstant);
_deferredcaster->setSunRadianceIntensity(_sunRadianceIntensity);
_deferredcaster->setHDRConstant(_hdrConstant);
_deferredcaster->setBackgroundConstant(_exposureBackgroundConstant);
_deferredcaster->setGammaConstant(_gammaConstant);
_deferredcaster->setRayleighScatteringCoefficients(_rayleighScatteringCoeff);
_deferredcaster->setOzoneExtinctionCoefficients(_ozoneExtinctionCoeff);
_deferredcaster->setMieScatteringCoefficients(_mieScatteringCoeff);
_deferredcaster->setMieExtinctionCoefficients(_mieExtinctionCoeff);
_deferredcaster->setRenderableClass(AtmosphereDeferredcaster::RenderablePlanet);
if (executeComputation)
_deferredcaster->preCalculateAtmosphereParam();
}
}
#endif
} // namespace openspace

View File

@@ -46,10 +46,6 @@ namespace ghoul::opengl {
namespace openspace {
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
class AtmosphereDeferredcaster;
#endif
struct TransformData;
namespace planetgeometry {
@@ -92,9 +88,6 @@ protected:
private:
void computeModelTransformMatrix(const openspace::TransformData & transformData, glm::dmat4 * modelTransform);
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
void updateAtmosphereParameters();
#endif
private:
properties::StringProperty _colorTexturePath;
@@ -111,54 +104,6 @@ private:
std::unique_ptr<planetgeometry::PlanetGeometry> _geometry;
#ifdef OPENSPACE_MODULE_ATMOSPHERE_ENABLED
properties::FloatProperty _atmosphereHeightP;
properties::FloatProperty _groundAverageReflectanceP;
properties::FloatProperty _rayleighHeightScaleP;
properties::FloatProperty _rayleighScatteringCoeffXP;
properties::FloatProperty _rayleighScatteringCoeffYP;
properties::FloatProperty _rayleighScatteringCoeffZP;
properties::BoolProperty _ozoneEnabledP;
properties::FloatProperty _ozoneHeightScaleP;
properties::FloatProperty _ozoneCoeffXP;
properties::FloatProperty _ozoneCoeffYP;
properties::FloatProperty _ozoneCoeffZP;
properties::FloatProperty _mieHeightScaleP;
properties::FloatProperty _mieScatteringCoefficientP;
properties::FloatProperty _mieScatteringExtinctionPropCoefficientP;
properties::FloatProperty _mieAsymmetricFactorGP;
properties::FloatProperty _sunIntensityP;
properties::FloatProperty _hdrExpositionP;
properties::FloatProperty _backgroundExposureP;
properties::FloatProperty _gammaConstantP;
bool _atmosphereEnabled;
bool _ozoneLayerEnabled;
float _atmosphereRadius;
float _atmospherePlanetRadius;
float _planetAverageGroundReflectance;
float _rayleighHeightScale;
float _ozoneHeightScale;
float _mieHeightScale;
float _miePhaseConstant;
float _sunRadianceIntensity;
float _hdrConstant;
float _exposureBackgroundConstant;
float _gammaConstant;
glm::vec3 _mieExtinctionCoeff;
glm::vec3 _rayleighScatteringCoeff;
glm::vec3 _ozoneExtinctionCoeff;
glm::vec3 _mieScatteringCoeff;
// Atmosphere Debug
bool _saveCalculationsToTexture;
float _preCalculatedTexturesScale;
std::unique_ptr<AtmosphereDeferredcaster> _deferredcaster;
#endif
float _alpha;
float _planetRadius;
bool _hasNightTexture;
@@ -168,9 +113,7 @@ private:
glm::dmat3 _stateMatrix;
std::vector< ShadowConf > _shadowConfArray;
std::vector< ShadowConf > _shadowConfArray;
};
} // namespace openspace

View File

@@ -799,12 +799,14 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
#ifdef _NEW_RENDERING_
if (!tasks.deferredcasterTasks.empty()) {
glBindFramebuffer(GL_READ_FRAMEBUFFER, _deferredFramebuffer);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, _deferredFramebuffer);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, defaultFbo);
GLenum dBuffer[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, dBuffer);
glReadBuffer(GL_COLOR_ATTACHMENT0);
glBlitFramebuffer(0, 0, GLsizei(_resolution.x), GLsizei(_resolution.y),
0, 0, GLsizei(_resolution.x), GLsizei(_resolution.y),
GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_FRAMEBUFFER, defaultFbo);
} else {