RenderableOrbitalKepler trail fix

This commit is contained in:
Arohdin
2025-09-08 14:51:31 +02:00
parent c7861c6106
commit 9494f2d1a1
4 changed files with 17 additions and 19 deletions

View File

@@ -687,11 +687,10 @@ void RenderableOrbitalKepler::updateBuffers() {
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, sizeof(TrailVBOLayout), nullptr);
glEnableVertexAttribArray(1);
glVertexAttribPointer(
glVertexAttribLPointer(
1,
2,
GL_DOUBLE,
GL_FALSE,
sizeof(TrailVBOLayout),
reinterpret_cast<GLvoid*>(4 * sizeof(GL_FLOAT))
);
@@ -713,8 +712,8 @@ void RenderableOrbitalKepler::calculateSegmentsForPoints(const RenderData& data)
// Check how far along the trail we are
const kepler::Parameters& orbit = _parameters[i];
const double nRevs = (data.time.j2000Seconds() - orbit.epoch) / orbit.period;
double frac = nRevs - std::trunc(nRevs);
frac += (frac < 0.0) ? 1.0: 0.0;
float frac = static_cast<float>(nRevs - std::trunc(nRevs));
frac += (frac < 0.f) ? 1.f: 0.f;
// Get the closest vertex before that point
const int nSegments = _segmentSizeRaw[i] - 1;
@@ -739,8 +738,8 @@ void RenderableOrbitalKepler::calculateSegmentsForTrails(const RenderData& data)
// Check how far along the trail we are
const kepler::Parameters& orbit = _parameters[i];
const double nRevs = (data.time.j2000Seconds() - orbit.epoch) / orbit.period;
double frac = nRevs - std::trunc(nRevs);
frac += (frac < 0.0) ? 1.0 : 0.0;
float frac = static_cast<float>(nRevs - std::trunc(nRevs));
frac += (frac < 0.f) ? 1.f : 0.f;
int p0Start = 0;
int p0Length = 0;

View File

@@ -54,8 +54,8 @@ void main() {
float v1Frac = vertexRevolutionFraction[1];
// Interpolate position of current position of the trail head
float dFrac = abs(cFrac - v0Frac);
float vFrac = abs(v1Frac - v0Frac);
float dFrac = cFrac - v0Frac;
float vFrac = v1Frac - v0Frac;
float percentage = dFrac / vFrac;
vec4 v0Weighted = (1.0 - percentage) * gl_in[0].gl_Position;

View File

@@ -25,7 +25,7 @@
#version __CONTEXT__
layout (location = 0) in vec4 vertexData; // 1: x, 2: y, 3: z, 4: timeOffset,
layout (location = 1) in vec2 orbitData; // 1: epoch, 2: period
layout (location = 1) in dvec2 orbitData; // 1: epoch, 2: period
uniform double inGameTime;
@@ -33,8 +33,8 @@ flat out float currentRevolutionFraction;
flat out float vertexRevolutionFraction;
void main() {
float epoch = orbitData.x;
float period = orbitData.y;
double epoch = orbitData.x;
double period = orbitData.y;
// calculate nr of periods, get fractional part to know where the vertex closest to the
// debris part is right now
@@ -45,7 +45,7 @@ void main() {
}
// Same procedure for the current vertex
vertexRevolutionFraction = vertexData.w / period;
vertexRevolutionFraction = float(vertexData.w / period);
gl_Position = vec4(vertexData.xyz, 1.0);
}

View File

@@ -27,7 +27,7 @@
#include "PowerScaling/powerScalingMath.hglsl"
layout (location = 0) in vec4 vertexData; // 1: x, 2: y, 3: z, 4: timeOffset,
layout (location = 1) in vec2 orbitData; // 1: epoch, 2: period
layout (location = 1) in dvec2 orbitData; // 1: epoch, 2: period
out vec4 viewSpacePosition;
out float viewSpaceDepth;
@@ -48,18 +48,17 @@ void main() {
// offsetPeriods is calculated to know how much to fade that specific fragment.
// If orbit_data is doubles, cast to float first
float epoch = orbitData.x;
float period = orbitData.y;
double epoch = orbitData.x;
double period = orbitData.y;
// Calculate nr of periods, get fractional part to know where the vertex closest to the
// debris part is right now
double nrOfRevolutions = (inGameTime - epoch) / period;
double frac = double(int(nrOfRevolutions));
double periodFractiond = nrOfRevolutions - frac;
if (periodFractiond < 0.0) {
periodFractiond += 1.0;
periodFraction = float(nrOfRevolutions - frac);
if (periodFraction < 0.0) {
periodFraction += 1.0;
}
periodFraction = float(periodFractiond);
// Same procedure for the current vertex
offsetPeriods = vertexData.w / float(period);