mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 19:29:04 -05:00
Some changes to PR #432
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# #
|
||||
# OpenSpace #
|
||||
# #
|
||||
# Copyright (c) 2014-2016 #
|
||||
# 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 #
|
||||
|
||||
@@ -89,9 +89,12 @@
|
||||
|
||||
namespace {
|
||||
const char* _loggerCat = "AtmosphereDeferredcaster";
|
||||
const char* GlslDeferredcastPath = "${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl";
|
||||
const char* GlslDeferredcastFSPath = "${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl";
|
||||
const char* GlslDeferredcastVsPath = "${MODULES}/atmosphere/shaders/atmosphere_deferred_vs.glsl";
|
||||
const char* GlslDeferredcastPath =
|
||||
"${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl";
|
||||
const char* GlslDeferredcastFSPath =
|
||||
"${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl";
|
||||
const char* GlslDeferredcastVsPath =
|
||||
"${MODULES}/atmosphere/shaders/atmosphere_deferred_vs.glsl";
|
||||
|
||||
const float ATM_EPS = 2.0;
|
||||
const double KM_TO_M = 1000.0;
|
||||
@@ -151,15 +154,13 @@ AtmosphereDeferredcaster::AtmosphereDeferredcaster()
|
||||
, _saveCalculationTextures(false)
|
||||
{}
|
||||
|
||||
void AtmosphereDeferredcaster::initialize()
|
||||
{
|
||||
void AtmosphereDeferredcaster::initialize() {
|
||||
if (!_atmosphereCalculated) {
|
||||
preCalculateAtmosphereParam();
|
||||
}
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::deinitialize()
|
||||
{
|
||||
void AtmosphereDeferredcaster::deinitialize() {
|
||||
_transmittanceProgramObject = nullptr;
|
||||
_irradianceProgramObject = nullptr;
|
||||
_irradianceSupTermsProgramObject = nullptr;
|
||||
@@ -181,25 +182,40 @@ void AtmosphereDeferredcaster::deinitialize()
|
||||
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, const DeferredcastData& deferredData,
|
||||
void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
const DeferredcastData& deferredData,
|
||||
ghoul::opengl::ProgramObject& program)
|
||||
{
|
||||
// Atmosphere Frustum Culling
|
||||
glm::dvec3 tPlanetPosWorld = glm::dvec3(_modelTransform * glm::dvec4(0.0, 0.0, 0.0, 1.0));
|
||||
glm::dvec3 tPlanetPosWorld = glm::dvec3(
|
||||
_modelTransform * glm::dvec4(0.0, 0.0, 0.0, 1.0)
|
||||
);
|
||||
|
||||
if (glm::distance(tPlanetPosWorld, renderData.camera.positionVec3()) > DISTANCE_CULLING) {
|
||||
double distance = glm::distance(tPlanetPosWorld, renderData.camera.positionVec3());
|
||||
if (distance > DISTANCE_CULLING) {
|
||||
program.setUniform("cullAtmosphere", 1);
|
||||
}
|
||||
else {
|
||||
glm::dmat4 MV = glm::dmat4(renderData.camera.sgctInternal.projectionMatrix()) * renderData.camera.combinedViewMatrix();
|
||||
if (!isAtmosphereInFrustum(glm::value_ptr(MV), tPlanetPosWorld, (_atmosphereRadius + ATM_EPS)*KM_TO_M)) {
|
||||
glm::dmat4 MV = glm::dmat4(
|
||||
renderData.camera.sgctInternal.projectionMatrix()
|
||||
) * renderData.camera.combinedViewMatrix();
|
||||
|
||||
if (!isAtmosphereInFrustum(
|
||||
glm::value_ptr(MV),
|
||||
tPlanetPosWorld,
|
||||
(_atmosphereRadius + ATM_EPS)*KM_TO_M)
|
||||
)
|
||||
{
|
||||
program.setUniform("cullAtmosphere", 1);
|
||||
}
|
||||
else {
|
||||
program.setUniform("cullAtmosphere", 0);
|
||||
program.setUniform("Rg", _atmospherePlanetRadius);
|
||||
program.setUniform("Rt", _atmosphereRadius);
|
||||
program.setUniform("AverageGroundReflectance", _planetAverageGroundReflectance);
|
||||
program.setUniform(
|
||||
"AverageGroundReflectance",
|
||||
_planetAverageGroundReflectance
|
||||
);
|
||||
program.setUniform("groundRadianceEmittion", _planetGroundRadianceEmittion);
|
||||
program.setUniform("HR", _rayleighHeightScale);
|
||||
program.setUniform("betaRayleigh", _rayleighScatteringCoeff);
|
||||
@@ -231,14 +247,26 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, const De
|
||||
program.setUniform("dModelTransformMatrix", _modelTransform);
|
||||
|
||||
// The following scale comes from PSC transformations.
|
||||
float fScaleFactor = renderData.camera.scaling().x * pow(10.0, renderData.camera.scaling().y);
|
||||
float fScaleFactor = renderData.camera.scaling().x *
|
||||
pow(10.0, renderData.camera.scaling().y);
|
||||
glm::dmat4 dfScaleCamTransf = glm::scale(glm::dvec3(fScaleFactor));
|
||||
program.setUniform("dInverseScaleTransformMatrix", glm::inverse(dfScaleCamTransf));
|
||||
program.setUniform(
|
||||
"dInverseScaleTransformMatrix",
|
||||
glm::inverse(dfScaleCamTransf)
|
||||
);
|
||||
|
||||
// World to Eye Space in OS
|
||||
program.setUniform("dInverseCamRotTransform", glm::mat4_cast(static_cast<glm::dquat>(renderData.camera.rotationQuaternion())));
|
||||
program.setUniform(
|
||||
"dInverseCamRotTransform",
|
||||
glm::mat4_cast(
|
||||
static_cast<glm::dquat>(renderData.camera.rotationQuaternion())
|
||||
)
|
||||
);
|
||||
|
||||
program.setUniform("dInverseSgctEyeToWorldTranform", glm::inverse(renderData.camera.combinedViewMatrix()));
|
||||
program.setUniform(
|
||||
"dInverseSgctEyeToWorldTranform",
|
||||
glm::inverse(renderData.camera.combinedViewMatrix())
|
||||
);
|
||||
|
||||
// Eye Space in OS to Eye Space in SGCT
|
||||
glm::dmat4 dOsEye2SGCTEye = glm::dmat4(renderData.camera.viewMatrix());
|
||||
@@ -255,12 +283,22 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, const De
|
||||
program.setUniform("dCampos", renderData.camera.positionVec3());
|
||||
|
||||
double lt;
|
||||
glm::dvec3 sunPosWorld = SpiceManager::ref().targetPosition("SUN", "SUN", "GALACTIC", {}, _time, lt);
|
||||
glm::dvec3 sunPosWorld = SpiceManager::ref().targetPosition(
|
||||
"SUN",
|
||||
"SUN",
|
||||
"GALACTIC",
|
||||
{},
|
||||
_time,
|
||||
lt
|
||||
);
|
||||
glm::dvec4 sunPosObj = glm::dvec4(0.0);
|
||||
|
||||
// Sun following camera position
|
||||
if (_sunFollowingCameraEnabled) {
|
||||
sunPosObj = inverseModelMatrix * glm::dvec4(renderData.camera.positionVec3(), 1.0);
|
||||
sunPosObj = inverseModelMatrix * glm::dvec4(
|
||||
renderData.camera.positionVec3(),
|
||||
1.0
|
||||
);
|
||||
}
|
||||
else {
|
||||
sunPosObj = inverseModelMatrix *
|
||||
@@ -278,24 +316,44 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, const De
|
||||
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...
|
||||
// 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);
|
||||
glm::dvec3 sourcePos = SpiceManager::ref().targetPosition(
|
||||
shadowConf.source.first,
|
||||
"SUN", "GALACTIC",
|
||||
{},
|
||||
_time,
|
||||
lt
|
||||
);
|
||||
sourcePos *= KM_TO_M; // converting to meters
|
||||
glm::dvec3 casterPos = SpiceManager::ref().targetPosition(shadowConf.caster.first, "SUN", "GALACTIC", {}, _time, lt);
|
||||
glm::dvec3 casterPos = SpiceManager::ref().targetPosition(
|
||||
shadowConf.caster.first,
|
||||
"SUN", "GALACTIC",
|
||||
{},
|
||||
_time,
|
||||
lt
|
||||
);
|
||||
casterPos *= KM_TO_M; // converting to meters
|
||||
|
||||
// First we determine if the caster is shadowing the current planet (all calculations in World Coordinates):
|
||||
// First we determine if the caster is shadowing the current planet
|
||||
// (all calculations in World Coordinates):
|
||||
glm::dvec3 planetCasterVec = casterPos - renderData.position.dvec3();
|
||||
glm::dvec3 sourceCasterVec = casterPos - sourcePos;
|
||||
double sc_length = glm::length(sourceCasterVec);
|
||||
glm::dvec3 planetCaster_proj = (glm::dot(planetCasterVec, sourceCasterVec) / (sc_length*sc_length)) * sourceCasterVec;
|
||||
glm::dvec3 planetCaster_proj = (
|
||||
glm::dot(planetCasterVec, sourceCasterVec) /
|
||||
(sc_length*sc_length)) * sourceCasterVec;
|
||||
double d_test = glm::length(planetCasterVec - planetCaster_proj);
|
||||
double xp_test = shadowConf.caster.second * sc_length / (shadowConf.source.second + shadowConf.caster.second);
|
||||
double rp_test = shadowConf.caster.second * (glm::length(planetCaster_proj) + xp_test) / xp_test;
|
||||
double xp_test = shadowConf.caster.second *
|
||||
sc_length / (shadowConf.source.second + shadowConf.caster.second);
|
||||
double rp_test = shadowConf.caster.second *
|
||||
(glm::length(planetCaster_proj) + xp_test) / xp_test;
|
||||
|
||||
double casterDistSun = glm::length(casterPos - sunPosWorld);
|
||||
double planetDistSun = glm::length(renderData.position.dvec3() - sunPosWorld);
|
||||
double planetDistSun = glm::length(
|
||||
renderData.position.dvec3() - sunPosWorld
|
||||
);
|
||||
|
||||
ShadowRenderingStruct shadowData;
|
||||
shadowData.isShadowing = false;
|
||||
@@ -309,7 +367,8 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, const De
|
||||
shadowData.rc = shadowConf.caster.second;
|
||||
shadowData.sourceCasterVec = glm::normalize(sourceCasterVec);
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu = shadowData.rc * sc_length / (shadowData.rs - shadowData.rc);
|
||||
shadowData.xu = shadowData.rc * sc_length /
|
||||
(shadowData.rs - shadowData.rc);
|
||||
shadowData.casterPositionVec = casterPos;
|
||||
}
|
||||
shadowDataArray.push_back(shadowData);
|
||||
@@ -361,7 +420,8 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, const De
|
||||
program.setUniform("inscatterTexture", _inScatteringTableTextureUnit);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::postRaycast(const RenderData& renderData, const DeferredcastData& deferredData,
|
||||
void AtmosphereDeferredcaster::postRaycast(const RenderData& renderData,
|
||||
const DeferredcastData& deferredData,
|
||||
ghoul::opengl::ProgramObject& program)
|
||||
{
|
||||
// Deactivate the texture units
|
||||
@@ -390,87 +450,100 @@ void AtmosphereDeferredcaster::setModelTransform(const glm::dmat4& transform) {
|
||||
_modelTransform = transform;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setTime(const double time) {
|
||||
void AtmosphereDeferredcaster::setTime(double time) {
|
||||
_time = time;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setAtmosphereRadius(const float atmRadius) {
|
||||
void AtmosphereDeferredcaster::setAtmosphereRadius(float atmRadius) {
|
||||
_atmosphereRadius = atmRadius;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setPlanetRadius(const float planetRadius) {
|
||||
void AtmosphereDeferredcaster::setPlanetRadius(float planetRadius) {
|
||||
_atmospherePlanetRadius = planetRadius;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setPlanetAverageGroundReflectance(const float averageGReflectance) {
|
||||
void AtmosphereDeferredcaster::setPlanetAverageGroundReflectance(
|
||||
float averageGReflectance)
|
||||
{
|
||||
_planetAverageGroundReflectance = averageGReflectance;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setPlanetGroundRadianceEmittion(const float groundRadianceEmittion) {
|
||||
void AtmosphereDeferredcaster::setPlanetGroundRadianceEmittion(
|
||||
float groundRadianceEmittion)
|
||||
{
|
||||
_planetGroundRadianceEmittion = groundRadianceEmittion;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setRayleighHeightScale(const float rayleighHeightScale) {
|
||||
void AtmosphereDeferredcaster::setRayleighHeightScale(float rayleighHeightScale) {
|
||||
_rayleighHeightScale = rayleighHeightScale;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::enableOzone(const bool enable) {
|
||||
void AtmosphereDeferredcaster::enableOzone(bool enable) {
|
||||
_ozoneEnabled = enable;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setOzoneHeightScale(const float ozoneHeightScale) {
|
||||
void AtmosphereDeferredcaster::setOzoneHeightScale(float ozoneHeightScale) {
|
||||
_ozoneHeightScale = ozoneHeightScale;
|
||||
}
|
||||
|
||||
|
||||
void AtmosphereDeferredcaster::setMieHeightScale(const float mieHeightScale) {
|
||||
void AtmosphereDeferredcaster::setMieHeightScale(float mieHeightScale) {
|
||||
_mieHeightScale = mieHeightScale;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setMiePhaseConstant(const float miePhaseConstant) {
|
||||
void AtmosphereDeferredcaster::setMiePhaseConstant(float miePhaseConstant) {
|
||||
_miePhaseConstant = miePhaseConstant;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setSunRadianceIntensity(const float sunRadiance) {
|
||||
void AtmosphereDeferredcaster::setSunRadianceIntensity(float sunRadiance) {
|
||||
_sunRadianceIntensity = sunRadiance;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setRayleighScatteringCoefficients(const glm::vec3 & rayScattCoeff) {
|
||||
void AtmosphereDeferredcaster::setRayleighScatteringCoefficients(
|
||||
const glm::vec3& rayScattCoeff)
|
||||
{
|
||||
_rayleighScatteringCoeff = rayScattCoeff;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setOzoneExtinctionCoefficients(const glm::vec3 & ozoneExtCoeff) {
|
||||
void AtmosphereDeferredcaster::setOzoneExtinctionCoefficients(
|
||||
const glm::vec3& ozoneExtCoeff)
|
||||
{
|
||||
_ozoneExtinctionCoeff = ozoneExtCoeff;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setMieScatteringCoefficients(const glm::vec3 & mieScattCoeff) {
|
||||
void AtmosphereDeferredcaster::setMieScatteringCoefficients(
|
||||
const glm::vec3& mieScattCoeff)
|
||||
{
|
||||
_mieScatteringCoeff = mieScattCoeff;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setMieExtinctionCoefficients(const glm::vec3 & mieExtCoeff) {
|
||||
void AtmosphereDeferredcaster::setMieExtinctionCoefficients(const glm::vec3& mieExtCoeff)
|
||||
{
|
||||
_mieExtinctionCoeff = mieExtCoeff;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setEllipsoidRadii(const glm::dvec3 & radii) {
|
||||
void AtmosphereDeferredcaster::setEllipsoidRadii(const glm::dvec3& radii) {
|
||||
_ellipsoidRadii = radii;
|
||||
}
|
||||
|
||||
|
||||
void AtmosphereDeferredcaster::setHardShadows(const bool enabled) {
|
||||
void AtmosphereDeferredcaster::setHardShadows(bool enabled) {
|
||||
_hardShadowsEnabled = enabled;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setShadowConfigArray(
|
||||
const std::vector<ShadowConfiguration>& shadowConfigArray) {
|
||||
const std::vector<ShadowConfiguration>& shadowConfigArray)
|
||||
{
|
||||
_shadowConfArray = shadowConfigArray;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::enableSunFollowing(const bool enable) {
|
||||
void AtmosphereDeferredcaster::enableSunFollowing(bool enable) {
|
||||
_sunFollowingCameraEnabled = enable;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setPrecalculationTextureScale(const float _preCalculatedTexturesScale) {
|
||||
_calculationTextureScale = _preCalculatedTexturesScale;
|
||||
void AtmosphereDeferredcaster::setPrecalculationTextureScale(
|
||||
float preCalculatedTexturesScale)
|
||||
{
|
||||
_calculationTextureScale = preCalculatedTexturesScale;
|
||||
_transmittance_table_width *= static_cast<unsigned int>(_calculationTextureScale);
|
||||
_transmittance_table_height *= static_cast<unsigned int>(_calculationTextureScale);
|
||||
_irradiance_table_width *= static_cast<unsigned int>(_calculationTextureScale);
|
||||
@@ -496,7 +569,9 @@ void AtmosphereDeferredcaster::loadComputationPrograms() {
|
||||
absPath("${MODULE_ATMOSPHERE}/shaders/transmittance_calc_fs.glsl"));
|
||||
}
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_transmittanceProgramObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_transmittanceProgramObject->setIgnoreSubroutineUniformLocationError(
|
||||
IgnoreError::Yes
|
||||
);
|
||||
_transmittanceProgramObject->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
//============== Irradiance E =================
|
||||
@@ -515,7 +590,9 @@ void AtmosphereDeferredcaster::loadComputationPrograms() {
|
||||
absPath("${MODULE_ATMOSPHERE}/shaders/irradiance_sup_calc_vs.glsl"),
|
||||
absPath("${MODULE_ATMOSPHERE}/shaders/irradiance_sup_calc_fs.glsl"));
|
||||
}
|
||||
_irradianceSupTermsProgramObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_irradianceSupTermsProgramObject->setIgnoreSubroutineUniformLocationError(
|
||||
IgnoreError::Yes
|
||||
);
|
||||
_irradianceSupTermsProgramObject->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
//============== InScattering S =================
|
||||
@@ -536,7 +613,9 @@ void AtmosphereDeferredcaster::loadComputationPrograms() {
|
||||
absPath("${MODULE_ATMOSPHERE}/shaders/inScattering_sup_calc_fs.glsl"),
|
||||
absPath("${MODULE_ATMOSPHERE}/shaders/inScattering_sup_calc_gs.glsl"));
|
||||
}
|
||||
_inScatteringSupTermsProgramObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_inScatteringSupTermsProgramObject->setIgnoreSubroutineUniformLocationError(
|
||||
IgnoreError::Yes
|
||||
);
|
||||
_inScatteringSupTermsProgramObject->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
//============== Delta E =================
|
||||
@@ -556,7 +635,9 @@ void AtmosphereDeferredcaster::loadComputationPrograms() {
|
||||
absPath("${MODULE_ATMOSPHERE}/shaders/irradiance_final_vs.glsl"),
|
||||
absPath("${MODULE_ATMOSPHERE}/shaders/irradiance_final_fs.glsl"));
|
||||
}
|
||||
_irradianceFinalProgramObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_irradianceFinalProgramObject->setIgnoreSubroutineUniformLocationError(
|
||||
IgnoreError::Yes
|
||||
);
|
||||
_irradianceFinalProgramObject->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
//============== Delta S =================
|
||||
@@ -577,7 +658,9 @@ void AtmosphereDeferredcaster::loadComputationPrograms() {
|
||||
absPath("${MODULE_ATMOSPHERE}/shaders/deltaS_sup_calc_fs.glsl"),
|
||||
absPath("${MODULE_ATMOSPHERE}/shaders/deltaS_sup_calc_gs.glsl"));
|
||||
}
|
||||
_deltaSSupTermsProgramObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_deltaSSupTermsProgramObject->setIgnoreSubroutineUniformLocationError(
|
||||
IgnoreError::Yes
|
||||
);
|
||||
_deltaSSupTermsProgramObject->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
//============== Delta J (Radiance Scattered) =================
|
||||
@@ -593,45 +676,16 @@ void AtmosphereDeferredcaster::loadComputationPrograms() {
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::unloadComputationPrograms() {
|
||||
if (_transmittanceProgramObject) {
|
||||
_transmittanceProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_irradianceProgramObject) {
|
||||
_irradianceProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_irradianceSupTermsProgramObject) {
|
||||
_irradianceSupTermsProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_inScatteringProgramObject) {
|
||||
_inScatteringProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_inScatteringSupTermsProgramObject) {
|
||||
_inScatteringSupTermsProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_deltaEProgramObject) {
|
||||
_deltaEProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_irradianceFinalProgramObject) {
|
||||
_irradianceFinalProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_deltaSProgramObject) {
|
||||
_deltaSProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_deltaSSupTermsProgramObject) {
|
||||
_deltaSSupTermsProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_deltaJProgramObject) {
|
||||
_deltaJProgramObject = nullptr;
|
||||
}
|
||||
_transmittanceProgramObject = nullptr;
|
||||
_irradianceProgramObject = nullptr;
|
||||
_irradianceSupTermsProgramObject = nullptr;
|
||||
_inScatteringProgramObject = nullptr;
|
||||
_inScatteringSupTermsProgramObject = nullptr;
|
||||
_deltaEProgramObject = nullptr;
|
||||
_irradianceFinalProgramObject = nullptr;
|
||||
_deltaSProgramObject = nullptr;
|
||||
_deltaSSupTermsProgramObject = nullptr;
|
||||
_deltaJProgramObject = nullptr;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::createComputationTextures() {
|
||||
@@ -752,9 +806,9 @@ void AtmosphereDeferredcaster::deleteUnusedComputationTextures() {
|
||||
glDeleteTextures(1, &_deltaJTableTexture);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
const GLenum drawBuffers[1],
|
||||
const GLsizei vertexSize)
|
||||
void AtmosphereDeferredcaster::executeCalculations(GLuint quadCalcVAO,
|
||||
GLenum drawBuffers[1],
|
||||
GLsizei vertexSize)
|
||||
{
|
||||
ghoul::opengl::TextureUnit transmittanceTableTextureUnit;
|
||||
ghoul::opengl::TextureUnit irradianceTableTextureUnit;
|
||||
@@ -773,8 +827,9 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
GLenum blendSrcAlpha;
|
||||
GLenum blendSrcRGB;
|
||||
|
||||
if (blendEnabled)
|
||||
if (blendEnabled) {
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB);
|
||||
glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha);
|
||||
glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha);
|
||||
@@ -785,7 +840,12 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
// ===========================================================
|
||||
// See Precomputed Atmosphere Scattering from Bruneton et al. paper, algorithm 4.1:
|
||||
// ===========================================================
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _transmittanceTableTexture, 0);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_transmittanceTableTexture,
|
||||
0
|
||||
);
|
||||
checkFrameBufferState("_transmittanceTableTexture");
|
||||
glViewport(0, 0, _transmittance_table_width, _transmittance_table_height);
|
||||
_transmittanceProgramObject->activate();
|
||||
@@ -795,8 +855,12 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
glClearBufferfv(GL_COLOR, 0, black);
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
if (_saveCalculationTextures) {
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, std::string("transmittance_texture.ppm"),
|
||||
_transmittance_table_width, _transmittance_table_height);
|
||||
saveTextureToPPMFile(
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
std::string("transmittance_texture.ppm"),
|
||||
_transmittance_table_width,
|
||||
_transmittance_table_height
|
||||
);
|
||||
}
|
||||
_transmittanceProgramObject->deactivate();
|
||||
|
||||
@@ -807,19 +871,36 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_irradianceProgramObject->activate();
|
||||
transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
_irradianceProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
_irradianceProgramObject->setUniform(
|
||||
"transmittanceTexture",
|
||||
transmittanceTableTextureUnit
|
||||
);
|
||||
loadAtmosphereDataIntoShaderProgram(_irradianceProgramObject);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
if (_saveCalculationTextures) {
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, std::string("deltaE_table_texture.ppm"),
|
||||
_delta_e_table_width, _delta_e_table_height);
|
||||
saveTextureToPPMFile(
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
std::string("deltaE_table_texture.ppm"),
|
||||
_delta_e_table_width,
|
||||
_delta_e_table_height
|
||||
);
|
||||
}
|
||||
_irradianceProgramObject->deactivate();
|
||||
|
||||
// line 3 in algorithm 4.1
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _deltaSRayleighTableTexture, 0);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, _deltaSMieTableTexture, 0);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_deltaSRayleighTableTexture,
|
||||
0
|
||||
);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT1,
|
||||
_deltaSMieTableTexture,
|
||||
0
|
||||
);
|
||||
GLenum colorBuffers[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
|
||||
glDrawBuffers(2, colorBuffers);
|
||||
checkFrameBufferState("_deltaSRay and _deltaSMie TableTexture");
|
||||
@@ -827,7 +908,10 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_inScatteringProgramObject->activate();
|
||||
transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
_inScatteringProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
_inScatteringProgramObject->setUniform(
|
||||
"transmittanceTexture",
|
||||
transmittanceTableTextureUnit
|
||||
);
|
||||
loadAtmosphereDataIntoShaderProgram(_inScatteringProgramObject);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
for (int layer = 0; layer < static_cast<int>(_r_samples); ++layer) {
|
||||
@@ -835,10 +919,18 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
}
|
||||
if (_saveCalculationTextures) {
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, std::string("deltaS_rayleigh_texture.ppm"),
|
||||
_mu_s_samples * _nu_samples, _mu_samples);
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT1, std::string("deltaS_mie_texture.ppm"),
|
||||
_mu_s_samples * _nu_samples, _mu_samples);
|
||||
saveTextureToPPMFile(
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
std::string("deltaS_rayleigh_texture.ppm"),
|
||||
_mu_s_samples * _nu_samples,
|
||||
_mu_samples
|
||||
);
|
||||
saveTextureToPPMFile(
|
||||
GL_COLOR_ATTACHMENT1,
|
||||
std::string("deltaS_mie_texture.ppm"),
|
||||
_mu_s_samples * _nu_samples,
|
||||
_mu_samples
|
||||
);
|
||||
}
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
|
||||
glDrawBuffers(1, drawBuffers);
|
||||
@@ -846,7 +938,12 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_inScatteringProgramObject->deactivate();
|
||||
|
||||
// line 4 in algorithm 4.1
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _irradianceTableTexture, 0);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_irradianceTableTexture,
|
||||
0
|
||||
);
|
||||
checkFrameBufferState("_irradianceTableTexture");
|
||||
glDrawBuffer(GL_COLOR_ATTACHMENT0);
|
||||
|
||||
@@ -866,7 +963,12 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_deltaEProgramObject->deactivate();
|
||||
|
||||
// line 5 in algorithm 4.1
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _inScatteringTableTexture, 0);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_inScatteringTableTexture,
|
||||
0
|
||||
);
|
||||
checkFrameBufferState("_inScatteringTableTexture");
|
||||
glViewport(0, 0, _mu_s_samples * _nu_samples, _mu_samples);
|
||||
_deltaSProgramObject->activate();
|
||||
@@ -892,7 +994,12 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
for (int scatteringOrder = 2; scatteringOrder <= 4; ++scatteringOrder) {
|
||||
|
||||
// line 7 in algorithm 4.1
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _deltaJTableTexture, 0);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_deltaJTableTexture,
|
||||
0
|
||||
);
|
||||
checkFrameBufferState("_deltaJTableTexture");
|
||||
glViewport(0, 0, _mu_s_samples * _nu_samples, _mu_samples);
|
||||
_deltaJProgramObject->activate();
|
||||
@@ -904,13 +1011,19 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
}
|
||||
transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
_deltaJProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
_deltaJProgramObject->setUniform(
|
||||
"transmittanceTexture",
|
||||
transmittanceTableTextureUnit
|
||||
);
|
||||
deltaETableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _deltaETableTexture);
|
||||
_deltaJProgramObject->setUniform("deltaETexture", deltaETableTextureUnit);
|
||||
deltaSRayleighTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaSRayleighTableTexture);
|
||||
_deltaJProgramObject->setUniform("deltaSRTexture", deltaSRayleighTableTextureUnit);
|
||||
_deltaJProgramObject->setUniform(
|
||||
"deltaSRTexture",
|
||||
deltaSRayleighTableTextureUnit
|
||||
);
|
||||
deltaSMieTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaSMieTableTexture);
|
||||
_deltaJProgramObject->setUniform("deltaSMTexture", deltaSMieTableTextureUnit);
|
||||
@@ -928,25 +1041,45 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_deltaJProgramObject->deactivate();
|
||||
|
||||
// line 8 in algorithm 4.1
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _deltaETableTexture, 0);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_deltaETableTexture,
|
||||
0
|
||||
);
|
||||
checkFrameBufferState("_deltaETableTexture");
|
||||
glViewport(0, 0, _delta_e_table_width, _delta_e_table_height);
|
||||
_irradianceSupTermsProgramObject->activate();
|
||||
if (scatteringOrder == 2) {
|
||||
_irradianceSupTermsProgramObject->setUniform("firstIteraction", static_cast<int>(1));
|
||||
_irradianceSupTermsProgramObject->setUniform(
|
||||
"firstIteraction",
|
||||
static_cast<int>(1)
|
||||
);
|
||||
}
|
||||
else {
|
||||
_irradianceSupTermsProgramObject->setUniform("firstIteraction", static_cast<int>(0));
|
||||
_irradianceSupTermsProgramObject->setUniform(
|
||||
"firstIteraction",
|
||||
static_cast<int>(0)
|
||||
);
|
||||
}
|
||||
transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
_irradianceSupTermsProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
_irradianceSupTermsProgramObject->setUniform(
|
||||
"transmittanceTexture",
|
||||
transmittanceTableTextureUnit
|
||||
);
|
||||
deltaSRayleighTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaSRayleighTableTexture);
|
||||
_irradianceSupTermsProgramObject->setUniform("deltaSRTexture", deltaSRayleighTableTextureUnit);
|
||||
_irradianceSupTermsProgramObject->setUniform(
|
||||
"deltaSRTexture",
|
||||
deltaSRayleighTableTextureUnit
|
||||
);
|
||||
deltaSMieTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaSMieTableTexture);
|
||||
_irradianceSupTermsProgramObject->setUniform("deltaSMTexture", deltaSMieTableTextureUnit);
|
||||
_irradianceSupTermsProgramObject->setUniform(
|
||||
"deltaSMTexture",
|
||||
deltaSMieTableTextureUnit
|
||||
);
|
||||
loadAtmosphereDataIntoShaderProgram(_irradianceSupTermsProgramObject);
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
if (_saveCalculationTextures) {
|
||||
@@ -958,16 +1091,27 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_irradianceSupTermsProgramObject->deactivate();
|
||||
|
||||
// line 9 in algorithm 4.1
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _deltaSRayleighTableTexture, 0);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_deltaSRayleighTableTexture,
|
||||
0
|
||||
);
|
||||
checkFrameBufferState("_deltaSRayleighTableTexture");
|
||||
glViewport(0, 0, _mu_s_samples * _nu_samples, _mu_samples);
|
||||
_inScatteringSupTermsProgramObject->activate();
|
||||
transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
_inScatteringSupTermsProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
_inScatteringSupTermsProgramObject->setUniform(
|
||||
"transmittanceTexture",
|
||||
transmittanceTableTextureUnit
|
||||
);
|
||||
deltaJTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaJTableTexture);
|
||||
_inScatteringSupTermsProgramObject->setUniform("deltaJTexture", deltaJTableTextureUnit);
|
||||
_inScatteringSupTermsProgramObject->setUniform(
|
||||
"deltaJTexture",
|
||||
deltaJTableTextureUnit
|
||||
);
|
||||
loadAtmosphereDataIntoShaderProgram(_inScatteringSupTermsProgramObject);
|
||||
for (int layer = 0; layer < static_cast<int>(_r_samples); ++layer) {
|
||||
step3DTexture(_inScatteringSupTermsProgramObject, layer);
|
||||
@@ -976,8 +1120,12 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
if (_saveCalculationTextures) {
|
||||
sst.str(std::string());
|
||||
sst << "deltaS_texture-scattering_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, sst.str(),
|
||||
_mu_s_samples * _nu_samples, _mu_samples);
|
||||
saveTextureToPPMFile(
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
sst.str(),
|
||||
_mu_s_samples * _nu_samples,
|
||||
_mu_samples
|
||||
);
|
||||
}
|
||||
_inScatteringSupTermsProgramObject->deactivate();
|
||||
|
||||
@@ -986,13 +1134,21 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ONE);
|
||||
|
||||
// line 10 in algorithm 4.1
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _irradianceTableTexture, 0);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_irradianceTableTexture,
|
||||
0
|
||||
);
|
||||
checkFrameBufferState("_irradianceTableTexture");
|
||||
glViewport(0, 0, _delta_e_table_width, _delta_e_table_height);
|
||||
_irradianceFinalProgramObject->activate();
|
||||
deltaETableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _deltaETableTexture);
|
||||
_irradianceFinalProgramObject->setUniform("deltaETexture", deltaETableTextureUnit);
|
||||
_irradianceFinalProgramObject->setUniform(
|
||||
"deltaETexture",
|
||||
deltaETableTextureUnit
|
||||
);
|
||||
loadAtmosphereDataIntoShaderProgram(_irradianceFinalProgramObject);
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
if (_saveCalculationTextures) {
|
||||
@@ -1004,13 +1160,21 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_irradianceFinalProgramObject->deactivate();
|
||||
|
||||
// line 11 in algorithm 4.1
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, _inScatteringTableTexture, 0);
|
||||
glFramebufferTexture(
|
||||
GL_FRAMEBUFFER,
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
_inScatteringTableTexture,
|
||||
0
|
||||
);
|
||||
checkFrameBufferState("_inScatteringTableTexture");
|
||||
glViewport(0, 0, _mu_s_samples * _nu_samples, _mu_samples);
|
||||
_deltaSSupTermsProgramObject->activate();
|
||||
deltaSRayleighTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaSRayleighTableTexture);
|
||||
_deltaSSupTermsProgramObject->setUniform("deltaSTexture", deltaSRayleighTableTextureUnit);
|
||||
_deltaSSupTermsProgramObject->setUniform(
|
||||
"deltaSTexture",
|
||||
deltaSRayleighTableTextureUnit
|
||||
);
|
||||
loadAtmosphereDataIntoShaderProgram(_deltaSSupTermsProgramObject);
|
||||
for (int layer = 0; layer < static_cast<int>(_r_samples); ++layer) {
|
||||
step3DTexture(_deltaSSupTermsProgramObject, layer, false);
|
||||
@@ -1033,7 +1197,6 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
|
||||
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
|
||||
glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha);
|
||||
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::preCalculateAtmosphereParam() {
|
||||
@@ -1087,16 +1250,11 @@ void AtmosphereDeferredcaster::preCalculateAtmosphereParam() {
|
||||
LDEBUG("Ended precalculations for Atmosphere effects...");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AtmosphereDeferredcaster::resetAtmosphereTextures()
|
||||
{
|
||||
void AtmosphereDeferredcaster::resetAtmosphereTextures(){
|
||||
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::createRenderQuad(GLuint* vao, GLuint* vbo,
|
||||
const GLfloat size) {
|
||||
|
||||
void AtmosphereDeferredcaster::createRenderQuad(GLuint* vao, GLuint* vbo, GLfloat size) {
|
||||
glGenVertexArrays(1, vao);
|
||||
glGenBuffers(1, vbo);
|
||||
glBindVertexArray(*vao);
|
||||
@@ -1113,13 +1271,22 @@ void AtmosphereDeferredcaster::createRenderQuad(GLuint* vao, GLuint* vbo,
|
||||
};
|
||||
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, reinterpret_cast<GLvoid*>(0));
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
4,
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(GLfloat) * 4,
|
||||
reinterpret_cast<GLvoid*>(0)
|
||||
);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::loadAtmosphereDataIntoShaderProgram(std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg) {
|
||||
void AtmosphereDeferredcaster::loadAtmosphereDataIntoShaderProgram(
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg)
|
||||
{
|
||||
shaderProg->setUniform("Rg", _atmospherePlanetRadius);
|
||||
shaderProg->setUniform("Rt", _atmosphereRadius);
|
||||
shaderProg->setUniform("AverageGroundReflectance", _planetAverageGroundReflectance);
|
||||
@@ -1131,8 +1298,14 @@ void AtmosphereDeferredcaster::loadAtmosphereDataIntoShaderProgram(std::unique_p
|
||||
shaderProg->setUniform("betaMieExtinction", _mieExtinctionCoeff);
|
||||
shaderProg->setUniform("mieG", _miePhaseConstant);
|
||||
shaderProg->setUniform("sunRadiance", _sunRadianceIntensity);
|
||||
shaderProg->setUniform("TRANSMITTANCE_W", static_cast<int>(_transmittance_table_width));
|
||||
shaderProg->setUniform("TRANSMITTANCE_H", static_cast<int>(_transmittance_table_height));
|
||||
shaderProg->setUniform(
|
||||
"TRANSMITTANCE_W",
|
||||
static_cast<int>(_transmittance_table_width)
|
||||
);
|
||||
shaderProg->setUniform(
|
||||
"TRANSMITTANCE_H",
|
||||
static_cast<int>(_transmittance_table_height)
|
||||
);
|
||||
shaderProg->setUniform("SKY_W", static_cast<int>(_irradiance_table_width));
|
||||
shaderProg->setUniform("SKY_H", static_cast<int>(_irradiance_table_height));
|
||||
shaderProg->setUniform("OTHER_TEXTURES_W", static_cast<int>(_delta_e_table_width));
|
||||
@@ -1146,7 +1319,9 @@ void AtmosphereDeferredcaster::loadAtmosphereDataIntoShaderProgram(std::unique_p
|
||||
shaderProg->setUniform("betaOzoneExtinction", _ozoneExtinctionCoeff);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::checkFrameBufferState(const std::string & codePosition) const {
|
||||
void AtmosphereDeferredcaster::checkFrameBufferState(
|
||||
const std::string& codePosition) const
|
||||
{
|
||||
if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LERROR("Framework not built. " + codePosition);
|
||||
GLenum fbErr = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
@@ -1161,30 +1336,35 @@ void AtmosphereDeferredcaster::checkFrameBufferState(const std::string & codePos
|
||||
LERROR("Framebuffer doesn't have at least one image attached to it.");
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
|
||||
LERROR("Returned if the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE \
|
||||
for any color attachment point(s) named by GL_DRAW_BUFFERi.");
|
||||
LERROR("Returned if the value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is "
|
||||
"GL_NONE for any color attachment point(s) named by GL_DRAW_BUFFERi.");
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
|
||||
LERROR("Returned if GL_READ_BUFFER is not GL_NONE and the value of \
|
||||
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for the color attachment point \
|
||||
named by GL_READ_BUFFER.");
|
||||
LERROR("Returned if GL_READ_BUFFER is not GL_NONE and the value of "
|
||||
"GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for the color attachment "
|
||||
"point named by GL_READ_BUFFER.");
|
||||
break;
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
LERROR("Returned if the combination of internal formats of the attached images \
|
||||
violates an implementation - dependent set of restrictions.");
|
||||
LERROR("Returned if the combination of internal formats of the attached "
|
||||
"images violates an implementation - dependent set of restrictions.");
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
|
||||
LERROR("Returned if the value of GL_RENDERBUFFE_r_samples is not the same for all \
|
||||
attached renderbuffers; if the value of GL_TEXTURE_SAMPLES is the not same for all \
|
||||
attached textures; or , if the attached images are a mix of renderbuffers and textures, \
|
||||
the value of GL_RENDERBUFFE_r_samples does not match the value of GL_TEXTURE_SAMPLES.");
|
||||
LERROR("Returned if the value of GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not the same \
|
||||
for all attached textures; or , if the attached images are a mix of renderbuffers and \
|
||||
textures, the value of GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not GL_TRUE for all attached textures.");
|
||||
LERROR("Returned if the value of GL_RENDERBUFFE_r_samples is not the same "
|
||||
"for all attached renderbuffers; if the value of GL_TEXTURE_SAMPLES is "
|
||||
"the not same for all attached textures; or , if the attached images are "
|
||||
"a mix of renderbuffers and textures, the value of "
|
||||
"GL_RENDERBUFFE_r_samples does not match the value of "
|
||||
"GL_TEXTURE_SAMPLES.");
|
||||
LERROR("Returned if the value of GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not "
|
||||
"the same for all attached textures; or , if the attached images are a "
|
||||
"mix of renderbuffers and textures, the value of "
|
||||
"GL_TEXTURE_FIXED_SAMPLE_LOCATIONS is not GL_TRUE for all attached "
|
||||
"textures.");
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
|
||||
LERROR("Returned if any framebuffer attachment is layered, and any populated attachment \
|
||||
is not layered, or if all populated color attachments are not from textures of the same target.");
|
||||
LERROR("Returned if any framebuffer attachment is layered, and any populated "
|
||||
"attachment is not layered, or if all populated color attachments are "
|
||||
"not from textures of the same target.");
|
||||
break;
|
||||
default:
|
||||
LDEBUG("No error found checking framebuffer: " + codePosition);
|
||||
@@ -1193,23 +1373,27 @@ void AtmosphereDeferredcaster::checkFrameBufferState(const std::string & codePos
|
||||
}
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::renderQuadForCalc(const GLuint vao, const GLsizei numberOfVertices) {
|
||||
void AtmosphereDeferredcaster::renderQuadForCalc(GLuint vao, GLsizei numberOfVertices) {
|
||||
glBindVertexArray(vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, numberOfVertices);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::step3DTexture(std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg,
|
||||
const int layer, const bool doCalc) {
|
||||
void AtmosphereDeferredcaster::step3DTexture(
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg,
|
||||
int layer, bool doCalc)
|
||||
{
|
||||
// See OpenGL redbook 8th Edition page 556 for Layered Rendering
|
||||
if (doCalc)
|
||||
{
|
||||
if (doCalc) {
|
||||
float earth2 = _atmospherePlanetRadius * _atmospherePlanetRadius;
|
||||
float atm2 = _atmosphereRadius * _atmosphereRadius;
|
||||
float diff = atm2 - earth2;
|
||||
float ri = static_cast<float>(layer) / static_cast<float>(_r_samples - 1);
|
||||
float ri_2 = ri * ri;
|
||||
float epsilon = (layer == 0) ? 0.01f : (layer == (static_cast<int>(_r_samples) - 1)) ? -0.001f : 0.0f;
|
||||
float epsilon =
|
||||
(layer == 0) ?
|
||||
0.01f :
|
||||
(layer == (static_cast<int>(_r_samples) - 1)) ? -0.001f : 0.0f;
|
||||
float r = sqrtf(earth2 + ri_2 * diff) + epsilon;
|
||||
float dminG = r - _atmospherePlanetRadius;
|
||||
float dminT = _atmosphereRadius - r;
|
||||
@@ -1223,9 +1407,10 @@ void AtmosphereDeferredcaster::step3DTexture(std::unique_ptr<ghoul::opengl::Prog
|
||||
shaderProg->setUniform("layer", static_cast<int>(layer));
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::saveTextureToPPMFile(const GLenum color_buffer_attachment,
|
||||
const std::string & fileName,
|
||||
const int width, const int height) const {
|
||||
void AtmosphereDeferredcaster::saveTextureToPPMFile(GLenum color_buffer_attachment,
|
||||
const std::string& fileName,
|
||||
int width, int height) const
|
||||
{
|
||||
std::fstream ppmFile;
|
||||
|
||||
ppmFile.open(fileName.c_str(), std::fstream::out);
|
||||
@@ -1240,7 +1425,15 @@ void AtmosphereDeferredcaster::saveTextureToPPMFile(const GLenum color_buffer_at
|
||||
|
||||
}
|
||||
else {
|
||||
glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, pixels);
|
||||
glReadPixels(
|
||||
0,
|
||||
0,
|
||||
width,
|
||||
height,
|
||||
GL_DEPTH_COMPONENT,
|
||||
GL_UNSIGNED_BYTE,
|
||||
pixels
|
||||
);
|
||||
}
|
||||
|
||||
ppmFile << "P3" << std::endl;
|
||||
@@ -1264,7 +1457,10 @@ void AtmosphereDeferredcaster::saveTextureToPPMFile(const GLenum color_buffer_at
|
||||
}
|
||||
}
|
||||
|
||||
bool AtmosphereDeferredcaster::isAtmosphereInFrustum(const double * MVMatrix, const glm::dvec3 position, const double radius) const {
|
||||
bool AtmosphereDeferredcaster::isAtmosphereInFrustum(const double* MVMatrix,
|
||||
const glm::dvec3& position,
|
||||
double radius) const
|
||||
{
|
||||
|
||||
// Frustum Planes
|
||||
glm::dvec3 col1(MVMatrix[0], MVMatrix[4], MVMatrix[8]);
|
||||
|
||||
@@ -36,8 +36,7 @@
|
||||
namespace ghoul::opengl {
|
||||
class Texture;
|
||||
class ProgramObject;
|
||||
|
||||
}
|
||||
} // namespace ghoul::opengl
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -65,27 +64,27 @@ public:
|
||||
void preCalculateAtmosphereParam();
|
||||
|
||||
void setModelTransform(const glm::dmat4 &transform);
|
||||
void setTime(const double time);
|
||||
void setAtmosphereRadius(const float atmRadius);
|
||||
void setPlanetRadius(const float planetRadius);
|
||||
void setPlanetAverageGroundReflectance(const float averageGReflectance);
|
||||
void setPlanetGroundRadianceEmittion(const float groundRadianceEmittion);
|
||||
void setRayleighHeightScale(const float rayleighHeightScale);
|
||||
void enableOzone(const bool enable);
|
||||
void setOzoneHeightScale(const float ozoneHeightScale);
|
||||
void setMieHeightScale(const float mieHeightScale);
|
||||
void setMiePhaseConstant(const float miePhaseConstant);
|
||||
void setSunRadianceIntensity(const float sunRadiance);
|
||||
void setRayleighScatteringCoefficients(const glm::vec3 & rayScattCoeff);
|
||||
void setOzoneExtinctionCoefficients(const glm::vec3 & ozoneExtCoeff);
|
||||
void setMieScatteringCoefficients(const glm::vec3 & mieScattCoeff);
|
||||
void setMieExtinctionCoefficients(const glm::vec3 & mieExtCoeff);
|
||||
void setEllipsoidRadii(const glm::dvec3 & radii);
|
||||
void setTime(double time);
|
||||
void setAtmosphereRadius(float atmRadius);
|
||||
void setPlanetRadius(float planetRadius);
|
||||
void setPlanetAverageGroundReflectance(float averageGReflectance);
|
||||
void setPlanetGroundRadianceEmittion(float groundRadianceEmittion);
|
||||
void setRayleighHeightScale(float rayleighHeightScale);
|
||||
void enableOzone(bool enable);
|
||||
void setOzoneHeightScale(float ozoneHeightScale);
|
||||
void setMieHeightScale(float mieHeightScale);
|
||||
void setMiePhaseConstant(float miePhaseConstant);
|
||||
void setSunRadianceIntensity(float sunRadiance);
|
||||
void setRayleighScatteringCoefficients(const glm::vec3& rayScattCoeff);
|
||||
void setOzoneExtinctionCoefficients(const glm::vec3& ozoneExtCoeff);
|
||||
void setMieScatteringCoefficients(const glm::vec3& mieScattCoeff);
|
||||
void setMieExtinctionCoefficients(const glm::vec3& mieExtCoeff);
|
||||
void setEllipsoidRadii(const glm::dvec3& radii);
|
||||
void setShadowConfigArray(const std::vector<ShadowConfiguration>& shadowConfigArray);
|
||||
void setHardShadows(const bool enabled);
|
||||
void enableSunFollowing(const bool enable);
|
||||
void setHardShadows(bool enabled);
|
||||
void enableSunFollowing(bool enable);
|
||||
|
||||
void setPrecalculationTextureScale(const float _preCalculatedTexturesScale);
|
||||
void setPrecalculationTextureScale(float preCalculatedTexturesScale);
|
||||
void enablePrecalculationTexturesSaving();
|
||||
|
||||
private:
|
||||
@@ -94,21 +93,21 @@ private:
|
||||
void createComputationTextures();
|
||||
void deleteComputationTextures();
|
||||
void deleteUnusedComputationTextures();
|
||||
void executeCalculations(const GLuint quadCalcVAO,
|
||||
const GLenum drawBuffers[1],
|
||||
const GLsizei vertexSize);
|
||||
void executeCalculations(GLuint quadCalcVAO, GLenum drawBuffers[1],
|
||||
GLsizei vertexSize);
|
||||
void resetAtmosphereTextures();
|
||||
void createRenderQuad(GLuint * vao, GLuint * vbo,
|
||||
const GLfloat size);
|
||||
void step3DTexture(std::unique_ptr<ghoul::opengl::ProgramObject> & shaderProg,
|
||||
const int layer, const bool doCalc = true);
|
||||
void checkFrameBufferState(const std::string & codePosition) const;
|
||||
void loadAtmosphereDataIntoShaderProgram(std::unique_ptr<ghoul::opengl::ProgramObject> & shaderProg);
|
||||
void renderQuadForCalc(const GLuint vao, const GLsizei numberOfVertices);
|
||||
void saveTextureToPPMFile(const GLenum color_buffer_attachment,
|
||||
const std::string & fileName,
|
||||
const int width, const int height) const;
|
||||
bool isAtmosphereInFrustum(const double * MVMatrix, const glm::dvec3 position, const double radius) const;
|
||||
void createRenderQuad(GLuint* vao, GLuint* vbo, GLfloat size);
|
||||
void step3DTexture(std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg,
|
||||
int layer, bool doCalc = true);
|
||||
void checkFrameBufferState(const std::string& codePosition) const;
|
||||
void loadAtmosphereDataIntoShaderProgram(
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> & shaderProg
|
||||
);
|
||||
void renderQuadForCalc(GLuint vao, GLsizei numberOfVertices);
|
||||
void saveTextureToPPMFile(GLenum color_buffer_attachment, const std::string& fileName,
|
||||
int width, int height) const;
|
||||
bool isAtmosphereInFrustum(const double* MVMatrix, const glm::dvec3& position,
|
||||
double radius) const;
|
||||
|
||||
|
||||
const double DISTANCE_CULLING = 1e10;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -80,7 +80,6 @@ public:
|
||||
|
||||
RenderableAtmosphere(const ghoul::Dictionary& dictionary);
|
||||
|
||||
void initialize() override;
|
||||
void deinitialize() override;
|
||||
void initializeGL() override;
|
||||
void deinitializeGL() override;
|
||||
@@ -148,8 +147,6 @@ private:
|
||||
glm::dmat3 _stateMatrix;
|
||||
|
||||
std::vector<ShadowConfiguration> _shadowConfArray;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -236,11 +236,15 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary)
|
||||
_texturePath.onChange([this]() { loadTexture(); });
|
||||
|
||||
if (dictionary.hasKey(FadeOutThreshouldInfo.identifier)) {
|
||||
_fadeOutThreshold = static_cast<float>(dictionary.value<double>(FadeOutThreshouldInfo.identifier));
|
||||
_fadeOutThreshold = static_cast<float>(
|
||||
dictionary.value<double>(FadeOutThreshouldInfo.identifier)
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(FadeInThreshouldInfo.identifier)) {
|
||||
_fadeInThreshold = static_cast<float>(dictionary.value<double>(FadeInThreshouldInfo.identifier));
|
||||
_fadeInThreshold = static_cast<float>(
|
||||
dictionary.value<double>(FadeInThreshouldInfo.identifier)
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(FadeOutThreshouldInfo.identifier) ||
|
||||
@@ -299,14 +303,21 @@ void RenderableSphere::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
if (_fadeInThreshold > 0.0) {
|
||||
float distCamera = glm::length(data.camera.positionVec3());
|
||||
float funcValue = static_cast<float>((1.0 / double(_fadeInThreshold/1E24))*(distCamera / 1E24));
|
||||
float funcValue = static_cast<float>(
|
||||
(1.0 / double(_fadeInThreshold/1E24))*(distCamera / 1E24)
|
||||
);
|
||||
|
||||
adjustedTransparency *= funcValue > 1.0 ? 1.0 : funcValue;
|
||||
}
|
||||
|
||||
if (_fadeOutThreshold > -1.0) {
|
||||
float distCamera = glm::distance(data.camera.positionVec3(), data.position.dvec3());
|
||||
double term = std::exp((-distCamera + _size * _fadeOutThreshold) / (_size * _fadeOutThreshold));
|
||||
float distCamera = glm::distance(
|
||||
data.camera.positionVec3(),
|
||||
data.position.dvec3()
|
||||
);
|
||||
double term = std::exp(
|
||||
(-distCamera + _size * _fadeOutThreshold) / (_size * _fadeOutThreshold)
|
||||
);
|
||||
|
||||
adjustedTransparency *= static_cast<float>(term / (term + 1.0));
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* 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 *
|
||||
@@ -21,10 +21,11 @@
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
out vec4 renderTableColor;
|
||||
|
||||
void main(void) {
|
||||
renderTableColor = vec4(0.0);
|
||||
void main() {
|
||||
renderTableColor = vec4(0.0);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2016 *
|
||||
* 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 *
|
||||
@@ -28,4 +28,4 @@ layout(location = 0) in vec3 in_position;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(in_position, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,11 +161,47 @@ namespace {
|
||||
"astronomical objects."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo TransformationMatrixInfo =
|
||||
{
|
||||
"TransformationMatrix",
|
||||
"Transformation Matrix",
|
||||
"Transformation matrix to be applied to each astronomical object."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo RenderOptionInfo = {
|
||||
"RenderOptionInfo",
|
||||
"Render Option",
|
||||
"Debug option for rendering of billboards and texts."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo FadeInDistancesInfo = {
|
||||
"FadeInDistances",
|
||||
"Fade-In Start and End Distances",
|
||||
"These values determine the initial and final distances from the center of "
|
||||
"our galaxy from which the astronomical object will start and end "
|
||||
"fading-in."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo DisableFadeInInfo = {
|
||||
"DisableFadeIn",
|
||||
"Disable Fade-in effect",
|
||||
"Enables/Disables the Fade-in effect."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo BillboardMaxSizeInfo = {
|
||||
"BillboardMaxSize",
|
||||
"Billboard Max Size in Pixels",
|
||||
"The max size (in pixels) for the billboard representing the astronomical "
|
||||
"object."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo BillboardMinSizeInfo = {
|
||||
"BillboardMinSize",
|
||||
"Billboard Min Size in Pixels",
|
||||
"The min size (in pixels) for the billboard representing the astronomical "
|
||||
"object."
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -271,6 +307,36 @@ documentation::Documentation RenderableBillboardsCloud::Documentation() {
|
||||
new Vector2ListVerifier<float>,
|
||||
Optional::Yes,
|
||||
ColorRangeInfo.description
|
||||
},
|
||||
{
|
||||
TransformationMatrixInfo.identifier,
|
||||
new Matrix4x4Verifier<double>,
|
||||
Optional::Yes,
|
||||
TransformationMatrixInfo.description
|
||||
},
|
||||
{
|
||||
FadeInDistancesInfo.identifier,
|
||||
new Vector2Verifier<double>,
|
||||
Optional::Yes,
|
||||
FadeInDistancesInfo.description
|
||||
},
|
||||
{
|
||||
DisableFadeInInfo.identifier,
|
||||
new BoolVerifier,
|
||||
Optional::Yes,
|
||||
DisableFadeInInfo.description
|
||||
},
|
||||
{
|
||||
BillboardMaxSizeInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
BillboardMaxSizeInfo.description
|
||||
},
|
||||
{
|
||||
BillboardMinSizeInfo.identifier,
|
||||
new DoubleVerifier,
|
||||
Optional::Yes,
|
||||
BillboardMinSizeInfo.description
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -306,6 +372,10 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
|
||||
, _drawElements(DrawElementsInfo, true)
|
||||
, _drawLabels(DrawLabelInfo, false)
|
||||
, _colorOption(ColorOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
|
||||
, _fadeInDistance(FadeInDistancesInfo, glm::vec2(0.0f), glm::vec2(0.0), glm::vec2(100.0))
|
||||
, _disableFadeInDistance(DisableFadeInInfo, true)
|
||||
, _billboardMaxSize(BillboardMaxSizeInfo, 400.0, 0.0, 1000.0)
|
||||
, _billboardMinSize(BillboardMinSizeInfo, 0.0, 0.0, 100.0)
|
||||
, _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
|
||||
, _polygonTexture(nullptr)
|
||||
, _spriteTexture(nullptr)
|
||||
@@ -317,6 +387,7 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
|
||||
, _labelFile("")
|
||||
, _colorOptionString("")
|
||||
, _unit(Parsec)
|
||||
, _transformationMatrix(glm::dmat4(1.0))
|
||||
, _nValuesPerAstronomicalObject(0)
|
||||
, _vao(0)
|
||||
, _vbo(0)
|
||||
@@ -486,6 +557,36 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di
|
||||
_textMaxSize = static_cast<int>(dictionary.value<float>(LabelMaxSizeInfo.identifier));
|
||||
}
|
||||
addProperty(_textMaxSize);
|
||||
|
||||
if (dictionary.hasKey(TransformationMatrixInfo.identifier)) {
|
||||
_transformationMatrix = dictionary.value<glm::dmat4>(
|
||||
TransformationMatrixInfo.identifier
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(FadeInDistancesInfo.identifier)) {
|
||||
glm::vec2 fadeInValue = dictionary.value<glm::vec2>(
|
||||
FadeInDistancesInfo.identifier
|
||||
);
|
||||
_fadeInDistance.set(fadeInValue);
|
||||
_disableFadeInDistance.set(false);
|
||||
addProperty(_fadeInDistance);
|
||||
addProperty(_disableFadeInDistance);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(BillboardMaxSizeInfo.identifier)) {
|
||||
_billboardMaxSize = static_cast<float>(
|
||||
dictionary.value<double>(BillboardMaxSizeInfo.identifier)
|
||||
);
|
||||
addProperty(_billboardMaxSize);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(BillboardMinSizeInfo.identifier)) {
|
||||
_billboardMinSize = static_cast<float>(
|
||||
dictionary.value<double>(BillboardMinSizeInfo.identifier)
|
||||
);
|
||||
addProperty(_billboardMinSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,8 +655,13 @@ void RenderableBillboardsCloud::deinitializeGL() {
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& projectionMatrix, const glm::vec3& orthoRight, const glm::vec3& orthoUp) {
|
||||
void RenderableBillboardsCloud::renderBillboards(const RenderData& data,
|
||||
const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& worldToModelTransform,
|
||||
const glm::dvec3& orthoRight,
|
||||
const glm::dvec3& orthoUp,
|
||||
float fadeInVariable)
|
||||
{
|
||||
glDepthMask(false);
|
||||
|
||||
// Saving current OpenGL state
|
||||
@@ -583,18 +689,28 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_program->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
glm::dmat4 projMatrix = glm::dmat4(data.camera.projectionMatrix());
|
||||
_program->setUniform("screenSize", glm::vec2(OsEng.renderEngine().renderingResolution()));
|
||||
_program->setUniform("projection", projectionMatrix);
|
||||
_program->setUniform("projection", projMatrix);
|
||||
_program->setUniform("modelViewTransform", modelViewMatrix);
|
||||
_program->setUniform("modelViewProjectionTransform", glm::dmat4(projectionMatrix) * modelViewMatrix);
|
||||
_program->setUniform("modelViewProjectionTransform", projMatrix * modelViewMatrix);
|
||||
_program->setUniform("cameraPosition", glm::dvec3(worldToModelTransform *
|
||||
glm::dvec4(data.camera.positionVec3(), 1.0)));
|
||||
_program->setUniform("cameraLookUp", glm::dvec3(worldToModelTransform *
|
||||
glm::dvec4(data.camera.lookUpVectorWorldSpace(), 1.0)));
|
||||
|
||||
//_program->setUniform("cameraPosition", data.camera.positionVec3());
|
||||
//_program->setUniform("cameraLookUp", data.camera.lookUpVectorWorldSpace());
|
||||
|
||||
|
||||
_program->setUniform("cameraPosition", data.camera.positionVec3());
|
||||
_program->setUniform("cameraLookUp", data.camera.lookUpVectorWorldSpace());
|
||||
_program->setUniform("renderOption", _renderOption.value());
|
||||
glm::dvec4 centerScreenWorld = glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0);
|
||||
glm::dvec4 centerScreenWorld = glm::inverse(data.camera.combinedViewMatrix()) *
|
||||
glm::dvec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
_program->setUniform("centerScreenInWorldPosition", centerScreenWorld);
|
||||
|
||||
_program->setUniform("minBillboardSize", 1.f); // in pixels
|
||||
_program->setUniform("minBillboardSize", _billboardMinSize); // in pixels
|
||||
_program->setUniform("maxBillboardSize", _billboardMaxSize); // in pixels
|
||||
_program->setUniform("color", _pointColor);
|
||||
_program->setUniform("sides", 4);
|
||||
_program->setUniform("alphaValue", _alphaValue);
|
||||
@@ -603,6 +719,13 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g
|
||||
_program->setUniform("up", orthoUp);
|
||||
_program->setUniform("right", orthoRight);
|
||||
|
||||
_program->setUniform("fadeInValue", fadeInVariable);
|
||||
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
_program->setUniform("screenSize", glm::vec2(viewport[2], viewport[3]));
|
||||
|
||||
|
||||
ghoul::opengl::TextureUnit spriteTextureUnit;
|
||||
if (_hasSpriteTexture) {
|
||||
spriteTextureUnit.activate();
|
||||
@@ -647,8 +770,12 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, const g
|
||||
|
||||
}
|
||||
|
||||
void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::vec3& orthoRight, const glm::vec3& orthoUp) {
|
||||
void RenderableBillboardsCloud::renderLabels(const RenderData& data,
|
||||
const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::dvec3& orthoRight,
|
||||
const glm::dvec3& orthoUp,
|
||||
float fadeInVariable)
|
||||
{
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
|
||||
_fontRenderer->setFramebufferSize(renderEngine.renderingResolution());
|
||||
@@ -678,6 +805,8 @@ void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm::
|
||||
break;
|
||||
}
|
||||
|
||||
glm::vec4 textColor = _textColor;
|
||||
textColor.a *= fadeInVariable;
|
||||
for (const std::pair<glm::vec3, std::string>& pair : _labelData) {
|
||||
//glm::vec3 scaledPos(_transformationMatrix * glm::dvec4(pair.first, 1.0));
|
||||
glm::vec3 scaledPos(pair.first);
|
||||
@@ -685,7 +814,7 @@ void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm::
|
||||
_fontRenderer->render(
|
||||
*_font,
|
||||
scaledPos,
|
||||
_textColor,
|
||||
textColor,
|
||||
pow(10.0, _textSize.value()),
|
||||
_textMinSize,
|
||||
_textMaxSize,
|
||||
@@ -701,6 +830,58 @@ void RenderableBillboardsCloud::renderLabels(const RenderData& data, const glm::
|
||||
}
|
||||
|
||||
void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
float scale = 0.0;
|
||||
switch (_unit) {
|
||||
case Meter:
|
||||
scale = 1.0;
|
||||
break;
|
||||
case Kilometer:
|
||||
scale = 1e3;
|
||||
break;
|
||||
case Parsec:
|
||||
scale = PARSEC;
|
||||
break;
|
||||
case Kiloparsec:
|
||||
scale = 1e3 * PARSEC;
|
||||
break;
|
||||
case Megaparsec:
|
||||
scale = 1e6 * PARSEC;
|
||||
break;
|
||||
case Gigaparsec:
|
||||
scale = 1e9 * PARSEC;
|
||||
break;
|
||||
case GigalightYears:
|
||||
scale = 306391534.73091 * PARSEC;
|
||||
break;
|
||||
}
|
||||
|
||||
float fadeInVariable = 1.0f;
|
||||
if (!_disableFadeInDistance) {
|
||||
float distCamera = glm::length(data.camera.positionVec3());
|
||||
|
||||
/*
|
||||
// Linear Fading
|
||||
float funcValue = static_cast<float>((1.0 / double(_fadeInDistance*scale))*(distCamera));
|
||||
fadeInVariable *= funcValue > 1.0 ? 1.0 : funcValue;
|
||||
|
||||
if (funcValue < 0.01) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
glm::vec2 fadeRange = _fadeInDistance;
|
||||
float a = 1.0f / ((fadeRange.y - fadeRange.x) * scale);
|
||||
float b = -(fadeRange.x / (fadeRange.y - fadeRange.x));
|
||||
float funcValue = a * distCamera + b;
|
||||
fadeInVariable *= funcValue > 1.0 ? 1.0 : funcValue;
|
||||
|
||||
if (funcValue < 0.01) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
glm::dmat4 modelMatrix =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * // Translation
|
||||
glm::dmat4(data.modelTransform.rotation) * // Spice rotation
|
||||
@@ -709,24 +890,59 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) {
|
||||
glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix;
|
||||
glm::mat4 viewMatrix = data.camera.viewMatrix();
|
||||
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
|
||||
glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) * modelViewMatrix;
|
||||
|
||||
glm::vec3 lookup = data.camera.lookUpVectorWorldSpace();
|
||||
glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace();
|
||||
glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) *
|
||||
modelViewMatrix;
|
||||
|
||||
glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix);
|
||||
|
||||
/*glm::dmat4 internalCameraMatrix = data.camera.viewRotationMatrix() *
|
||||
glm::inverse(glm::translate(glm::dmat4(1.0), data.camera.positionVec3()));
|
||||
glm::dmat4 invInternalCameraMatrix = glm::inverse(internalCameraMatrix);
|
||||
glm::vec3 lookup = worldToModelTransform * invInternalCameraMatrix * glm::dvec4(data.camera.lookUpVectorWorldSpace(), 0.0);
|
||||
glm::vec3 viewDirection = worldToModelTransform * invInternalCameraMatrix * glm::dvec4(data.camera.viewDirectionWorldSpace(), 0.0);
|
||||
|
||||
|
||||
glm::vec3 right = glm::cross(viewDirection, lookup);
|
||||
glm::vec3 up = glm::cross(right, viewDirection);
|
||||
|
||||
glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix);
|
||||
glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)));
|
||||
glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0)));
|
||||
|
||||
glm::vec3 orthoRight = glm::normalize(right);
|
||||
glm::vec3 orthoUp = glm::normalize(up);*/
|
||||
|
||||
/*
|
||||
glm::dmat4 internalCameraMatrix = data.camera.viewRotationMatrix() *
|
||||
glm::inverse(glm::translate(glm::dmat4(1.0), data.camera.positionVec3()));
|
||||
glm::dmat4 invInternalCameraMatrix = glm::inverse(internalCameraMatrix);
|
||||
glm::dvec4 lookup = worldToModelTransform * glm::dvec4(data.camera.lookUpVectorWorldSpace(), 0.0);
|
||||
glm::dvec4 viewDirection = worldToModelTransform * glm::dvec4(data.camera.viewDirectionWorldSpace(), 0.0);
|
||||
glm::vec3 right = glm::cross(glm::vec3(viewDirection), glm::vec3(lookup));
|
||||
glm::vec3 up = glm::cross(right, glm::vec3(viewDirection));
|
||||
|
||||
glm::vec3 orthoRight = glm::normalize(right);
|
||||
glm::vec3 orthoUp = glm::normalize(up);
|
||||
*/
|
||||
|
||||
|
||||
// Almost Working
|
||||
glm::dmat4 invMVPParts = worldToModelTransform * glm::inverse(data.camera.combinedViewMatrix()) *
|
||||
glm::inverse(glm::dmat4(projectionMatrix));
|
||||
glm::dvec3 orthoRight = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(1.0, 0.0, 0.0, 0.0))));
|
||||
glm::dvec3 orthoUp = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0))));
|
||||
|
||||
if (_hasSpeckFile) {
|
||||
renderBillboards(data, modelViewMatrix, projectionMatrix, orthoRight, orthoUp);
|
||||
renderBillboards(
|
||||
data,
|
||||
modelViewMatrix,
|
||||
worldToModelTransform,
|
||||
orthoRight,
|
||||
orthoUp,
|
||||
fadeInVariable
|
||||
);
|
||||
}
|
||||
|
||||
if (_drawLabels && _hasLabel) {
|
||||
renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp);
|
||||
renderLabels(data, modelViewProjectionMatrix, orthoRight, orthoUp, fadeInVariable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1119,12 +1335,18 @@ bool RenderableBillboardsCloud::readLabelFile() {
|
||||
dummy.clear();
|
||||
|
||||
while (str >> dummy) {
|
||||
if (dummy == "#") {
|
||||
break;
|
||||
}
|
||||
|
||||
label += " " + dummy;
|
||||
dummy.clear();
|
||||
}
|
||||
|
||||
_labelData.push_back(std::make_pair(position, label));
|
||||
|
||||
glm::vec3 transformedPos = glm::vec3(
|
||||
_transformationMatrix * glm::dvec4(position, 1.0)
|
||||
);
|
||||
_labelData.push_back(std::make_pair(transformedPos, label));
|
||||
} while (!file.eof());
|
||||
|
||||
return true;
|
||||
@@ -1247,13 +1469,20 @@ void RenderableBillboardsCloud::createDataSlice() {
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < _fullData.size(); i += _nValuesPerAstronomicalObject) {
|
||||
glm::dvec4 transformedPos = glm::dvec4(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2], 1.0);
|
||||
float biggestCoord = -1.0f;
|
||||
for (size_t i = 0; i < _fullData.size(); i += _nValuesPerAstronomicalObject) {
|
||||
glm::dvec4 transformedPos = _transformationMatrix * glm::dvec4(
|
||||
_fullData[i + 0],
|
||||
_fullData[i + 1],
|
||||
_fullData[i + 2],
|
||||
1.0
|
||||
);
|
||||
glm::vec4 position(glm::vec3(transformedPos), static_cast<float>(_unit));
|
||||
|
||||
if (_hasColorMapFile) {
|
||||
for (auto j = 0; j < 4; ++j) {
|
||||
_slicedData.push_back(position[j]);
|
||||
biggestCoord = biggestCoord < position[j] ? position[j] : biggestCoord;
|
||||
}
|
||||
// Finds from which bin to get the color.
|
||||
// Note: the first color in the colormap file
|
||||
@@ -1279,6 +1508,7 @@ void RenderableBillboardsCloud::createDataSlice() {
|
||||
}
|
||||
}
|
||||
}
|
||||
_fadeInDistance.setMaxValue(glm::vec2(10.0f * biggestCoord));
|
||||
}
|
||||
|
||||
void RenderableBillboardsCloud::createPolygonTexture() {
|
||||
@@ -1363,7 +1593,8 @@ void RenderableBillboardsCloud::renderPolygonGeometry(GLuint vao) {
|
||||
ghoul::opengl::ProgramObject::Build("RenderableBillboardsCloud_Polygon",
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_vs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_fs.glsl"),
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_gs.glsl"));
|
||||
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboardpolygon_gs.glsl")
|
||||
);
|
||||
|
||||
program->activate();
|
||||
static const float black[] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
|
||||
@@ -91,10 +91,10 @@ private:
|
||||
void loadPolygonGeometryForRendering();
|
||||
void renderPolygonGeometry(GLuint vao);
|
||||
void renderBillboards(const RenderData& data, const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& worldToModelTransform, const glm::dvec3& orthoRight, const glm::dvec3& orthoUp,
|
||||
const float fadeInVariable);
|
||||
const glm::dmat4& worldToModelTransform, const glm::dvec3& orthoRight,
|
||||
const glm::dvec3& orthoUp, float fadeInVariable);
|
||||
void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVariable);
|
||||
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable);
|
||||
|
||||
bool loadData();
|
||||
bool readSpeckFile();
|
||||
|
||||
@@ -127,7 +127,8 @@ namespace {
|
||||
"Determines whether labels should be drawn or hidden."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo TransformationMatrixInfo = {
|
||||
static const openspace::properties::Property::PropertyInfo TransformationMatrixInfo =
|
||||
{
|
||||
"TransformationMatrix",
|
||||
"Transformation Matrix",
|
||||
"Transformation matrix to be applied to each astronomical object."
|
||||
@@ -163,8 +164,8 @@ documentation::Documentation RenderableDUMeshes::Documentation() {
|
||||
KeyFile,
|
||||
new StringVerifier,
|
||||
Optional::No,
|
||||
"The path to the SPECK file that contains information about the astronomical "
|
||||
"object being rendered."
|
||||
"The path to the SPECK file that contains information about the "
|
||||
"astronomical object being rendered."
|
||||
},
|
||||
{
|
||||
keyColor,
|
||||
@@ -248,7 +249,6 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary)
|
||||
, _textMaxSize(200)
|
||||
, _alphaValue(TransparencyInfo, 1.f, 0.f, 1.f)
|
||||
, _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 64.f)
|
||||
//, _pointColor(ColorInfo, glm::vec3(1.f, 0.4f, 0.2f), glm::vec3(0.f, 0.f, 0.f), glm::vec3(1.0f, 1.0f, 1.0f))
|
||||
, _textColor(
|
||||
TextColorInfo,
|
||||
glm::vec4(1.0f, 1.0, 1.0f, 1.f),
|
||||
@@ -361,22 +361,28 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_textSize);
|
||||
|
||||
if (dictionary.hasKey(LabelMinSizeInfo.identifier)) {
|
||||
_textMinSize = static_cast<int>(dictionary.value<float>(LabelMinSizeInfo.identifier));
|
||||
_textMinSize = static_cast<int>(
|
||||
dictionary.value<float>(LabelMinSizeInfo.identifier)
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(LabelMaxSizeInfo.identifier)) {
|
||||
_textMaxSize = static_cast<int>(dictionary.value<float>(LabelMaxSizeInfo.identifier));
|
||||
_textMaxSize = static_cast<int>(
|
||||
dictionary.value<float>(LabelMaxSizeInfo.identifier)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(TransformationMatrixInfo.identifier)) {
|
||||
_transformationMatrix = dictionary.value<glm::dmat4>(TransformationMatrixInfo.identifier);
|
||||
_transformationMatrix = dictionary.value<glm::dmat4>(
|
||||
TransformationMatrixInfo.identifier
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(MeshColorInfo.identifier)) {
|
||||
ghoul::Dictionary colorDic = dictionary.value<ghoul::Dictionary>(
|
||||
MeshColorInfo.identifier
|
||||
);
|
||||
);
|
||||
for (int i = 0; i < static_cast<int>(colorDic.size()); ++i) {
|
||||
_meshColorMap.insert({ i + 1,
|
||||
colorDic.value<glm::vec3>(std::to_string(i + 1)) });
|
||||
@@ -386,7 +392,8 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
bool RenderableDUMeshes::isReady() const {
|
||||
return (_program != nullptr) && (!_renderingMeshesMap.empty() || (!_labelData.empty()));
|
||||
return (_program != nullptr) &&
|
||||
(!_renderingMeshesMap.empty() || (!_labelData.empty()));
|
||||
}
|
||||
|
||||
void RenderableDUMeshes::initializeGL() {
|
||||
@@ -410,8 +417,12 @@ void RenderableDUMeshes::initializeGL() {
|
||||
ghoul::fontrendering::FontRenderer::createProjectionSubjectText());
|
||||
if (_font == nullptr) {
|
||||
size_t _fontSize = 30;
|
||||
_font = OsEng.fontManager().font("Mono", static_cast<float>(_fontSize),
|
||||
ghoul::fontrendering::FontManager::Outline::Yes, ghoul::fontrendering::FontManager::LoadGlyphs::No);
|
||||
_font = OsEng.fontManager().font(
|
||||
"Mono",
|
||||
static_cast<float>(_fontSize),
|
||||
ghoul::fontrendering::FontManager::Outline::Yes,
|
||||
ghoul::fontrendering::FontManager::LoadGlyphs::No
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -508,8 +519,11 @@ void RenderableDUMeshes::renderMeshes(const RenderData&,
|
||||
}
|
||||
}
|
||||
|
||||
void RenderableDUMeshes::renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::vec3& orthoRight, const glm::vec3& orthoUp) {
|
||||
void RenderableDUMeshes::renderLabels(const RenderData& data,
|
||||
const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::vec3& orthoRight,
|
||||
const glm::vec3& orthoUp)
|
||||
{
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
|
||||
_fontRenderer->setFramebufferSize(renderEngine.renderingResolution());
|
||||
@@ -577,8 +591,12 @@ void RenderableDUMeshes::render(const RenderData& data, RendererTasks&) {
|
||||
glm::vec3 up = glm::cross(right, viewDirection);
|
||||
|
||||
glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix);
|
||||
glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)));
|
||||
glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0)));
|
||||
glm::vec3 orthoRight = glm::normalize(
|
||||
glm::vec3(worldToModelTransform * glm::vec4(right, 0.0))
|
||||
);
|
||||
glm::vec3 orthoUp = glm::normalize(
|
||||
glm::vec3(worldToModelTransform * glm::vec4(up, 0.0))
|
||||
);
|
||||
|
||||
if (_hasSpeckFile) {
|
||||
renderMeshes(data, modelViewMatrix, projectionMatrix);
|
||||
@@ -864,7 +882,9 @@ bool RenderableDUMeshes::readLabelFile() {
|
||||
dummy.clear();
|
||||
}
|
||||
|
||||
glm::vec3 transformedPos = glm::vec3(_transformationMatrix * glm::dvec4(position, 1.0));
|
||||
glm::vec3 transformedPos = glm::vec3(
|
||||
_transformationMatrix * glm::dvec4(position, 1.0)
|
||||
);
|
||||
_labelData.push_back(std::make_pair(transformedPos, label));
|
||||
|
||||
} while (!file.eof());
|
||||
@@ -886,7 +906,10 @@ bool RenderableDUMeshes::loadCachedFile(const std::string& file) {
|
||||
|
||||
int32_t nValues = 0;
|
||||
fileStream.read(reinterpret_cast<char*>(&nValues), sizeof(int32_t));
|
||||
fileStream.read(reinterpret_cast<char*>(&_nValuesPerAstronomicalObject), sizeof(int32_t));
|
||||
fileStream.read(
|
||||
reinterpret_cast<char*>(&_nValuesPerAstronomicalObject),
|
||||
sizeof(int32_t)
|
||||
);
|
||||
|
||||
_fullData.resize(nValues);
|
||||
fileStream.read(reinterpret_cast<char*>(&_fullData[0]),
|
||||
@@ -914,8 +937,13 @@ bool RenderableDUMeshes::saveCachedFile(const std::string& file) const {
|
||||
}
|
||||
fileStream.write(reinterpret_cast<const char*>(&nValues), sizeof(int32_t));
|
||||
|
||||
int32_t nValuesPerAstronomicalObject = static_cast<int32_t>(_nValuesPerAstronomicalObject);
|
||||
fileStream.write(reinterpret_cast<const char*>(&nValuesPerAstronomicalObject), sizeof(int32_t));
|
||||
int32_t nValuesPerAstronomicalObject = static_cast<int32_t>(
|
||||
_nValuesPerAstronomicalObject
|
||||
);
|
||||
fileStream.write(
|
||||
reinterpret_cast<const char*>(&nValuesPerAstronomicalObject),
|
||||
sizeof(int32_t)
|
||||
);
|
||||
|
||||
size_t nBytes = nValues * sizeof(_fullData[0]);
|
||||
fileStream.write(reinterpret_cast<const char*>(&_fullData[0]), nBytes);
|
||||
@@ -933,34 +961,34 @@ void RenderableDUMeshes::createMeshes() {
|
||||
if (_dataIsDirty && _hasSpeckFile) {
|
||||
LDEBUG("Creating planes");
|
||||
|
||||
|
||||
std::unordered_map<int, RenderingMesh>::iterator it = _renderingMeshesMap.begin();
|
||||
std::unordered_map<int, RenderingMesh>::iterator itEnd = _renderingMeshesMap.end();
|
||||
std::unordered_map<int, RenderingMesh>::iterator itEnd =
|
||||
_renderingMeshesMap.end();
|
||||
|
||||
for (; it != itEnd; ++it) {
|
||||
float scale = 0.0;
|
||||
switch (_unit) {
|
||||
case Meter:
|
||||
scale = 1.0;
|
||||
break;
|
||||
case Kilometer:
|
||||
scale = 1e3;
|
||||
break;
|
||||
case Parsec:
|
||||
scale = PARSEC;
|
||||
break;
|
||||
case Kiloparsec:
|
||||
scale = 1e3 * PARSEC;
|
||||
break;
|
||||
case Megaparsec:
|
||||
scale = 1e6 * PARSEC;
|
||||
break;
|
||||
case Gigaparsec:
|
||||
scale = 1e9 * PARSEC;
|
||||
break;
|
||||
case GigalightYears:
|
||||
scale = 306391534.73091 * PARSEC;
|
||||
break;
|
||||
case Meter:
|
||||
scale = 1.0;
|
||||
break;
|
||||
case Kilometer:
|
||||
scale = 1e3;
|
||||
break;
|
||||
case Parsec:
|
||||
scale = PARSEC;
|
||||
break;
|
||||
case Kiloparsec:
|
||||
scale = 1e3 * PARSEC;
|
||||
break;
|
||||
case Megaparsec:
|
||||
scale = 1e6 * PARSEC;
|
||||
break;
|
||||
case Gigaparsec:
|
||||
scale = 1e9 * PARSEC;
|
||||
break;
|
||||
case GigalightYears:
|
||||
scale = 306391534.73091 * PARSEC;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int v = 0; v < static_cast<int>(it->second.vertices.size()); ++v) {
|
||||
@@ -977,12 +1005,17 @@ void RenderableDUMeshes::createMeshes() {
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||
//glBufferData(GL_ARRAY_BUFFER, it->second.numV * sizeof(GLfloat),
|
||||
glBufferData(GL_ARRAY_BUFFER, it->second.vertices.size() * sizeof(GLfloat),
|
||||
&it->second.vertices[0], GL_STATIC_DRAW);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
it->second.vertices.size() * sizeof(GLfloat),
|
||||
&it->second.vertices[0],
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
// in_position
|
||||
glEnableVertexAttribArray(0);
|
||||
// U and V may not be given by the user
|
||||
if (it->second.vertices.size() / (it->second.numU * it->second.numV) > 3) {
|
||||
if (it->second.vertices.size() / (it->second.numU * it->second.numV) > 3)
|
||||
{
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
3,
|
||||
@@ -1000,7 +1033,9 @@ void RenderableDUMeshes::createMeshes() {
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
sizeof(GLfloat) * 7,
|
||||
reinterpret_cast<GLvoid*>(sizeof(GLfloat) * 3 * i * it->second.numV)
|
||||
reinterpret_cast<GLvoid*>(
|
||||
sizeof(GLfloat) * 3 * i * it->second.numV
|
||||
)
|
||||
);
|
||||
}
|
||||
else { // no U and V:
|
||||
@@ -1010,7 +1045,9 @@ void RenderableDUMeshes::createMeshes() {
|
||||
GL_FLOAT,
|
||||
GL_FALSE,
|
||||
0,
|
||||
reinterpret_cast<GLvoid*>(sizeof(GLfloat) * 3 * i * it->second.numV)
|
||||
reinterpret_cast<GLvoid*>(
|
||||
sizeof(GLfloat) * 3 * i * it->second.numV
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1026,12 +1063,18 @@ void RenderableDUMeshes::createMeshes() {
|
||||
|
||||
glBindVertexArray(cvao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, cvbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, it->second.vertices.size() * sizeof(GLfloat),
|
||||
&it->second.vertices[0], GL_STATIC_DRAW);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
it->second.vertices.size() * sizeof(GLfloat),
|
||||
&it->second.vertices[0],
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
// in_position
|
||||
glEnableVertexAttribArray(0);
|
||||
// U and V may not be given by the user
|
||||
if (it->second.vertices.size() / (it->second.numU * it->second.numV) > 3) {
|
||||
if (it->second.vertices.size() /
|
||||
(it->second.numU * it->second.numV) > 3)
|
||||
{
|
||||
glVertexAttribPointer(
|
||||
0,
|
||||
3,
|
||||
@@ -1073,7 +1116,7 @@ void RenderableDUMeshes::createMeshes() {
|
||||
|
||||
if (_hasLabel && _labelDataIsDirty) {
|
||||
_labelDataIsDirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <ghoul/glm.h>
|
||||
|
||||
#include <array>
|
||||
#include <fstream>
|
||||
@@ -121,7 +121,8 @@ namespace {
|
||||
"Enables/Disables the drawing of the astronomical objects."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo TransformationMatrixInfo = {
|
||||
static const openspace::properties::Property::PropertyInfo TransformationMatrixInfo =
|
||||
{
|
||||
"TransformationMatrix",
|
||||
"Transformation Matrix",
|
||||
"Transformation matrix to be applied to each astronomical object."
|
||||
@@ -197,8 +198,8 @@ documentation::Documentation RenderablePlanesCloud::Documentation() {
|
||||
KeyFile,
|
||||
new StringVerifier,
|
||||
Optional::Yes,
|
||||
"The path to the SPECK file that contains information about the astronomical "
|
||||
"object being rendered."
|
||||
"The path to the SPECK file that contains information about the "
|
||||
"astronomical object being rendered."
|
||||
},
|
||||
{
|
||||
TransparencyInfo.identifier,
|
||||
@@ -317,7 +318,12 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary
|
||||
, _textSize(TextSizeInfo, 8.0, 0.5, 24.0)
|
||||
, _drawElements(DrawElementsInfo, true)
|
||||
, _blendMode(BlendModeInfo, properties::OptionProperty::DisplayType::Dropdown)
|
||||
, _fadeInDistance(FadeInDistancesInfo, glm::vec2(0.0), glm::vec2(0.0), glm::vec2(200000.0))
|
||||
, _fadeInDistance(
|
||||
FadeInDistancesInfo,
|
||||
glm::vec2(0.f),
|
||||
glm::vec2(0.f),
|
||||
glm::vec2(200000.f)
|
||||
)
|
||||
, _disableFadeInDistance(DisableFadeInInfo, true)
|
||||
, _planeMinSize(PlaneMinSizeInfo, 0.5, 0.0, 500.0)
|
||||
, _renderOption(RenderOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
|
||||
@@ -425,16 +431,22 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary
|
||||
addProperty(_textSize);
|
||||
|
||||
if (dictionary.hasKey(LabelMinSizeInfo.identifier)) {
|
||||
_textMinSize = static_cast<int>(dictionary.value<float>(LabelMinSizeInfo.identifier));
|
||||
_textMinSize = static_cast<int>(
|
||||
dictionary.value<float>(LabelMinSizeInfo.identifier)
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(LabelMaxSizeInfo.identifier)) {
|
||||
_textMaxSize = static_cast<int>(dictionary.value<float>(LabelMaxSizeInfo.identifier));
|
||||
_textMaxSize = static_cast<int>(
|
||||
dictionary.value<float>(LabelMaxSizeInfo.identifier)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(TransformationMatrixInfo.identifier)) {
|
||||
_transformationMatrix = dictionary.value<glm::dmat4>(TransformationMatrixInfo.identifier);
|
||||
_transformationMatrix = dictionary.value<glm::dmat4>(
|
||||
TransformationMatrixInfo.identifier
|
||||
);
|
||||
}
|
||||
|
||||
_blendMode.addOptions({
|
||||
@@ -471,11 +483,15 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(ScaleLuminosityInfo.identifier)) {
|
||||
_sluminosity = static_cast<float>(dictionary.value<double>(ScaleLuminosityInfo.identifier));
|
||||
_sluminosity = static_cast<float>(
|
||||
dictionary.value<double>(ScaleLuminosityInfo.identifier)
|
||||
);
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(FadeInDistancesInfo.identifier)) {
|
||||
glm::vec2 fadeInValue = dictionary.value<glm::vec2>(FadeInDistancesInfo.identifier);
|
||||
glm::vec2 fadeInValue = dictionary.value<glm::vec2>(
|
||||
FadeInDistancesInfo.identifier
|
||||
);
|
||||
_fadeInDistance.set(fadeInValue);
|
||||
_disableFadeInDistance.set(false);
|
||||
addProperty(_fadeInDistance);
|
||||
@@ -483,7 +499,9 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary
|
||||
}
|
||||
|
||||
if (dictionary.hasKey(PlaneMinSizeInfo.identifier)) {
|
||||
_planeMinSize = static_cast<float>(dictionary.value<double>(PlaneMinSizeInfo.identifier));
|
||||
_planeMinSize = static_cast<float>(
|
||||
dictionary.value<double>(PlaneMinSizeInfo.identifier)
|
||||
);
|
||||
addProperty(_planeMinSize);
|
||||
}
|
||||
}
|
||||
@@ -518,8 +536,12 @@ void RenderablePlanesCloud::initializeGL() {
|
||||
ghoul::fontrendering::FontRenderer::createProjectionSubjectText());
|
||||
if (_font == nullptr) {
|
||||
size_t _fontSize = 30;
|
||||
_font = OsEng.fontManager().font("Mono", static_cast<float>(_fontSize),
|
||||
ghoul::fontrendering::FontManager::Outline::Yes, ghoul::fontrendering::FontManager::LoadGlyphs::No);
|
||||
_font = OsEng.fontManager().font(
|
||||
"Mono",
|
||||
static_cast<float>(_fontSize),
|
||||
ghoul::fontrendering::FontManager::Outline::Yes,
|
||||
ghoul::fontrendering::FontManager::LoadGlyphs::No
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -578,24 +600,7 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&,
|
||||
_program->setUniform("alphaValue", _alphaValue);
|
||||
_program->setUniform("scaleFactor", _scaleFactor);
|
||||
_program->setUniform("fadeInValue", fadeInVariable);
|
||||
//_program->setUniform("minPlaneSize", 1.f); // in pixels
|
||||
|
||||
//bool usingFramebufferRenderer =
|
||||
// OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::Framebuffer;
|
||||
|
||||
//bool usingABufferRenderer =
|
||||
// OsEng.renderEngine().rendererImplementation() == RenderEngine::RendererImplementation::ABuffer;
|
||||
|
||||
//if (usingABufferRenderer) {
|
||||
// _program->setUniform("additiveBlending", _blendMode == BlendModeAdditive);
|
||||
//}
|
||||
|
||||
//bool additiveBlending = _blendMode == BlendModeAdditive && usingFramebufferRenderer;
|
||||
//if (additiveBlending) {
|
||||
// //glDepthMask(false);
|
||||
// glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
//}
|
||||
|
||||
GLint viewport[4];
|
||||
glGetIntegerv(GL_VIEWPORT, viewport);
|
||||
|
||||
@@ -619,14 +624,17 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&,
|
||||
|
||||
// Testing size:
|
||||
glm::vec4 topRight = vertex1 / vertex1.w;
|
||||
topRight = ((topRight + glm::vec4(1.0)) / glm::vec4(2.0)) * glm::vec4(viewport[2], viewport[3], 1.0, 1.0);
|
||||
topRight = ((topRight + glm::vec4(1.0)) / glm::vec4(2.0)) *
|
||||
glm::vec4(viewport[2], viewport[3], 1.0, 1.0);
|
||||
glm::vec4 bottomLeft = vertex0 / vertex0.w;
|
||||
bottomLeft = ((bottomLeft + glm::vec4(1.0)) / glm::vec4(2.0)) * glm::vec4(viewport[2], viewport[3], 1.0, 1.0);
|
||||
bottomLeft = ((bottomLeft + glm::vec4(1.0)) / glm::vec4(2.0)) *
|
||||
glm::vec4(viewport[2], viewport[3], 1.0, 1.0);
|
||||
|
||||
float lengthY = std::fabs(topRight.y - bottomLeft.y);
|
||||
float lengthX = std::fabs(topRight.x - bottomLeft.x);
|
||||
float lengthXY = glm::length(glm::vec2(topRight) - glm::vec2(bottomLeft));
|
||||
float biggestAxis = lengthY > lengthX ? (lengthY > lengthXY ? lengthY : lengthXY) :
|
||||
float biggestAxis =
|
||||
lengthY > lengthX ? (lengthY > lengthXY ? lengthY : lengthXY) :
|
||||
(lengthX > lengthXY ? lengthX : lengthXY);
|
||||
if (biggestAxis < _planeMinSize ) {
|
||||
continue;
|
||||
@@ -662,35 +670,38 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&,
|
||||
}
|
||||
}
|
||||
|
||||
void RenderablePlanesCloud::renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVariable) {
|
||||
void RenderablePlanesCloud::renderLabels(const RenderData& data,
|
||||
const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::dvec3& orthoRight,
|
||||
const glm::dvec3& orthoUp, float fadeInVariable)
|
||||
{
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
|
||||
_fontRenderer->setFramebufferSize(renderEngine.renderingResolution());
|
||||
|
||||
float scale = 0.0;
|
||||
switch (_unit) {
|
||||
case Meter:
|
||||
scale = 1.0;
|
||||
break;
|
||||
case Kilometer:
|
||||
scale = 1e3;
|
||||
break;
|
||||
case Parsec:
|
||||
scale = PARSEC;
|
||||
break;
|
||||
case Kiloparsec:
|
||||
scale = 1e3 * PARSEC;
|
||||
break;
|
||||
case Megaparsec:
|
||||
scale = 1e6 * PARSEC;
|
||||
break;
|
||||
case Gigaparsec:
|
||||
scale = 1e9 * PARSEC;
|
||||
break;
|
||||
case GigalightYears:
|
||||
scale = 306391534.73091 * PARSEC;
|
||||
break;
|
||||
case Meter:
|
||||
scale = 1.0;
|
||||
break;
|
||||
case Kilometer:
|
||||
scale = 1e3;
|
||||
break;
|
||||
case Parsec:
|
||||
scale = PARSEC;
|
||||
break;
|
||||
case Kiloparsec:
|
||||
scale = 1e3 * PARSEC;
|
||||
break;
|
||||
case Megaparsec:
|
||||
scale = 1e6 * PARSEC;
|
||||
break;
|
||||
case Gigaparsec:
|
||||
scale = 1e9 * PARSEC;
|
||||
break;
|
||||
case GigalightYears:
|
||||
scale = 306391534.73091 * PARSEC;
|
||||
break;
|
||||
}
|
||||
|
||||
glm::vec4 textColor = _textColor;
|
||||
@@ -722,33 +733,35 @@ void RenderablePlanesCloud::renderLabels(const RenderData& data, const glm::dmat
|
||||
void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) {
|
||||
double scale = 0.0;
|
||||
switch (_unit) {
|
||||
case Meter:
|
||||
scale = 1.0;
|
||||
break;
|
||||
case Kilometer:
|
||||
scale = 1e3;
|
||||
break;
|
||||
case Parsec:
|
||||
scale = PARSEC;
|
||||
break;
|
||||
case Kiloparsec:
|
||||
scale = 1e3 * PARSEC;
|
||||
break;
|
||||
case Megaparsec:
|
||||
scale = 1e6 * PARSEC;
|
||||
break;
|
||||
case Gigaparsec:
|
||||
scale = 1e9 * PARSEC;
|
||||
break;
|
||||
case GigalightYears:
|
||||
scale = 306391534.73091 * PARSEC;
|
||||
break;
|
||||
case Meter:
|
||||
scale = 1.0;
|
||||
break;
|
||||
case Kilometer:
|
||||
scale = 1e3;
|
||||
break;
|
||||
case Parsec:
|
||||
scale = PARSEC;
|
||||
break;
|
||||
case Kiloparsec:
|
||||
scale = 1e3 * PARSEC;
|
||||
break;
|
||||
case Megaparsec:
|
||||
scale = 1e6 * PARSEC;
|
||||
break;
|
||||
case Gigaparsec:
|
||||
scale = 1e9 * PARSEC;
|
||||
break;
|
||||
case GigalightYears:
|
||||
scale = 306391534.73091 * PARSEC;
|
||||
break;
|
||||
}
|
||||
|
||||
float fadeInVariable = 1.0f;
|
||||
if (!_disableFadeInDistance) {
|
||||
double distCamera = glm::length(data.camera.positionVec3());
|
||||
//float funcValue = static_cast<float>((1.0 / double(_fadeInDistance))*(distCamera / scale));
|
||||
//float funcValue = static_cast<float>(
|
||||
//(1.0 / double(_fadeInDistance))*(distCamera / scale)
|
||||
//);
|
||||
//
|
||||
//// Let's not waste performance
|
||||
//if (funcValue < 0.01) {
|
||||
@@ -777,20 +790,29 @@ void RenderablePlanesCloud::render(const RenderData& data, RendererTasks&) {
|
||||
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
|
||||
glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) * modelViewMatrix;
|
||||
|
||||
/*glm::vec3 lookup = data.camera.lookUpVectorWorldSpace();
|
||||
glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace();
|
||||
glm::vec3 right = glm::cross(viewDirection, lookup);
|
||||
glm::vec3 up = glm::cross(right, viewDirection);
|
||||
//glm::vec3 lookup = data.camera.lookUpVectorWorldSpace();
|
||||
//glm::vec3 viewDirection = data.camera.viewDirectionWorldSpace();
|
||||
//glm::vec3 right = glm::cross(viewDirection, lookup);
|
||||
//glm::vec3 up = glm::cross(right, viewDirection);
|
||||
|
||||
glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix);
|
||||
glm::vec3 orthoRight = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(right, 0.0)));
|
||||
glm::vec3 orthoUp = glm::normalize(glm::vec3(worldToModelTransform * glm::vec4(up, 0.0)));*/
|
||||
//glm::dmat4 worldToModelTransform = glm::inverse(modelMatrix);
|
||||
//glm::vec3 orthoRight = glm::normalize(
|
||||
// glm::vec3(worldToModelTransform * glm::vec4(right, 0.0))
|
||||
//);
|
||||
//glm::vec3 orthoUp = glm::normalize(
|
||||
// glm::vec3(worldToModelTransform * glm::vec4(up, 0.0))
|
||||
//);
|
||||
|
||||
//glm::dmat4 invMVP = glm::inverse(modelViewProjectionMatrix);
|
||||
glm::dmat4 invMVPParts = glm::inverse(modelMatrix) * glm::inverse(data.camera.combinedViewMatrix()) *
|
||||
glm::inverse(glm::dmat4(projectionMatrix));
|
||||
glm::dvec3 orthoRight = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(1.0, 0.0, 0.0, 0.0))));
|
||||
glm::dvec3 orthoUp = glm::dvec3(glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0))));
|
||||
glm::dmat4 invMVPParts = glm::inverse(modelMatrix) *
|
||||
glm::inverse(data.camera.combinedViewMatrix()) *
|
||||
glm::inverse(glm::dmat4(projectionMatrix));
|
||||
glm::dvec3 orthoRight = glm::dvec3(
|
||||
glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(1.0, 0.0, 0.0, 0.0)))
|
||||
);
|
||||
glm::dvec3 orthoUp = glm::dvec3(
|
||||
glm::normalize(glm::dvec3(invMVPParts * glm::dvec4(0.0, 1.0, 0.0, 0.0)))
|
||||
);
|
||||
|
||||
if (_hasSpeckFile) {
|
||||
renderPlanes(data, modelViewMatrix, projectionMatrix, fadeInVariable);
|
||||
@@ -959,10 +981,12 @@ bool RenderablePlanesCloud::readSpeckFile() {
|
||||
_variableDataPositionMap.insert({ dummy, _nValuesPerAstronomicalObject + 3});
|
||||
|
||||
if ((dummy == "orientation") || (dummy == "ori")) { // 3d vectors u and v
|
||||
_nValuesPerAstronomicalObject += 6; // We want the number, but the index is 0 based
|
||||
// We want the number, but the index is 0 based
|
||||
_nValuesPerAstronomicalObject += 6;
|
||||
}
|
||||
else {
|
||||
_nValuesPerAstronomicalObject += 1; // We want the number, but the index is 0 based
|
||||
// We want the number, but the index is 0 based
|
||||
_nValuesPerAstronomicalObject += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1035,7 +1059,7 @@ bool RenderablePlanesCloud::readSpeckFile() {
|
||||
for (int i = 0; i < _nValuesPerAstronomicalObject; ++i) {
|
||||
str >> values[i];
|
||||
if ((i >= _planeStartingIndexPos) &&
|
||||
(i <= _planeStartingIndexPos+6)) { // vectors u and v
|
||||
(i <= _planeStartingIndexPos + 6)) { // vectors u and v
|
||||
int index = i - _planeStartingIndexPos;
|
||||
switch (index) {
|
||||
case 0:
|
||||
@@ -1149,7 +1173,9 @@ bool RenderablePlanesCloud::readLabelFile() {
|
||||
dummy.clear();
|
||||
}
|
||||
|
||||
glm::vec3 transformedPos = glm::vec3(_transformationMatrix * glm::dvec4(position, 1.0));
|
||||
glm::vec3 transformedPos = glm::vec3(
|
||||
_transformationMatrix * glm::dvec4(position, 1.0)
|
||||
);
|
||||
_labelData.push_back(std::make_pair(transformedPos, label));
|
||||
|
||||
} while (!file.eof());
|
||||
@@ -1171,7 +1197,10 @@ bool RenderablePlanesCloud::loadCachedFile(const std::string& file) {
|
||||
|
||||
int32_t nValues = 0;
|
||||
fileStream.read(reinterpret_cast<char*>(&nValues), sizeof(int32_t));
|
||||
fileStream.read(reinterpret_cast<char*>(&_nValuesPerAstronomicalObject), sizeof(int32_t));
|
||||
fileStream.read(reinterpret_cast<char*>(
|
||||
&_nValuesPerAstronomicalObject),
|
||||
sizeof(int32_t)
|
||||
);
|
||||
|
||||
_fullData.resize(nValues);
|
||||
fileStream.read(reinterpret_cast<char*>(&_fullData[0]),
|
||||
@@ -1199,8 +1228,13 @@ bool RenderablePlanesCloud::saveCachedFile(const std::string& file) const {
|
||||
}
|
||||
fileStream.write(reinterpret_cast<const char*>(&nValues), sizeof(int32_t));
|
||||
|
||||
int32_t nValuesPerAstronomicalObject = static_cast<int32_t>(_nValuesPerAstronomicalObject);
|
||||
fileStream.write(reinterpret_cast<const char*>(&nValuesPerAstronomicalObject), sizeof(int32_t));
|
||||
int32_t nValuesPerAstronomicalObject = static_cast<int32_t>(
|
||||
_nValuesPerAstronomicalObject
|
||||
);
|
||||
fileStream.write(reinterpret_cast<const char*>(
|
||||
&nValuesPerAstronomicalObject),
|
||||
sizeof(int32_t)
|
||||
);
|
||||
|
||||
size_t nBytes = nValues * sizeof(_fullData[0]);
|
||||
fileStream.write(reinterpret_cast<const char*>(&_fullData[0]), nBytes);
|
||||
@@ -1242,7 +1276,8 @@ void RenderablePlanesCloud::createPlanes() {
|
||||
v.w = 0.0;
|
||||
|
||||
if (!_luminosityVar.empty()) {
|
||||
float lumS = _fullData[p + _variableDataPositionMap[_luminosityVar]] * _sluminosity;
|
||||
float lumS = _fullData[p + _variableDataPositionMap[_luminosityVar]] *
|
||||
_sluminosity;
|
||||
u *= lumS;
|
||||
v *= lumS;
|
||||
}
|
||||
@@ -1255,7 +1290,6 @@ void RenderablePlanesCloud::createPlanes() {
|
||||
|
||||
// JCC: Ask Abbott about these points refeering to a non-existing texture.
|
||||
if (plane.planeIndex == 30) {
|
||||
//std::cout << "--- Creating planes - index: " << plane.planeIndex << std::endl;
|
||||
plane.planeIndex = -1;
|
||||
}
|
||||
|
||||
@@ -1318,7 +1352,12 @@ void RenderablePlanesCloud::createPlanes() {
|
||||
|
||||
glBindVertexArray(plane.vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, plane.vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(plane.vertexData), plane.vertexData, GL_STATIC_DRAW);
|
||||
glBufferData(
|
||||
GL_ARRAY_BUFFER,
|
||||
sizeof(plane.vertexData),
|
||||
plane.vertexData,
|
||||
GL_STATIC_DRAW
|
||||
);
|
||||
// in_position
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(
|
||||
|
||||
@@ -94,9 +94,9 @@ namespace openspace {
|
||||
void deleteDataGPU();
|
||||
void createPlanes();
|
||||
void renderPlanes(const RenderData& data, const glm::dmat4& modelViewMatrix,
|
||||
const glm::dmat4& projectionMatrix, const float fadeInVariable);
|
||||
const glm::dmat4& projectionMatrix, float fadeInVariable);
|
||||
void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
|
||||
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, const float fadeInVarible);
|
||||
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVarible);
|
||||
|
||||
bool loadData();
|
||||
bool loadTextures();
|
||||
|
||||
@@ -167,7 +167,8 @@ glm::dvec3 Ellipsoid::cartesianPosition(const Geodetic3& geodetic3) const {
|
||||
}
|
||||
|
||||
void Ellipsoid::setShadowConfigurationArray(
|
||||
const std::vector<Ellipsoid::ShadowConfiguration>& shadowConfArray) {
|
||||
const std::vector<Ellipsoid::ShadowConfiguration>& shadowConfArray)
|
||||
{
|
||||
_shadowConfArray = shadowConfArray;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,9 @@ public:
|
||||
glm::dvec3 cartesianSurfacePosition(const Geodetic2& geodetic2) const;
|
||||
glm::dvec3 cartesianPosition(const Geodetic3& geodetic3) const;
|
||||
|
||||
void setShadowConfigurationArray(const std::vector<Ellipsoid::ShadowConfiguration>& shadowConfArray);
|
||||
void setShadowConfigurationArray(
|
||||
const std::vector<Ellipsoid::ShadowConfiguration>& shadowConfArray
|
||||
);
|
||||
std::vector<Ellipsoid::ShadowConfiguration> shadowConfigurationArray() const;
|
||||
bool hasEclipseShadows() const;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*****************************************************************************************
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
properties::BoolProperty eclipseShadowsEnabled;
|
||||
properties::BoolProperty eclipseHardShadows;
|
||||
properties::FloatProperty lodScaleFactor;
|
||||
properties::FloatProperty cameraMinHeight;
|
||||
properties::FloatProperty cameraMinHeight;
|
||||
properties::FloatProperty orenNayarRoughness;
|
||||
};
|
||||
|
||||
@@ -149,7 +149,6 @@ private:
|
||||
DebugProperties _debugProperties;
|
||||
GeneralProperties _generalProperties;
|
||||
properties::PropertyOwner _debugPropertyOwner;
|
||||
|
||||
};
|
||||
|
||||
} // namespace openspace::globebrowsing
|
||||
|
||||
Reference in New Issue
Block a user