mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-02 08:49:20 -05:00
Fade almost done, issue with reading some data to the shader
This commit is contained in:
committed by
ElonOlsson
parent
b81db510de
commit
c4a7e7f930
@@ -50,6 +50,7 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
@@ -742,7 +743,7 @@ void RenderableSatellites::initializeGL() {
|
||||
_uniformCache.segments = _programObject->uniformLocation("numberOfSegments");
|
||||
_uniformCache.position = _programObject->uniformLocation("debrisPosition");
|
||||
_uniformCache.numberOfOrbits = _programObject->uniformLocation("numberOfOrbits");
|
||||
_uniformCache.vertexIDs = _programObject->uniformLocation("vertexIDs");
|
||||
_uniformCache.inGameTime = _programObject->uniformLocation("inGameTime");
|
||||
|
||||
updateBuffers();
|
||||
|
||||
@@ -776,9 +777,30 @@ int getNearestVertexNeighbour(int whatOrbit) {
|
||||
}
|
||||
|
||||
void RenderableSatellites::render(const RenderData& data, RendererTasks&) {
|
||||
if (_TLEData.empty())
|
||||
return;
|
||||
_inGameTime = data.time.j2000Seconds();
|
||||
//if (_TLEData.empty())
|
||||
// return;
|
||||
_inGameTime = static_cast<float>(data.time.j2000Seconds());
|
||||
// -----------------
|
||||
double nrOfPeriods = (_inGameTime - _vertexBufferData[4].epoch) / _vertexBufferData[4].period;
|
||||
double periodFraction = std::fmod(nrOfPeriods, 1);
|
||||
|
||||
float offsetPeriods = _vertexBufferData[4].time / float(_vertexBufferData[4].period);
|
||||
float offsetFraction = std::fmod(offsetPeriods, 1);
|
||||
|
||||
float vertexDistance = float(periodFraction) - offsetFraction;
|
||||
|
||||
if (vertexDistance < 0) {
|
||||
vertexDistance += 1;
|
||||
}
|
||||
|
||||
// int vertexID = gl_VertexID;
|
||||
// float id = float(vertexID) / float(numberOfSegments*numberOfOrbits);
|
||||
|
||||
double kuken = (1 - vertexDistance);
|
||||
double fade = std::min(std::max(kuken, 0.0), 1.0);
|
||||
LINFO(fmt::format("fade: {}", fade));
|
||||
|
||||
// -----------------
|
||||
|
||||
std::vector<TrailVBOLayout>::iterator it = _vertexBufferData.begin();
|
||||
std::vector<unsigned int> vertexIDs;
|
||||
@@ -830,9 +852,11 @@ void RenderableSatellites::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
_programObject->setUniform(_uniformCache.vertexIDs, vertexIDs.data());
|
||||
|
||||
_programObject->setUniform(_uniformCache.numberOfOrbits, _TLEData.size());
|
||||
//_programObject->setUniform(_uniformCache.numberOfOrbits, _TLEData.size());
|
||||
|
||||
_programObject->setUniform(_uniformCache.opacity, _opacity);
|
||||
_programObject->setUniform(_uniformCache.inGameTime, _inGameTime);
|
||||
|
||||
|
||||
glm::dmat4 modelTransform =
|
||||
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
|
||||
@@ -907,13 +931,19 @@ void RenderableSatellites::updateBuffers() {
|
||||
_vertexBufferData[index].y = position.y;
|
||||
_vertexBufferData[index].z = position.z;
|
||||
_vertexBufferData[index].time = timeOffset;
|
||||
if (i > 0) {
|
||||
_indexBufferData[elementindex++] = static_cast<unsigned int>(index) - 1;
|
||||
_indexBufferData[elementindex++] = static_cast<unsigned int>(index);
|
||||
}
|
||||
_vertexBufferData[index].epoch = static_cast<float>(orbit.epoch);
|
||||
_vertexBufferData[index].period = static_cast<float>(orbit.period);
|
||||
|
||||
//if (i > 0) {
|
||||
//_indexBufferData[elementindex++] = static_cast<unsigned int>(index) - 1;
|
||||
//_indexBufferData[elementindex++] = static_cast<unsigned int>(index);
|
||||
//}
|
||||
}
|
||||
++orbitindex;
|
||||
}
|
||||
|
||||
|
||||
|
||||
glBindVertexArray(_vertexArray);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace openspace {
|
||||
private:
|
||||
/// The layout of the VBOs
|
||||
struct TrailVBOLayout {
|
||||
float x, y, z, time;
|
||||
float x, y, z, time, epoch, period;
|
||||
};
|
||||
|
||||
KeplerTranslation _keplerTranslator;
|
||||
@@ -126,7 +126,7 @@ namespace openspace {
|
||||
double _inGameTime = 0.0;
|
||||
|
||||
UniformCache(opacity, modelView, projection, color, useLineFade, lineFade,
|
||||
segments, position, vertexIDs, numberOfOrbits)
|
||||
segments, position, vertexIDs, numberOfOrbits, inGameTime)
|
||||
_uniformCache;
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ in float fade;
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
frag.color = vec4(color * fade, fade * opacity);
|
||||
frag.color = vec4(color, fade * opacity);
|
||||
frag.depth = vs_position.w;
|
||||
frag.gPosition = viewSpacePosition;
|
||||
frag.gNormal = vec4(-viewSpacePosition.xyz, 0);
|
||||
|
||||
@@ -28,31 +28,65 @@
|
||||
#include "C:\Users\Jonathan\Documents\exjobb\OpenSpace\shaders\PowerScaling\powerScalingMath.hglsl"
|
||||
|
||||
|
||||
layout(location = 0) in vec4 vertex_data;
|
||||
layout (location = 0) in vec4 vertex_data; // 1: x, 2: y, 3: z, 4: time
|
||||
// This doesn't work, plz help
|
||||
layout (location = 1) in vec2 orbit_data; // 1: epoch, 2: period
|
||||
|
||||
|
||||
uniform dmat4 modelViewTransform;
|
||||
uniform mat4 projectionTransform;
|
||||
|
||||
uniform int numberOfSegments;
|
||||
//uniform int numberOfSegments;
|
||||
uniform float lineFade;
|
||||
uniform vec3 debrisPosition;
|
||||
uniform int* VertexIDs;
|
||||
uniform int numberOfOrbits;
|
||||
//uniform vec3 debrisPosition;
|
||||
//uniform int* VertexIDs;
|
||||
//uniform int numberOfOrbits;
|
||||
uniform /*double*/float inGameTime;
|
||||
|
||||
out vec4 viewSpacePosition;
|
||||
out vec4 vs_position;
|
||||
out float fade;
|
||||
|
||||
void main() {
|
||||
// ta in en vector med vilka index i vertexbufferten som positionen är =.
|
||||
// dela vectorns längd med antalet orbits för att få vilket index i den lilla
|
||||
// vectorn vi ska använda värdet från.
|
||||
|
||||
int vertexID = gl_VertexID;
|
||||
float id = float(vertexID) / float(numberOfSegments);
|
||||
fade = clamp(id * lineFade, 0.0, 1.0);
|
||||
// The error is in line 33 at "location 1"!!
|
||||
|
||||
int orbit = vertexID/numberOfSegments;
|
||||
// calculate nr of periods, get fractional part to know where
|
||||
// the vertex closest to the debris part is right now
|
||||
//float nrOfPeriods = (609590465 - 609590465/4.5) / 9000;
|
||||
float nrOfPeriods = (inGameTime - orbit_data.x) / orbit_data.y;
|
||||
float periodFraction = fract(nrOfPeriods); //mod(nrOfPeriods, 1.0);
|
||||
|
||||
// same procedure for the current vertex
|
||||
//float offsetPeriods = vertex_data.w / 9000;
|
||||
float offsetPeriods = vertex_data.w / orbit_data.y;
|
||||
float offsetFraction = fract(offsetPeriods); //mod(offsetPeriods, 1.0);
|
||||
|
||||
// check difference of these two locations
|
||||
float vertexDistance = periodFraction - offsetFraction;
|
||||
|
||||
if(vertexDistance < 0.0) {
|
||||
vertexDistance += 1.0;
|
||||
}
|
||||
|
||||
|
||||
// int vertexID = gl_VertexID;
|
||||
// float id = float(vertexID) / float(numberOfSegments*numberOfOrbits);
|
||||
|
||||
float test = 1.0 - vertexDistance; // * lineFade;
|
||||
// if (test < 1.0 ) {
|
||||
// test = 0.4;
|
||||
// }
|
||||
// if (test >= 1.0) {
|
||||
// test = 1.0;
|
||||
// }
|
||||
fade = test;
|
||||
|
||||
//fade = clamp( test, 0.0, 1.0);
|
||||
|
||||
//fade = 0.5 * lineFade;
|
||||
|
||||
// int orbit = vertexID/numberOfSegments;
|
||||
// will this iterate or add onto the value in vertexIDs?: VertexIDs = VertexIDs + orbit;
|
||||
// should it be VertexIDs[orbit] - gl_VertexID, OR gl_VertexID - VertexIDs[orbit]:
|
||||
// int offset = VertexIDs[orbit] - gl_VertexID
|
||||
|
||||
@@ -304,7 +304,7 @@ glm::dvec3 KeplerTranslation::position(const UpdateData& data) const {
|
||||
return _orbitPlaneRotation * p;
|
||||
}
|
||||
// !!! is only used in module/space/rendering/renderablesatellites
|
||||
glm::dvec3 KeplerTranslation::debrisPos(const double& time) const {
|
||||
glm::dvec3 KeplerTranslation::debrisPos(const float& time) const {
|
||||
if (_orbitPlaneDirty) {
|
||||
computeOrbitPlane();
|
||||
_orbitPlaneDirty = false;
|
||||
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
glm::dvec3 position(const UpdateData& data) const override;
|
||||
|
||||
// Is only used in renderableDebris so far. May rename if needed
|
||||
glm::dvec3 debrisPos(const double& time) const;
|
||||
glm::dvec3 debrisPos(const float& time) const;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user