mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 04:30:09 -05:00
Performance Optimizations (#450)
* Make derived transform classes less involved in simulation state * Add performance measurements in openspaceengine * Avoid redundant transformation lookups * Fix bug causing redundant calls to GPULayerManager::bind * Move water reflectance to alpha component of normal buffer. Remove otherData buffer.
This commit is contained in:
@@ -83,7 +83,6 @@ uniform sampler3D inscatterTexture;
|
||||
uniform sampler2DMS mainPositionTexture;
|
||||
uniform sampler2DMS mainNormalTexture;
|
||||
uniform sampler2DMS mainColorTexture;
|
||||
uniform sampler2DMS otherDataTexture;
|
||||
|
||||
// Model Transform Matrix Used for Globe Rendering
|
||||
uniform dmat4 dInverseSgctEyeToWorldTranform; // SGCT Eye to OS World
|
||||
@@ -596,7 +595,6 @@ void main() {
|
||||
vec4 color = texelFetch(mainColorTexture, ivec2(gl_FragCoord), i);
|
||||
// Data in the mainPositionTexture are written in view space (view plus camera rig)
|
||||
vec4 position = texelFetch(mainPositionTexture, ivec2(gl_FragCoord), i);
|
||||
vec4 otherData = texelFetch(otherDataTexture, ivec2(gl_FragCoord), i);
|
||||
|
||||
// Ray in object space
|
||||
dRay ray;
|
||||
@@ -708,7 +706,7 @@ void main() {
|
||||
color, sunIntensityInscatter);
|
||||
vec3 groundColor = groundColor(x, tF, v, s, r, mu, attenuation,
|
||||
color, normal.xyz, irradianceFactor,
|
||||
otherData.r, sunIntensityGround);
|
||||
normal.a, sunIntensityGround);
|
||||
vec3 sunColor = sunColor(x, tF, v, s, r, mu, irradianceFactor);
|
||||
|
||||
// Final Color of ATM plus terrain:
|
||||
|
||||
@@ -195,6 +195,12 @@ void RenderableTrailOrbit::update(const UpdateData& data) {
|
||||
// Update the trails; the report contains whether any of the other values has been
|
||||
// touched and if so, how many
|
||||
UpdateReport report = updateTrails(data);
|
||||
_previousTime = data.time.j2000Seconds();
|
||||
|
||||
// Do not do anything if no point needs to be updated
|
||||
if (!report.permanentPointsNeedUpdate && !report.floatingPointNeedsUpdate) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 2
|
||||
// Write the current location into the floating position
|
||||
@@ -205,14 +211,16 @@ void RenderableTrailOrbit::update(const UpdateData& data) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _primaryRenderInformation._vBufferID);
|
||||
|
||||
// 3
|
||||
if (!report.needsUpdate) {
|
||||
// If no other values have been touched, we only need to upload the floating value
|
||||
glBufferSubData(
|
||||
GL_ARRAY_BUFFER,
|
||||
_primaryRenderInformation.first * sizeof(TrailVBOLayout),
|
||||
sizeof(TrailVBOLayout),
|
||||
_vertexArray.data() + _primaryRenderInformation.first
|
||||
);
|
||||
if (!report.permanentPointsNeedUpdate) {
|
||||
if (report.floatingPointNeedsUpdate) {
|
||||
// If no other values have been touched, we only need to upload the floating value
|
||||
glBufferSubData(
|
||||
GL_ARRAY_BUFFER,
|
||||
_primaryRenderInformation.first * sizeof(TrailVBOLayout),
|
||||
sizeof(TrailVBOLayout),
|
||||
_vertexArray.data() + _primaryRenderInformation.first
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Otherwise we need to check how many values have been changed
|
||||
@@ -315,7 +323,7 @@ void RenderableTrailOrbit::update(const UpdateData& data) {
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
|
||||
glBindVertexArray(0);
|
||||
_previousTime = data.time.j2000Seconds();
|
||||
|
||||
}
|
||||
|
||||
RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails(
|
||||
@@ -323,14 +331,14 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails(
|
||||
{
|
||||
if (_needsFullSweep) {
|
||||
fullSweep(data.time.j2000Seconds());
|
||||
return { true, UpdateReport::All } ;
|
||||
return { false, true, UpdateReport::All } ;
|
||||
}
|
||||
|
||||
|
||||
const double Epsilon = 1e-7;
|
||||
// When time stands still (at the iron hill), we don't need to perform any work
|
||||
if (std::abs(data.time.j2000Seconds() - _previousTime) < Epsilon) {
|
||||
return { false, 0 };
|
||||
return { false, false, 0 };
|
||||
}
|
||||
|
||||
double secondsPerPoint = _period / (_resolution - 1);
|
||||
@@ -345,14 +353,14 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails(
|
||||
// intervals
|
||||
|
||||
if (std::abs(delta) < Epsilon) {
|
||||
return { false, 0 };
|
||||
return { false, false, 0 };
|
||||
}
|
||||
|
||||
if (delta > 0.0) {
|
||||
// Check whether we need to drop a new permanent point. This is only the case if
|
||||
// enough (> secondsPerPoint) time has passed since the last permanent point
|
||||
if (std::abs(delta) < secondsPerPoint) {
|
||||
return { false, 0 };
|
||||
return { true, false, 0 };
|
||||
}
|
||||
|
||||
// See how many points we need to drop
|
||||
@@ -362,7 +370,7 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails(
|
||||
// array, it is faster to regenerate the entire array
|
||||
if (nNewPoints >= _resolution) {
|
||||
fullSweep(data.time.j2000Seconds());
|
||||
return { true, UpdateReport::All };
|
||||
return { false, true, UpdateReport::All };
|
||||
}
|
||||
|
||||
for (int i = 0; i < nNewPoints; ++i) {
|
||||
@@ -386,7 +394,7 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails(
|
||||
// future
|
||||
_firstPointTime += nNewPoints * secondsPerPoint;
|
||||
|
||||
return { true, nNewPoints };
|
||||
return { false, true, nNewPoints };
|
||||
}
|
||||
else {
|
||||
// See how many new points needs to be generated. Delta is negative, so we need
|
||||
@@ -397,7 +405,7 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails(
|
||||
// array, it is faster to regenerate the entire array
|
||||
if (nNewPoints >= _resolution) {
|
||||
fullSweep(data.time.j2000Seconds());
|
||||
return { true, UpdateReport::All };
|
||||
return { false, true, UpdateReport::All };
|
||||
}
|
||||
|
||||
for (int i = 0; i < nNewPoints; ++i) {
|
||||
@@ -423,7 +431,7 @@ RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails(
|
||||
// The previously youngest point has become nNewPoints steps older
|
||||
_lastPointTime -= nNewPoints * secondsPerPoint;
|
||||
|
||||
return { true, -nNewPoints };
|
||||
return { false, true, -nNewPoints };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,9 +66,10 @@ private:
|
||||
/// about which parts of the vertex array to update
|
||||
struct UpdateReport {
|
||||
static const int All = 0; ///< The entire array was touched in the update
|
||||
|
||||
/// If \c true at least one point was touched
|
||||
bool needsUpdate;
|
||||
/// If \c true the floating point needs to be updated
|
||||
bool floatingPointNeedsUpdate;
|
||||
/// If \c true at least one of their permanent point were touched
|
||||
bool permanentPointsNeedUpdate;
|
||||
/// Returns the number of fixed points that were touched in the update method
|
||||
/// If this value is negative, the newest values were replaced, if positive the
|
||||
/// oldest
|
||||
|
||||
@@ -533,10 +533,9 @@ bool FixedRotation::initialize() {
|
||||
return res;
|
||||
}
|
||||
|
||||
void FixedRotation::update(const UpdateData&) {
|
||||
glm::dmat3 FixedRotation::matrix(const Time& time) const {
|
||||
if (!_enabled) {
|
||||
_matrix = glm::dmat3();
|
||||
return;
|
||||
return glm::dmat3();
|
||||
}
|
||||
|
||||
glm::vec3 x = xAxis();
|
||||
@@ -554,10 +553,10 @@ void FixedRotation::update(const UpdateData&) {
|
||||
"Dangerously collinear vectors detected: " <<
|
||||
"x: " << x << " y: " << y << " z: " << z
|
||||
);
|
||||
_matrix = glm::dmat3();
|
||||
return glm::dmat3();
|
||||
}
|
||||
else {
|
||||
_matrix = {
|
||||
return {
|
||||
x.x, x.y, x.z,
|
||||
y.x, y.y, y.z,
|
||||
z.x, z.y, z.z
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
void update(const UpdateData& data) override;
|
||||
glm::dmat3 matrix(const Time& time) const override;
|
||||
|
||||
private:
|
||||
glm::vec3 xAxis() const;
|
||||
|
||||
@@ -74,6 +74,14 @@ LuaRotation::LuaRotation()
|
||||
, _state(false)
|
||||
{
|
||||
addProperty(_luaScriptFile);
|
||||
|
||||
_luaScriptFile.onChange([&]() {
|
||||
requireUpdate();
|
||||
_fileHandle = std::make_unique<ghoul::filesystem::File>(_luaScriptFile);
|
||||
_fileHandle->setCallback([&](const ghoul::filesystem::File&) {
|
||||
requireUpdate();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
LuaRotation::LuaRotation(const ghoul::Dictionary& dictionary)
|
||||
@@ -88,7 +96,7 @@ LuaRotation::LuaRotation(const ghoul::Dictionary& dictionary)
|
||||
_luaScriptFile = absPath(dictionary.value<std::string>(ScriptInfo.identifier));
|
||||
}
|
||||
|
||||
void LuaRotation::update(const UpdateData& data) {
|
||||
glm::dmat3 LuaRotation::matrix(const Time& time) const {
|
||||
ghoul::lua::runScriptFile(_state, _luaScriptFile);
|
||||
|
||||
// Get the scaling function
|
||||
@@ -99,11 +107,11 @@ void LuaRotation::update(const UpdateData& data) {
|
||||
"LuaRotation",
|
||||
"Script '" << _luaScriptFile << "' does not have a function 'rotation'"
|
||||
);
|
||||
return;
|
||||
return glm::dmat3(1.0);
|
||||
}
|
||||
|
||||
// First argument is the number of seconds past the J2000 epoch in ingame time
|
||||
lua_pushnumber(_state, data.time.j2000Seconds());
|
||||
lua_pushnumber(_state, time.j2000Seconds());
|
||||
|
||||
// Second argument is the number of milliseconds past the J2000 epoch in wallclock
|
||||
using namespace std::chrono;
|
||||
@@ -129,7 +137,7 @@ void LuaRotation::update(const UpdateData& data) {
|
||||
values[i] = luaL_checknumber(_state, -1 - i);
|
||||
}
|
||||
|
||||
_matrix = glm::make_mat3(values);
|
||||
return glm::make_mat3(values);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
#include <ghoul/lua/luastate.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -40,12 +41,13 @@ public:
|
||||
LuaRotation();
|
||||
LuaRotation(const ghoul::Dictionary& dictionary);
|
||||
|
||||
void update(const UpdateData& data) override;
|
||||
glm::dmat3 matrix(const Time& data) const override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
properties::StringProperty _luaScriptFile;
|
||||
std::unique_ptr<ghoul::filesystem::File> _fileHandle;
|
||||
ghoul::lua::LuaState _state;
|
||||
};
|
||||
|
||||
|
||||
@@ -67,7 +67,9 @@ StaticRotation::StaticRotation()
|
||||
: _rotationMatrix(RotationInfo, glm::dmat3(1.0), glm::dmat3(-1.0), glm::dmat3(1.0))
|
||||
{
|
||||
addProperty(_rotationMatrix);
|
||||
_rotationMatrix.onChange([this]() { _matrix = _rotationMatrix; });
|
||||
_rotationMatrix.onChange([this]() {
|
||||
requireUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
StaticRotation::StaticRotation(const ghoul::Dictionary& dictionary)
|
||||
@@ -92,4 +94,8 @@ StaticRotation::StaticRotation(const ghoul::Dictionary& dictionary)
|
||||
|
||||
}
|
||||
|
||||
glm::dmat3 StaticRotation::matrix(const Time&) const {
|
||||
return _rotationMatrix;
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
StaticRotation();
|
||||
StaticRotation(const ghoul::Dictionary& dictionary);
|
||||
|
||||
glm::dmat3 matrix(const Time& time) const override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
|
||||
@@ -69,6 +69,14 @@ LuaScale::LuaScale()
|
||||
, _state(false)
|
||||
{
|
||||
addProperty(_luaScriptFile);
|
||||
|
||||
_luaScriptFile.onChange([&]() {
|
||||
requireUpdate();
|
||||
_fileHandle = std::make_unique<ghoul::filesystem::File>(_luaScriptFile);
|
||||
_fileHandle->setCallback([&](const ghoul::filesystem::File&) {
|
||||
requireUpdate();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
LuaScale::LuaScale(const ghoul::Dictionary& dictionary)
|
||||
@@ -79,7 +87,7 @@ LuaScale::LuaScale(const ghoul::Dictionary& dictionary)
|
||||
_luaScriptFile = absPath(dictionary.value<std::string>(ScriptInfo.identifier));
|
||||
}
|
||||
|
||||
void LuaScale::update(const UpdateData& data) {
|
||||
double LuaScale::scaleValue(const Time& time) const {
|
||||
ghoul::lua::runScriptFile(_state, _luaScriptFile);
|
||||
|
||||
// Get the scaling function
|
||||
@@ -90,11 +98,11 @@ void LuaScale::update(const UpdateData& data) {
|
||||
"LuaScale",
|
||||
"Script '" << _luaScriptFile << "' does not have a function 'scale'"
|
||||
);
|
||||
return;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
// First argument is the number of seconds past the J2000 epoch in ingame time
|
||||
lua_pushnumber(_state, data.time.j2000Seconds());
|
||||
lua_pushnumber(_state, time.j2000Seconds());
|
||||
|
||||
// Second argument is the number of milliseconds past the J2000 epoch in wallclock
|
||||
using namespace std::chrono;
|
||||
@@ -115,7 +123,7 @@ void LuaScale::update(const UpdateData& data) {
|
||||
);
|
||||
}
|
||||
|
||||
_scale = luaL_checknumber(_state, -1);
|
||||
return luaL_checknumber(_state, -1);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <openspace/properties/stringproperty.h>
|
||||
|
||||
#include <ghoul/lua/luastate.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
@@ -40,12 +41,13 @@ public:
|
||||
LuaScale();
|
||||
LuaScale(const ghoul::Dictionary& dictionary);
|
||||
|
||||
void update(const UpdateData& data) override;
|
||||
double scaleValue(const Time& time) const override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
properties::StringProperty _luaScriptFile;
|
||||
std::unique_ptr<ghoul::filesystem::File> _fileHandle;
|
||||
ghoul::lua::LuaState _state;
|
||||
};
|
||||
|
||||
|
||||
@@ -54,12 +54,18 @@ documentation::Documentation StaticScale::Documentation() {
|
||||
};
|
||||
}
|
||||
|
||||
double StaticScale::scaleValue(const Time&) const {
|
||||
return _scaleValue;
|
||||
}
|
||||
|
||||
StaticScale::StaticScale()
|
||||
: _scaleValue(ScaleInfo, 1.0, 1.0, 1e6)
|
||||
{
|
||||
addProperty(_scaleValue);
|
||||
|
||||
_scaleValue.onChange([&](){ _scale = _scaleValue; });
|
||||
_scaleValue.onChange([this]() {
|
||||
requireUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
StaticScale::StaticScale(const ghoul::Dictionary& dictionary)
|
||||
|
||||
@@ -37,6 +37,7 @@ class StaticScale : public Scale {
|
||||
public:
|
||||
StaticScale();
|
||||
StaticScale(const ghoul::Dictionary& dictionary);
|
||||
double scaleValue(const Time& time) const override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ Fragment getFragment() {
|
||||
frag.color = gridColor;
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vs_positionViewSpace;
|
||||
frag.gOtherData = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ Fragment getFragment() {
|
||||
}
|
||||
|
||||
// G-Buffer
|
||||
frag.gOtherData = vec4(frag.color.xyz, 1.0);
|
||||
frag.gPosition = vs_gPosition;
|
||||
frag.gNormal = vec4(vs_gNormal, 1.0);
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@ Fragment getFragment() {
|
||||
}
|
||||
|
||||
// G-Buffer
|
||||
frag.gOtherData = vec4(frag.color.xyz, 1.0);
|
||||
frag.gPosition = vs_gPosition;
|
||||
// There is no normal here
|
||||
// TODO: Add the correct normal if necessary (JCC)
|
||||
|
||||
@@ -46,7 +46,6 @@ Fragment getFragment() {
|
||||
frag.depth = pscDepth(position);
|
||||
|
||||
// G-Buffer
|
||||
frag.gOtherData = vec4(frag.color.xyz, 1.0);
|
||||
frag.gPosition = vs_gPosition;
|
||||
// There is no normal here
|
||||
// TODO: Add the correct normal (JCC)
|
||||
|
||||
@@ -77,8 +77,10 @@ LuaTranslation::LuaTranslation()
|
||||
addProperty(_luaScriptFile);
|
||||
|
||||
_luaScriptFile.onChange([&](){
|
||||
requireUpdate();
|
||||
_fileHandle = std::make_unique<ghoul::filesystem::File>(_luaScriptFile);
|
||||
_fileHandle->setCallback([&](const ghoul::filesystem::File&) {
|
||||
requireUpdate();
|
||||
notifyObservers();
|
||||
});
|
||||
});
|
||||
@@ -96,7 +98,7 @@ LuaTranslation::LuaTranslation(const ghoul::Dictionary& dictionary)
|
||||
_luaScriptFile = absPath(dictionary.value<std::string>(ScriptInfo.identifier));
|
||||
}
|
||||
|
||||
void LuaTranslation::update(const UpdateData& data) {
|
||||
glm::dvec3 LuaTranslation::position(const Time& time) const {
|
||||
ghoul::lua::runScriptFile(_state, _luaScriptFile);
|
||||
|
||||
// Get the scaling function
|
||||
@@ -107,11 +109,11 @@ void LuaTranslation::update(const UpdateData& data) {
|
||||
"LuaScale",
|
||||
"Script '" << _luaScriptFile << "' does not have a function 'translation'"
|
||||
);
|
||||
return;
|
||||
return glm::dvec3(0.0);
|
||||
}
|
||||
|
||||
// First argument is the number of seconds past the J2000 epoch in ingame time
|
||||
lua_pushnumber(_state, data.time.j2000Seconds());
|
||||
lua_pushnumber(_state, time.j2000Seconds());
|
||||
|
||||
// Second argument is the number of milliseconds past the J2000 epoch in wallclock
|
||||
using namespace std::chrono;
|
||||
@@ -137,7 +139,7 @@ void LuaTranslation::update(const UpdateData& data) {
|
||||
values[i] = luaL_checknumber(_state, -1 - i);
|
||||
}
|
||||
|
||||
_positionValue = glm::make_vec3(values);
|
||||
return glm::make_vec3(values);
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -43,15 +43,14 @@ public:
|
||||
LuaTranslation();
|
||||
LuaTranslation(const ghoul::Dictionary& dictionary);
|
||||
|
||||
virtual void update(const UpdateData& data) override;
|
||||
glm::dvec3 position(const Time& time) const override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
properties::StringProperty _luaScriptFile;
|
||||
ghoul::lua::LuaState _state;
|
||||
|
||||
std::unique_ptr<ghoul::filesystem::File> _fileHandle;
|
||||
ghoul::lua::LuaState _state;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -70,7 +70,14 @@ StaticTranslation::StaticTranslation()
|
||||
{
|
||||
addProperty(_position);
|
||||
|
||||
_position.onChange([&](){ _positionValue = _position; });
|
||||
_position.onChange([this]() {
|
||||
requireUpdate();
|
||||
notifyObservers();
|
||||
});
|
||||
}
|
||||
|
||||
glm::dvec3 StaticTranslation::position(const Time&) const {
|
||||
return _position;
|
||||
}
|
||||
|
||||
StaticTranslation::StaticTranslation(const ghoul::Dictionary& dictionary)
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
StaticTranslation();
|
||||
StaticTranslation(const ghoul::Dictionary& dictionary);
|
||||
|
||||
glm::dvec3 position(const Time& time) const;
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
private:
|
||||
|
||||
@@ -62,7 +62,6 @@ Fragment getFragment() {
|
||||
frag.color = fullColor;
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vec4(1e32, 1e32, 1e32, 1.0);
|
||||
frag.gOtherData = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@ Fragment getFragment() {
|
||||
frag.color = fullColor;
|
||||
frag.depth = gs_screenSpaceDepth;
|
||||
frag.gPosition = vec4(1e27, 1e27, 1e27, 1.0);
|
||||
frag.gOtherData = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
return frag;
|
||||
|
||||
@@ -42,7 +42,6 @@ Fragment getFragment() {
|
||||
|
||||
// JCC: Need to change the position to camera space
|
||||
frag.gPosition = vs_positionViewSpace;
|
||||
frag.gOtherData = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
return frag;
|
||||
|
||||
@@ -58,7 +58,6 @@ Fragment getFragment() {
|
||||
//frag.color = texture(galaxyTexture, vs_st);
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vec4(1e27, 1e27, 1e27, 1.0);
|
||||
frag.gOtherData = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
return frag;
|
||||
|
||||
@@ -48,7 +48,6 @@ Fragment getFragment() {
|
||||
//frag.depth = gs_screenSpaceDepth;
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vec4(1e27, 1e27, 1e27, 1.0);
|
||||
frag.gOtherData = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
return frag;
|
||||
|
||||
@@ -91,7 +91,7 @@ ghoul::opengl::ProgramObject* ChunkRenderer::getActivatedProgramWithTileData(
|
||||
// Now the shader program can be accessed
|
||||
ghoul::opengl::ProgramObject* programObject = layeredShaderManager->programObject();
|
||||
|
||||
if (layeredShaderManager->updatedOnLastCall()) {
|
||||
if (layeredShaderManager->updatedSinceLastCall()) {
|
||||
gpuLayerManager->bind(programObject, *_layerManager);
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ LayerShaderManager::LayerShaderManager(const std::string& shaderName,
|
||||
: _shaderName(shaderName)
|
||||
, _vsPath(vsPath)
|
||||
, _fsPath(fsPath)
|
||||
, _updatedOnLastCall(false)
|
||||
, _updatedSinceLastCall(false)
|
||||
{}
|
||||
|
||||
LayerShaderManager::~LayerShaderManager() {
|
||||
@@ -243,11 +243,13 @@ void LayerShaderManager::recompileShaderProgram(
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_programObject->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
_updatedOnLastCall = true;
|
||||
_updatedSinceLastCall = true;
|
||||
}
|
||||
|
||||
bool LayerShaderManager::updatedOnLastCall() {
|
||||
return _updatedOnLastCall;
|
||||
bool LayerShaderManager::updatedSinceLastCall() {
|
||||
const bool updated = _updatedSinceLastCall;
|
||||
_updatedSinceLastCall = false;
|
||||
return updated;
|
||||
}
|
||||
|
||||
} // namespace openspace::globebrowsing
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
*/
|
||||
ghoul::opengl::ProgramObject* programObject() const;
|
||||
|
||||
bool updatedOnLastCall();
|
||||
bool updatedSinceLastCall();
|
||||
|
||||
void recompileShaderProgram(LayerShaderPreprocessingData preprocessingData);
|
||||
|
||||
@@ -96,7 +96,7 @@ private:
|
||||
const std::string _vsPath;
|
||||
const std::string _fsPath;
|
||||
|
||||
bool _updatedOnLastCall;
|
||||
bool _updatedSinceLastCall;
|
||||
};
|
||||
|
||||
} // namespace openspace::globebrowsing
|
||||
|
||||
@@ -280,16 +280,16 @@ Fragment getTileFragment() {
|
||||
// Other data
|
||||
#if USE_WATERMASK
|
||||
// Water reflectance is added to the G-Buffer.
|
||||
frag.gOtherData = vec4(waterReflectance, waterReflectance, waterReflectance, 1.0);
|
||||
frag.gNormal.w = waterReflectance;
|
||||
#else
|
||||
frag.gOtherData = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
frag.gNormal.w = 0;
|
||||
#endif
|
||||
// Normal is written Object Space.
|
||||
// Right now the only renderable using this info is the atm and,
|
||||
// because all calculation for light interactions are done in Object
|
||||
// Space, we avoid a new computation saving the normals in Object Space.
|
||||
frag.gNormal = vec4(normalModelSpace, 1.0);
|
||||
frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space
|
||||
frag.gNormal.xyz = normalModelSpace;
|
||||
frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space
|
||||
|
||||
frag.depth = fs_position.w;
|
||||
return frag;
|
||||
|
||||
@@ -119,18 +119,25 @@ SpiceRotation::SpiceRotation(const ghoul::Dictionary& dictionary)
|
||||
|
||||
addProperty(_sourceFrame);
|
||||
addProperty(_destinationFrame);
|
||||
|
||||
auto update = [this]() {
|
||||
requireUpdate();
|
||||
};
|
||||
|
||||
_sourceFrame.onChange(update);
|
||||
_destinationFrame.onChange(update);
|
||||
}
|
||||
|
||||
void SpiceRotation::update(const UpdateData& data) {
|
||||
glm::dmat3 SpiceRotation::matrix(const Time& time) const {
|
||||
try {
|
||||
_matrix = SpiceManager::ref().positionTransformMatrix(
|
||||
return SpiceManager::ref().positionTransformMatrix(
|
||||
_sourceFrame,
|
||||
_destinationFrame,
|
||||
data.time.j2000Seconds()
|
||||
time.j2000Seconds()
|
||||
);
|
||||
}
|
||||
catch (const SpiceManager::SpiceException&) {
|
||||
_matrix = glm::dmat3(1.0);
|
||||
return glm::dmat3(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class SpiceRotation : public Rotation {
|
||||
public:
|
||||
SpiceRotation(const ghoul::Dictionary& dictionary);
|
||||
const glm::dmat3& matrix() const;
|
||||
void update(const UpdateData& data) override;
|
||||
glm::dmat3 matrix(const Time& time) const override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
|
||||
@@ -68,8 +68,6 @@ Fragment getFragment() {
|
||||
|
||||
frag.color = vec4(diffuse.rgb, transparency);
|
||||
frag.depth = vs_position.w;
|
||||
|
||||
frag.gOtherData = vec4(diffuse.xyz, 1.0);
|
||||
frag.gPosition = vs_gPosition;
|
||||
frag.gNormal = vec4(vs_gNormal, 1.0);
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ Fragment getFragment() {
|
||||
frag.color = vec4(diffuse.rgb, transparency);
|
||||
frag.depth = vs_position.w;
|
||||
|
||||
frag.gOtherData = vec4(diffuse.xyz, 1.0);
|
||||
frag.gPosition = vs_gPosition;
|
||||
frag.gNormal = vec4(vs_gNormal, 1.0);
|
||||
|
||||
|
||||
@@ -89,7 +89,6 @@ Fragment getFragment() {
|
||||
frag.color = diffuse;
|
||||
frag.depth = vs_position.w;
|
||||
|
||||
//frag.gOtherData = diffuse;
|
||||
//frag.gPosition = vs_gPosition;
|
||||
//frag.gNormal = vs_gNormal;
|
||||
|
||||
|
||||
@@ -111,7 +111,6 @@ Fragment getFragment() {
|
||||
frag.color = vec4(diffuse.rgb, transparency);
|
||||
frag.depth = depth;
|
||||
|
||||
frag.gOtherData = vec4(diffuse.xyz, 1.0);
|
||||
frag.gPosition = vs_gPosition;
|
||||
frag.gNormal = vec4(vs_gNormal, 1.0);
|
||||
|
||||
|
||||
@@ -118,7 +118,6 @@ Fragment getFragment() {
|
||||
frag.color = vec4(diffuse.rgb, transparency);
|
||||
frag.depth = depth;
|
||||
|
||||
frag.gOtherData = vec4(diffuse.xyz, 1.0);
|
||||
frag.gPosition = vs_gPosition;
|
||||
frag.gNormal = vec4(vs_gNormal, 1.0);
|
||||
|
||||
|
||||
@@ -88,7 +88,6 @@ Fragment getFragment() {
|
||||
frag.depth = pscDepth(position);
|
||||
|
||||
// G-Buffer
|
||||
frag.gOtherData = vec4(fullColor.xyz, 1.0);
|
||||
frag.gPosition = ge_gPosition;
|
||||
// There is no normal here
|
||||
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
@@ -195,6 +195,7 @@ KeplerTranslation::KeplerTranslation()
|
||||
{
|
||||
auto update = [this]() {
|
||||
_orbitPlaneDirty = true;
|
||||
requireUpdate();
|
||||
};
|
||||
|
||||
// Only the eccentricity, semimajor axis, inclination, and location of ascending node
|
||||
@@ -241,10 +242,6 @@ KeplerTranslation::KeplerTranslation(const ghoul::Dictionary& dictionary)
|
||||
);
|
||||
}
|
||||
|
||||
glm::dvec3 KeplerTranslation::position() const {
|
||||
return _position;
|
||||
}
|
||||
|
||||
double KeplerTranslation::eccentricAnomaly(double meanAnomaly) const {
|
||||
// Compute the eccentric anomaly (the location of the spacecraft taking the
|
||||
// eccentricity of the orbit into account) using different solves for the regimes in
|
||||
@@ -292,13 +289,13 @@ double KeplerTranslation::eccentricAnomaly(double meanAnomaly) const {
|
||||
}
|
||||
}
|
||||
|
||||
void KeplerTranslation::update(const UpdateData& data) {
|
||||
glm::dvec3 KeplerTranslation::position(const Time& time) const {
|
||||
if (_orbitPlaneDirty) {
|
||||
computeOrbitPlane();
|
||||
_orbitPlaneDirty = false;
|
||||
}
|
||||
|
||||
double t = data.time.j2000Seconds() - _epoch;
|
||||
double t = time.j2000Seconds() - _epoch;
|
||||
double meanMotion = 2.0 * glm::pi<double>() / _period;
|
||||
double meanAnomaly = glm::radians(_meanAnomalyAtEpoch.value()) + t * meanMotion;
|
||||
double e = eccentricAnomaly(meanAnomaly);
|
||||
@@ -310,10 +307,10 @@ void KeplerTranslation::update(const UpdateData& data) {
|
||||
a * sqrt(1.0 - _eccentricity * _eccentricity) * sin(e),
|
||||
0.0
|
||||
};
|
||||
_position = _orbitPlaneRotation * p;
|
||||
return _orbitPlaneRotation * p;
|
||||
}
|
||||
|
||||
void KeplerTranslation::computeOrbitPlane() {
|
||||
void KeplerTranslation::computeOrbitPlane() const {
|
||||
// We assume the following coordinate system:
|
||||
// z = axis of rotation
|
||||
// x = pointing towards the first point of Aries
|
||||
|
||||
@@ -62,20 +62,10 @@ public:
|
||||
virtual ~KeplerTranslation() = default;
|
||||
|
||||
/**
|
||||
* This method returns the position of the object at the time that was passed to the
|
||||
* last call of the #update method. The KeplerTranslation caches its position, thus
|
||||
* repeated calls to this function are cheap.
|
||||
* \return The position of the object at the time of last call to the #update method
|
||||
*/
|
||||
virtual glm::dvec3 position() const override;
|
||||
|
||||
/**
|
||||
* Updates the cached position of the object to correspond to the time passed in the
|
||||
* \p data.
|
||||
* \param data The UpdateData struct that contains all information necessary to update
|
||||
* this Translation
|
||||
*/
|
||||
void update(const UpdateData& data) override;
|
||||
* Method returning the translation vector at a given time
|
||||
* \param time The time to use when doing the position lookup
|
||||
*/
|
||||
glm::dvec3 position(const Time& time) const override;
|
||||
|
||||
/**
|
||||
* Method returning the openspace::Documentation that describes the ghoul::Dictinoary
|
||||
@@ -133,7 +123,7 @@ protected:
|
||||
|
||||
private:
|
||||
/// Recombutes the rotation matrix used in the update method
|
||||
void computeOrbitPlane();
|
||||
void computeOrbitPlane() const;
|
||||
|
||||
/**
|
||||
* This method computes the eccentric anomaly (location of the space craft taking the
|
||||
@@ -164,9 +154,9 @@ private:
|
||||
properties::DoubleProperty _period;
|
||||
|
||||
/// Dirty flag for the _orbitPlaneRotation parameters
|
||||
bool _orbitPlaneDirty;
|
||||
mutable bool _orbitPlaneDirty;
|
||||
/// The rotation matrix that defines the plane of the orbit
|
||||
glm::dmat3 _orbitPlaneRotation;
|
||||
mutable glm::dmat3 _orbitPlaneRotation;
|
||||
|
||||
/// The cached position for the last time with which the update method was called
|
||||
glm::dvec3 _position;
|
||||
|
||||
@@ -159,6 +159,7 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
auto update = [this](){
|
||||
requireUpdate();
|
||||
notifyObservers();
|
||||
};
|
||||
|
||||
@@ -172,18 +173,14 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_frame);
|
||||
}
|
||||
|
||||
glm::dvec3 SpiceTranslation::position() const {
|
||||
return _position;
|
||||
}
|
||||
|
||||
void SpiceTranslation::update(const UpdateData& data) {
|
||||
glm::dvec3 SpiceTranslation::position(const Time& time) const {
|
||||
double lightTime = 0.0;
|
||||
_position = SpiceManager::ref().targetPosition(
|
||||
return SpiceManager::ref().targetPosition(
|
||||
_target,
|
||||
_observer,
|
||||
_frame,
|
||||
{},
|
||||
data.time.j2000Seconds(),
|
||||
time.j2000Seconds(),
|
||||
lightTime
|
||||
) * glm::pow(10.0, 3.0);
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ class SpiceTranslation : public Translation {
|
||||
public:
|
||||
SpiceTranslation(const ghoul::Dictionary& dictionary);
|
||||
|
||||
glm::dvec3 position() const override;
|
||||
void update(const UpdateData& data) override;
|
||||
glm::dvec3 position(const Time& time) const override;
|
||||
|
||||
static documentation::Documentation Documentation();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user