mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 20:50:59 -05:00
Merge pull request #1026 from OpenSpace/feature/AALines2
Feature/aa lines2
This commit is contained in:
@@ -38,10 +38,10 @@ namespace {
|
||||
constexpr const char* ProgramName = "EphemerisProgram";
|
||||
constexpr const char* KeyTranslation = "Translation";
|
||||
|
||||
constexpr const std::array<const char*, 12> UniformNames = {
|
||||
constexpr const std::array<const char*, 14> UniformNames = {
|
||||
"opacity", "modelViewTransform", "projectionTransform", "color", "useLineFade",
|
||||
"lineFade", "vertexSortingMethod", "idOffset", "nVertices", "stride", "pointSize",
|
||||
"renderPhase"
|
||||
"renderPhase", "resolution", "lineWidth"
|
||||
};
|
||||
|
||||
// The possible values for the _renderingModes property
|
||||
@@ -178,7 +178,7 @@ RenderableTrail::Appearance::Appearance()
|
||||
, lineColor(LineColorInfo, glm::vec3(1.0f, 1.0f, 0.f), glm::vec3(0.f), glm::vec3(1.f))
|
||||
, useLineFade(EnableFadeInfo, true)
|
||||
, lineFade(FadeInfo, 1.f, 0.f, 30.f)
|
||||
, lineWidth(LineWidthInfo, 2.f, 1.f, 20.f)
|
||||
, lineWidth(LineWidthInfo, 10.f, 1.f, 20.f)
|
||||
, pointSize(PointSizeInfo, 1, 1, 64)
|
||||
, renderingModes(
|
||||
RenderingModeInfo,
|
||||
@@ -294,6 +294,9 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
|
||||
_programObject->setUniform(_uniformCache.lineFade, _appearance.lineFade);
|
||||
}
|
||||
|
||||
/*glm::ivec2 resolution = global::renderEngine.renderingResolution();
|
||||
_programObject->setUniform(_uniformCache.resolution, resolution);*/
|
||||
|
||||
static std::map<RenderInformation::VertexSorting, int> SortingMapping = {
|
||||
// Fragile! Keep in sync with shader
|
||||
{ RenderInformation::VertexSorting::NewestFirst, 0 },
|
||||
@@ -317,15 +320,15 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
|
||||
(_appearance.renderingModes == RenderingModeLinesPoints);
|
||||
|
||||
if (renderLines) {
|
||||
glLineWidth(_appearance.lineWidth);
|
||||
glLineWidth(ceil((2.f * 1.f + _appearance.lineWidth) * std::sqrt(2.f)));
|
||||
}
|
||||
if (renderPoints) {
|
||||
glEnable(GL_PROGRAM_POINT_SIZE);
|
||||
}
|
||||
|
||||
auto render = [renderLines, renderPoints, p = _programObject, &data,
|
||||
&modelTransform, pointSize = _appearance.pointSize.value(),
|
||||
c = _uniformCache]
|
||||
&modelTransform, pointSize = _appearance.pointSize.value(),
|
||||
c = _uniformCache, lw = _appearance.lineWidth]
|
||||
(RenderInformation& info, int nVertices, int offset)
|
||||
{
|
||||
// We pass in the model view transformation matrix as double in order to maintain
|
||||
@@ -346,6 +349,11 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
p->setUniform(c.nVertices, nVertices);
|
||||
|
||||
glm::ivec2 resolution = global::renderEngine.renderingResolution();
|
||||
p->setUniform(c.resolution, resolution);
|
||||
|
||||
p->setUniform(c.lineWidth, ceil((2.f * 1.f + lw) * std::sqrt(2.f)));
|
||||
|
||||
if (renderPoints) {
|
||||
// The stride parameter determines the distance between larger points and
|
||||
// smaller ones
|
||||
@@ -361,8 +369,6 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
|
||||
|
||||
glBindVertexArray(info._vaoID);
|
||||
if (renderLines) {
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||
p->setUniform(c.renderPhase, RenderPhaseLines);
|
||||
// Subclasses of this renderer might be using the index array or might now be
|
||||
// so we check if there is data available and if there isn't, we use the
|
||||
@@ -382,7 +388,6 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
|
||||
reinterpret_cast<void*>(info.first * sizeof(unsigned int))
|
||||
);
|
||||
}
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
}
|
||||
if (renderPoints) {
|
||||
// Subclasses of this renderer might be using the index array or might now be
|
||||
@@ -413,6 +418,24 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
|
||||
0 :
|
||||
_primaryRenderInformation.first;
|
||||
|
||||
// Culling
|
||||
const double scaledRadius = glm::length(
|
||||
glm::dmat3(modelTransform) * glm::dvec3(_boundingSphere, 0.0, 0.0)
|
||||
);
|
||||
|
||||
glm::dvec3 trailPosWorld = glm::dvec3(
|
||||
modelTransform * _primaryRenderInformation._localTransform *
|
||||
glm::dvec4(0.0, 0.0, 0.0, 1.0)
|
||||
);
|
||||
const double distance = glm::distance(
|
||||
trailPosWorld,
|
||||
data.camera.eyePositionVec3()
|
||||
);
|
||||
|
||||
if (distance > scaledRadius * DISTANCE_CULLING_RADII) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Render the primary batch of vertices
|
||||
render(_primaryRenderInformation, totalNumber, primaryOffset);
|
||||
|
||||
|
||||
@@ -72,6 +72,8 @@ class Translation;
|
||||
class RenderableTrail : public Renderable {
|
||||
public:
|
||||
|
||||
const double DISTANCE_CULLING_RADII = 800.0;
|
||||
|
||||
struct Appearance : properties::PropertyOwner {
|
||||
Appearance();
|
||||
/// Specifies the base color of the line before fading
|
||||
@@ -182,7 +184,8 @@ private:
|
||||
ghoul::opengl::ProgramObject* _programObject = nullptr;
|
||||
|
||||
UniformCache(opacity, modelView, projection, color, useLineFade, lineFade,
|
||||
vertexSorting, idOffset, nVertices, stride, pointSize, renderPhase) _uniformCache;
|
||||
vertexSorting, idOffset, nVertices, stride, pointSize, renderPhase,
|
||||
resolution, lineWidth) _uniformCache;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -356,6 +356,24 @@ void RenderableTrailOrbit::update(const UpdateData& data) {
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
// Updating bounding sphere
|
||||
glm::vec3 maxVertex(-std::numeric_limits<float>::max());
|
||||
glm::vec3 minVertex(std::numeric_limits<float>::max());
|
||||
|
||||
auto setMax = [&maxVertex, &minVertex](const TrailVBOLayout& vertexData) {
|
||||
maxVertex.x = std::max(maxVertex.x, vertexData.x);
|
||||
maxVertex.y = std::max(maxVertex.y, vertexData.y);
|
||||
maxVertex.z = std::max(maxVertex.z, vertexData.z);
|
||||
|
||||
minVertex.x = std::min(minVertex.x, vertexData.x);
|
||||
minVertex.y = std::min(minVertex.y, vertexData.y);
|
||||
minVertex.z = std::min(minVertex.z, vertexData.z);
|
||||
};
|
||||
|
||||
std::for_each(_vertexArray.begin(), _vertexArray.end(), setMax);
|
||||
|
||||
setBoundingSphere(glm::distance(maxVertex, minVertex) / 2.0);
|
||||
}
|
||||
|
||||
RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails(
|
||||
|
||||
@@ -24,14 +24,15 @@
|
||||
|
||||
#include "fragment.glsl"
|
||||
|
||||
in vec4 vs_positionScreenSpace;
|
||||
in float vs_positionDepth;
|
||||
in vec4 vs_gPosition;
|
||||
in float fade;
|
||||
in float v_pointSize;
|
||||
noperspective in vec2 mathLine;
|
||||
|
||||
uniform vec3 color;
|
||||
uniform int renderPhase;
|
||||
uniform float opacity = 1.0;
|
||||
uniform float lineWidth;
|
||||
|
||||
// Fragile! Keep in sync with RenderableTrail::render::RenderPhase
|
||||
#define RenderPhaseLines 0
|
||||
@@ -43,7 +44,7 @@ uniform float opacity = 1.0;
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
frag.color = vec4(color * fade, fade * opacity);
|
||||
frag.depth = vs_positionScreenSpace.w;
|
||||
frag.depth = vs_positionDepth;
|
||||
frag.blend = BLEND_MODE_ADDITIVE;
|
||||
|
||||
if (renderPhase == RenderPhasePoints) {
|
||||
@@ -60,6 +61,16 @@ Fragment getFragment() {
|
||||
frag.color.a = transparencyCorrection;
|
||||
}
|
||||
|
||||
double distanceCenter = length(mathLine - vec2(gl_FragCoord.xy));
|
||||
double dLW = double(lineWidth);
|
||||
float blendFactor = 20;
|
||||
|
||||
if (distanceCenter > dLW) {
|
||||
frag.color.a = 0.0;
|
||||
} else {
|
||||
frag.color.a *= pow(float((dLW - distanceCenter) / dLW), blendFactor);
|
||||
}
|
||||
|
||||
frag.gPosition = vs_gPosition;
|
||||
|
||||
// There is no normal here
|
||||
|
||||
@@ -28,10 +28,10 @@
|
||||
|
||||
layout(location = 0) in vec3 in_point_position;
|
||||
|
||||
out vec4 vs_positionScreenSpace;
|
||||
out float vs_positionDepth;
|
||||
out vec4 vs_gPosition;
|
||||
out float fade;
|
||||
out float v_pointSize;
|
||||
noperspective out vec2 mathLine;
|
||||
|
||||
uniform dmat4 modelViewTransform;
|
||||
uniform mat4 projectionTransform;
|
||||
@@ -43,6 +43,8 @@ uniform int vertexSortingMethod;
|
||||
uniform int pointSize;
|
||||
uniform int stride;
|
||||
|
||||
uniform ivec2 resolution;
|
||||
|
||||
// Fragile! Keep in sync with RenderableTrail::render
|
||||
#define VERTEX_SORTING_NEWESTFIRST 0
|
||||
#define VERTEX_SORTING_OLDESTFIRST 1
|
||||
@@ -73,9 +75,13 @@ void main() {
|
||||
}
|
||||
|
||||
vs_gPosition = vec4(modelViewTransform * dvec4(in_point_position, 1));
|
||||
vs_positionScreenSpace = z_normalization(projectionTransform * vs_gPosition);
|
||||
vec4 vs_positionClipSpace = projectionTransform * vs_gPosition;
|
||||
vec4 vs_positionNDC = vs_positionClipSpace / vs_positionClipSpace.w;
|
||||
vs_positionDepth = vs_positionClipSpace.w;
|
||||
|
||||
gl_PointSize = (stride == 1 || int(modId) % stride == 0) ?
|
||||
float(pointSize) : float(pointSize) / 2;
|
||||
gl_Position = z_normalization(vs_positionClipSpace);
|
||||
|
||||
gl_PointSize = (stride == 1 || int(modId) % stride == 0) ? float(pointSize) : float(pointSize) / 2;
|
||||
v_pointSize = gl_PointSize;
|
||||
gl_Position = vs_positionScreenSpace;
|
||||
mathLine = 0.5 * (vs_positionNDC.xy + vec2(1.0)) * vec2(resolution);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user