mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-19 11:29:08 -06:00
Update path rendering to higher precision.
This commit is contained in:
@@ -148,10 +148,10 @@ function postInitialization()
|
||||
]]--
|
||||
openspace.printInfo("Setting default values")
|
||||
openspace.setPropertyValue("Sun.renderable.enabled", false)
|
||||
openspace.setPropertyValue("SunMarker.renderable.enabled", true)
|
||||
openspace.setPropertyValue("EarthMarker.renderable.enabled", true)
|
||||
openspace.setPropertyValue("SunMarker.renderable.enabled", false)
|
||||
openspace.setPropertyValue("EarthMarker.renderable.enabled", false)
|
||||
--openspace.setPropertyValue("Constellation Bounds.renderable.enabled", false)
|
||||
openspace.setPropertyValue("PlutoTrail.renderable.enabled", false)
|
||||
openspace.setPropertyValue("PlutoTrail.renderable.enabled", true)
|
||||
openspace.setPropertyValue("PlutoTexture.renderable.enabled", false)
|
||||
|
||||
openspace.setPropertyValue("MilkyWay.renderable.transparency", 0.55)
|
||||
|
||||
@@ -140,17 +140,40 @@ void RenderablePath::render(const RenderData& data) {
|
||||
if (_start > time || _stop < time)
|
||||
return;
|
||||
|
||||
//const psc& position = data.camera.position();
|
||||
//const psc& origin = openspace::OpenSpaceEngine::ref().interactionHandler()->focusNode()->worldPosition();
|
||||
//const PowerScaledScalar& pssl = (position - origin).length();
|
||||
//double properLength = static_cast<double>(pssl.lengthf());
|
||||
//const PowerScaledScalar corrected = PowerScaledScalar::CreatePSS(properLength);
|
||||
//float exp = corrected[1];
|
||||
//
|
||||
//if (exp > 11)
|
||||
// return;
|
||||
|
||||
|
||||
int nPointsToDraw = (time - _start) / (_stop - _start) * _vertexArray.size() + 3;
|
||||
|
||||
_programObject->activate();
|
||||
|
||||
// Calculate variables to be used as uniform variables in shader
|
||||
glm::dvec3 bodyPosition = data.positionVec3;
|
||||
|
||||
// Model transform and view transform needs to be in double precision
|
||||
glm::dmat4 modelTransform =
|
||||
glm::translate(glm::dmat4(1.0), bodyPosition); // Translation
|
||||
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
|
||||
_programObject->setUniform("modelViewTransform", glm::mat4(modelViewTransform));
|
||||
_programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
|
||||
_programObject->setUniform("color", _lineColor);
|
||||
|
||||
if (_drawLine) {
|
||||
glLineWidth(_lineWidth);
|
||||
glBindVertexArray(_vaoID);
|
||||
glDrawArrays(GL_LINE_STRIP, 0, static_cast<GLsizei>(nPointsToDraw));
|
||||
glBindVertexArray(0);
|
||||
glLineWidth(1.f);
|
||||
}
|
||||
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
|
||||
glBindVertexArray(_vaoID);
|
||||
glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(nPointsToDraw));
|
||||
glBindVertexArray(0);
|
||||
|
||||
glDisable(GL_PROGRAM_POINT_SIZE);
|
||||
|
||||
/*
|
||||
psc currentPosition = data.position;
|
||||
glm::mat4 camrot = glm::mat4(data.camera.viewRotationMatrix());
|
||||
glm::mat4 transform = glm::mat4(1);
|
||||
@@ -188,6 +211,7 @@ void RenderablePath::render(const RenderData& data) {
|
||||
glBindVertexArray(0);
|
||||
|
||||
glDisable(GL_PROGRAM_POINT_SIZE);
|
||||
*/
|
||||
|
||||
_programObject->deactivate();
|
||||
}
|
||||
@@ -219,15 +243,20 @@ void RenderablePath::calculatePath(std::string observer) {
|
||||
double currentTime = _start;
|
||||
_vertexArray.resize(segments);
|
||||
|
||||
psc pscPos;
|
||||
//psc pscPos;
|
||||
//float r, g, b;
|
||||
//float g = _lineColor[1];
|
||||
//float b = _lineColor[2];
|
||||
glm::vec3 position;
|
||||
for (int i = 0; i < segments; i++) {
|
||||
glm::dvec3 p =
|
||||
SpiceManager::ref().targetPosition(_target, observer, _frame, {}, currentTime, lightTime);
|
||||
pscPos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
pscPos[3] += 3;
|
||||
position =
|
||||
glm::vec3(SpiceManager::ref().targetPosition(_target, observer, _frame, {}, currentTime, lightTime));
|
||||
|
||||
// Convert from 100 m to m
|
||||
position *= 10e2;
|
||||
|
||||
//pscPos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z);
|
||||
//pscPos[3] += 3;
|
||||
|
||||
//if (!correctPosition) {
|
||||
// r = 1.f;
|
||||
@@ -242,12 +271,12 @@ void RenderablePath::calculatePath(std::string observer) {
|
||||
// r = g = b = 0.6f;
|
||||
//}
|
||||
//add position
|
||||
_vertexArray[i] = { pscPos[0], pscPos[1], pscPos[2], pscPos[3] };
|
||||
_vertexArray[i] = { position[0], position[1], position[2], 1.0f };
|
||||
//add color for position
|
||||
//_vertexArray[i + 1] = { r, g, b, a };
|
||||
currentTime += _increment;
|
||||
}
|
||||
_lastPosition = pscPos.dvec4();
|
||||
_lastPosition = glm::vec4(position, 1.0f);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vBufferID);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, _vertexArray.size() * sizeof(VertexInfo), &_vertexArray[0]);
|
||||
|
||||
@@ -59,7 +59,7 @@ private:
|
||||
//float r, g, b, a;
|
||||
};
|
||||
void sendToGPU();
|
||||
void addPosition(psc pos);
|
||||
void addPosition(glm::vec3 pos);
|
||||
void addColor(glm::vec4 col);
|
||||
|
||||
glm::vec3 _lineColor;
|
||||
|
||||
@@ -22,23 +22,16 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
in vec4 vs_point_position;
|
||||
flat in int isHour;
|
||||
in vec4 vs_point_color;
|
||||
|
||||
uniform vec3 color;
|
||||
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
in vec4 vs_positionScreenSpace;
|
||||
in vec4 vs_pointColor;
|
||||
|
||||
Fragment getFragment() {
|
||||
vec4 position = vs_point_position;
|
||||
float depth = pscDepth(position);
|
||||
|
||||
vec4 diffuse = vs_point_color;
|
||||
|
||||
Fragment frag;
|
||||
frag.color = diffuse;
|
||||
frag.depth = depth;
|
||||
frag.color = vs_pointColor;
|
||||
frag.depth = vs_positionScreenSpace.w;
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -25,108 +25,32 @@
|
||||
#version __CONTEXT__
|
||||
|
||||
in vec4 in_point_position;
|
||||
|
||||
uniform vec3 color;
|
||||
uniform mat4 modelViewTransform;
|
||||
uniform mat4 projectionTransform;
|
||||
|
||||
out vec4 vs_point_position;
|
||||
flat out int isHour;
|
||||
out vec4 vs_point_color;
|
||||
|
||||
uniform mat4 ViewProjection;
|
||||
uniform mat4 ModelTransform;
|
||||
uniform vec4 objectVelocity;
|
||||
uniform vec4 lastPosition;
|
||||
|
||||
//this function does not consider cases where w component is negative
|
||||
float psc_distance(vec4 v1, vec4 v2) {
|
||||
// reduce position numbers
|
||||
/*while(v1.w > 1 && v2.w > 1) {
|
||||
v1.w -= 1;
|
||||
v2.w -= 1;
|
||||
} */
|
||||
// get position in vec3
|
||||
if (v1.w > 1) {
|
||||
float f = floor(v1.w);
|
||||
v1.xyz *= pow(10, f);
|
||||
v1.w -= f;
|
||||
}
|
||||
|
||||
if (v2.w > 1) {
|
||||
float f = floor(v2.w);
|
||||
v2.xyz *= pow(10, f);
|
||||
v2.w -= f;
|
||||
}
|
||||
|
||||
// using native distance function
|
||||
return distance(v1.xyz, v2.xyz);
|
||||
}
|
||||
out vec4 vs_positionScreenSpace;
|
||||
out vec4 vs_pointColor;
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
void main() {
|
||||
vec4 gray = vec4(0.6f, 0.6f, 0.6f, 0.8f);
|
||||
float cameraTooFar = 1 * pow(k, 10);
|
||||
float bigPoint = 5.f;
|
||||
float smallPoint = 2.f;
|
||||
|
||||
vec4 tmp = in_point_position;
|
||||
vec4 position = pscTransform(tmp, ModelTransform);
|
||||
vs_point_position = tmp;
|
||||
position = ViewProjection * position;
|
||||
gl_Position = z_normalization(position);
|
||||
|
||||
void main() {
|
||||
vec4 positionClipSpace = projectionTransform * modelViewTransform * in_point_position;
|
||||
vs_positionScreenSpace = z_normalization(positionClipSpace);
|
||||
|
||||
gl_Position = vs_positionScreenSpace;
|
||||
|
||||
int id = gl_VertexID;
|
||||
float hour = mod(id, 4);
|
||||
bool isNewHour = mod(id * 900, 3600) > 0;
|
||||
|
||||
vs_point_color.xyz = color;
|
||||
vs_point_color[3] = 1.f;
|
||||
|
||||
vec4 v1 = campos;
|
||||
vec4 v2 = vs_point_position;
|
||||
float cameraDistance = psc_distance(v1,v2);
|
||||
|
||||
vec4 temp = in_point_position;
|
||||
vec4 templast = lastPosition;
|
||||
|
||||
if (temp.w > 1) {
|
||||
float f = floor(temp.w);
|
||||
temp.w -= f;
|
||||
temp.xyz *= pow(10, f);
|
||||
}
|
||||
|
||||
if (templast.w > 1) {
|
||||
float f = floor(templast.w);
|
||||
templast.w -= f;
|
||||
templast.xyz *= pow(10, f);
|
||||
}
|
||||
|
||||
// while(temp.w > 1) {
|
||||
// temp.xyz *= 10;
|
||||
// temp.w -= 1;
|
||||
// }
|
||||
// while(templast.w > 1) {
|
||||
// templast.xyz *= 10;
|
||||
// templast.w -= 1;
|
||||
// }
|
||||
float observerDistance = length(temp.xyz);
|
||||
float lastDistance = length(templast.xyz);
|
||||
|
||||
if(hour > 0.1f) {
|
||||
isHour = 0;
|
||||
vs_point_color = gray;
|
||||
gl_PointSize = bigPoint;
|
||||
if(isNewHour) {
|
||||
vs_pointColor = vec4(0.6f, 0.6f, 0.6f, 0.8f);
|
||||
gl_PointSize = 5.f;
|
||||
}
|
||||
else {
|
||||
isHour = 1;
|
||||
gl_PointSize = bigPoint;
|
||||
vs_pointColor.rgb = color;
|
||||
vs_pointColor.a = 1.f;
|
||||
gl_PointSize = 10.0f;
|
||||
}
|
||||
if (observerDistance > (lastDistance/20)) {
|
||||
gl_PointSize = smallPoint;
|
||||
//vs_point_color = gray;
|
||||
}
|
||||
/*if (cameraDistance > cameraTooFar ) {
|
||||
vs_point_color[3] = 0.0f;
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
return {
|
||||
-- Determines which SGCT configuration file is loaded, that is, if there rendering
|
||||
-- occurs in a single window, a fisheye projection, or a dome cluster system
|
||||
--SGCTConfig = "${SGCT}/single.xml",
|
||||
SGCTConfig = "${SGCT}/single.xml",
|
||||
--SGCTConfig = "${SGCT}/single_fisheye.xml",
|
||||
SGCTConfig = "${SGCT}/two_nodes.xml",
|
||||
--SGCTConfig = "${SGCT}/two_nodes.xml",
|
||||
|
||||
-- Sets the scene that is to be loaded by OpenSpace. A scene file is a description
|
||||
-- of all entities that will be visible during an instance of OpenSpace
|
||||
@@ -15,6 +15,7 @@ return {
|
||||
-- Scene = "${SCENE}/newhorizons.scene",
|
||||
Scene = "${SCENE}/osirisrex.scene",
|
||||
--Scene = "${SCENE}/debugmodel.scene",
|
||||
--Scene = "${SCENE}/rosetta.scene",
|
||||
|
||||
Paths = {
|
||||
SGCT = "${BASE_PATH}/config/sgct",
|
||||
|
||||
@@ -742,8 +742,6 @@ void OpenSpaceEngine::preSynchronization() {
|
||||
FileSys.triggerFilesystemEvents();
|
||||
if (_isMaster) {
|
||||
double dt = _windowWrapper->averageDeltaTime();
|
||||
// Update the mouse velocities for interaction handler
|
||||
_interactionHandler->preSynchronization(dt);
|
||||
|
||||
Time::ref().advanceTime(dt);
|
||||
Time::ref().preSynchronization();
|
||||
@@ -751,6 +749,10 @@ void OpenSpaceEngine::preSynchronization() {
|
||||
_scriptEngine->preSynchronization();
|
||||
|
||||
_renderEngine->preSynchronization();
|
||||
|
||||
// Update the mouse velocities for interaction handler
|
||||
_interactionHandler->preSynchronization(dt);
|
||||
|
||||
_renderEngine->camera()->preSynchronization();
|
||||
|
||||
_parallelConnection->preSynchronization();
|
||||
@@ -767,12 +769,13 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
}
|
||||
|
||||
Time::ref().postSynchronizationPreDraw();
|
||||
// Sync the camera to match the previous frame
|
||||
_renderEngine->camera()->postSynchronizationPreDraw();
|
||||
|
||||
|
||||
_scriptEngine->postSynchronizationPreDraw();
|
||||
_renderEngine->postSynchronizationPreDraw();
|
||||
|
||||
// Sync the camera to match the previous frame
|
||||
_renderEngine->camera()->postSynchronizationPreDraw();
|
||||
|
||||
// Step the camera using the current mouse velocities which are synced
|
||||
_interactionHandler->postSynchronizationPreDraw();
|
||||
|
||||
|
||||
@@ -171,9 +171,7 @@ bool SceneGraphNode::deinitialize() {
|
||||
}
|
||||
|
||||
void SceneGraphNode::update(const UpdateData& data) {
|
||||
_worldPositionCached = calculateWorldPosition();
|
||||
UpdateData newUpdateData = data;
|
||||
newUpdateData.position = worldPosition();
|
||||
if (_ephemeris) {
|
||||
if (data.doPerformanceMeasurement) {
|
||||
glFinish();
|
||||
@@ -203,6 +201,8 @@ void SceneGraphNode::update(const UpdateData& data) {
|
||||
else
|
||||
_renderable->update(newUpdateData);
|
||||
}
|
||||
_worldPositionCached = calculateWorldPosition();
|
||||
newUpdateData.position = worldPosition();
|
||||
}
|
||||
|
||||
void SceneGraphNode::evaluate(const Camera* camera, const psc& parentPosition) {
|
||||
|
||||
Reference in New Issue
Block a user