Star rendering: stereo support + remove psc

This commit is contained in:
Emil Axelsson
2018-02-15 19:04:50 +01:00
parent cb77e2839c
commit 656bd0e89e
5 changed files with 102 additions and 168 deletions

View File

@@ -27,6 +27,7 @@
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/util/updatestructures.h>
#include <openspace/util/distanceconstants.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
@@ -99,25 +100,24 @@ namespace {
"stars."
};
static const openspace::properties::Property::PropertyInfo TransparencyInfo = {
"Transparency",
"Transparency",
"This value is a multiplicative factor that is applied to the transparency of "
"all stars."
static const openspace::properties::Property::PropertyInfo MagnitudeExponentInfo = {
"MagnitudeExponent",
"MagnitudeExponent",
"Adjust star magnitude by 10^MagnitudeExponent. "
"Stars closer than this distance are given full opacity. "
"Farther away, stars dim proportionally to the logarithm of their distance."
};
static const openspace::properties::Property::PropertyInfo ScaleFactorInfo = {
"ScaleFactor",
"Scale Factor",
"This value is used as a multiplicative factor that is applied to the apparent "
"size of each star."
static const openspace::properties::Property::PropertyInfo SharpnessInfo = {
"Sharpness",
"Sharpness",
"Adjust star sharpness"
};
static const openspace::properties::Property::PropertyInfo MinBillboardSizeInfo = {
"MinBillboardSize",
"Min Billboard Size",
"This value is used as a lower limit on the size of stars that are rendered. Any "
"stars that have a smaller apparent size will be discarded entirely."
static const openspace::properties::Property::PropertyInfo BillboardSizeInfo = {
"BillboardSize",
"Billboard Size",
"Set the billboard size of all stars"
};
} // namespace
@@ -162,22 +162,22 @@ documentation::Documentation RenderableStars::Documentation() {
ColorOptionInfo.description
},
{
TransparencyInfo.identifier,
MagnitudeExponentInfo.identifier,
new DoubleVerifier,
Optional::Yes,
TransparencyInfo.description
MagnitudeExponentInfo.description
},
{
ScaleFactorInfo.identifier,
SharpnessInfo.identifier,
new DoubleVerifier,
Optional::Yes,
ScaleFactorInfo.description
SharpnessInfo.description
},
{
MinBillboardSizeInfo.identifier,
BillboardSizeInfo.identifier,
new DoubleVerifier,
Optional::Yes,
MinBillboardSizeInfo.description
BillboardSizeInfo.description
}
}
};
@@ -193,9 +193,9 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
, _colorTextureIsDirty(true)
, _colorOption(ColorOptionInfo, properties::OptionProperty::DisplayType::Dropdown)
, _dataIsDirty(true)
, _alphaValue(TransparencyInfo, 1.f, 0.f, 1.f)
, _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 10.f)
, _minBillboardSize(MinBillboardSizeInfo, 1.f, 1.f, 100.f)
, _magnitudeExponent(MagnitudeExponentInfo, 19.f, 0.f, 30.f)
, _sharpness(SharpnessInfo, 1.f, 0.f, 5.f)
, _billboardSize(BillboardSizeInfo, 30.f, 1.f, 100.f)
, _program(nullptr)
, _speckFile("")
, _nValuesPerStar(0)
@@ -258,26 +258,26 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
);
addProperty(_colorTexturePath);
if (dictionary.hasKey(TransparencyInfo.identifier)) {
_alphaValue = static_cast<float>(
dictionary.value<double>(TransparencyInfo.identifier)
if (dictionary.hasKey(MagnitudeExponentInfo.identifier)) {
_magnitudeExponent = static_cast<float>(
dictionary.value<double>(MagnitudeExponentInfo.identifier)
);
}
addProperty(_alphaValue);
addProperty(_magnitudeExponent);
if (dictionary.hasKey(ScaleFactorInfo.identifier)) {
_scaleFactor = static_cast<float>(
dictionary.value<double>(ScaleFactorInfo.identifier)
);
if (dictionary.hasKey(SharpnessInfo.identifier)) {
_sharpness = static_cast<float>(
dictionary.value<double>(SharpnessInfo.identifier)
);
}
addProperty(_scaleFactor);
addProperty(_sharpness);
if (dictionary.hasKey(MinBillboardSizeInfo.identifier)) {
_minBillboardSize = static_cast<float>(
dictionary.value<double>(MinBillboardSizeInfo.identifier)
if (dictionary.hasKey(BillboardSizeInfo.identifier)) {
_billboardSize = static_cast<float>(
dictionary.value<double>(BillboardSizeInfo.identifier)
);
}
addProperty(_minBillboardSize);
addProperty(_billboardSize);
}
RenderableStars::~RenderableStars() {}
@@ -294,14 +294,15 @@ void RenderableStars::initializeGL() {
absPath("${MODULE_SPACE}/shaders/star_ge.glsl")
);
_uniformCache.model = _program->uniformLocation("model");
_uniformCache.view = _program->uniformLocation("view");
_uniformCache.viewScaling = _program->uniformLocation("viewScaling");
_uniformCache.projection = _program->uniformLocation("projection");
_uniformCache.colorOption = _program->uniformLocation("colorOption");
_uniformCache.alphaValue = _program->uniformLocation("alphaValue");
_uniformCache.scaleFactor = _program->uniformLocation("scaleFactor");
_uniformCache.minBillboardSize = _program->uniformLocation("minBillboardSize");
_uniformCache.magnitudeExponent = _program->uniformLocation("magnitudeExponent");
_uniformCache.sharpness = _program->uniformLocation("sharpness");
_uniformCache.billboardSize = _program->uniformLocation("billboardSize");
_uniformCache.screenSize = _program->uniformLocation("screenSize");
_uniformCache.scaling = _program->uniformLocation("scaling");
_uniformCache.psfTexture = _program->uniformLocation("psfTexture");
_uniformCache.colorTexture = _program->uniformLocation("colorTexture");
@@ -331,25 +332,29 @@ void RenderableStars::render(const RenderData& data, RendererTasks&) {
glDepthMask(false);
_program->activate();
// @Check overwriting the scaling from the camera; error as parsec->meter conversion
// is done twice? ---abock
glm::vec2 scaling = glm::vec2(1, -19);
glm::mat4 model =
glm::translate(glm::dmat4(1.0), data.modelTransform.translation) *
glm::dmat4(data.modelTransform.rotation) *
glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)));
_program->setUniform(_uniformCache.view, data.camera.viewMatrix());
_program->setUniform(_uniformCache.projection, data.camera.projectionMatrix());
glm::mat4 view = data.camera.combinedViewMatrix();
glm::mat4 projection = data.camera.projectionMatrix();
float viewScaling = data.camera.scaling();
_program->setUniform(_uniformCache.model, model);
_program->setUniform(_uniformCache.view, view);
_program->setUniform(_uniformCache.projection, projection);
_program->setUniform(_uniformCache.viewScaling, viewScaling);
_program->setUniform(_uniformCache.colorOption, _colorOption);
_program->setUniform(_uniformCache.alphaValue, _alphaValue);
_program->setUniform(_uniformCache.scaleFactor, _scaleFactor);
_program->setUniform(_uniformCache.minBillboardSize, _minBillboardSize);
_program->setUniform(_uniformCache.magnitudeExponent, _magnitudeExponent);
_program->setUniform(_uniformCache.sharpness, _sharpness);
_program->setUniform(_uniformCache.billboardSize, _billboardSize);
_program->setUniform(
_uniformCache.screenSize,
glm::vec2(OsEng.renderEngine().renderingResolution())
);
setPscUniforms(*_program.get(), data.camera, data.position);
_program->setUniform(_uniformCache.scaling, scaling);
ghoul::opengl::TextureUnit psfUnit;
psfUnit.activate();
_pointSpreadFunctionTexture->bind();
@@ -552,14 +557,15 @@ void RenderableStars::update(const UpdateData&) {
if (_program->isDirty()) {
_program->rebuildFromFile();
_uniformCache.model = _program->uniformLocation("model");
_uniformCache.view = _program->uniformLocation("view");
_uniformCache.viewScaling = _program->uniformLocation("viewScaling");
_uniformCache.projection = _program->uniformLocation("projection");
_uniformCache.colorOption = _program->uniformLocation("colorOption");
_uniformCache.alphaValue = _program->uniformLocation("alphaValue");
_uniformCache.scaleFactor = _program->uniformLocation("scaleFactor");
_uniformCache.minBillboardSize = _program->uniformLocation("minBillboardSize");
_uniformCache.magnitudeExponent = _program->uniformLocation("magnitudeExponent");
_uniformCache.sharpness = _program->uniformLocation("sharpness");
_uniformCache.billboardSize = _program->uniformLocation("billboardSize");
_uniformCache.screenSize = _program->uniformLocation("screenSize");
_uniformCache.scaling = _program->uniformLocation("scaling");
_uniformCache.psfTexture = _program->uniformLocation("psfTexture");
_uniformCache.colorTexture = _program->uniformLocation("colorTexture");
}
@@ -735,51 +741,20 @@ bool RenderableStars::saveCachedFile(const std::string& file) const {
void RenderableStars::createDataSlice(ColorOption option) {
_slicedData.clear();
// This is only temporary until the scalegraph is in place ---abock
float minDistance = std::numeric_limits<float>::max();
float maxDistance = -std::numeric_limits<float>::max();
for (size_t i = 0; i < _fullData.size(); i+=_nValuesPerStar) {
float distLy = _fullData[i + 6];
//if (distLy < 20.f) {
minDistance = std::min(minDistance, distLy);
maxDistance = std::max(maxDistance, distLy);
//}
}
for (size_t i = 0; i < _fullData.size(); i+=_nValuesPerStar) {
glm::vec3 p = glm::vec3(_fullData[i + 0], _fullData[i + 1], _fullData[i + 2]);
// This is only temporary until the scalegraph is in place. It places all stars
// on a sphere with a small variation in the distance to account for blending
// issues ---abock
//if (p != glm::vec3(0.f))
// p = glm::normalize(p);
//float distLy = _fullData[i + 6];
//float normalizedDist = (distLy - minDistance) / (maxDistance - minDistance);
//float distance = 18.f - normalizedDist / 1.f ;
//psc position = psc(glm::vec4(p, distance));
// Convert parsecs -> meter
psc position = psc(glm::vec4(p * 0.308567756f, 17));
//position[1] *= parsecsToMetersFactor[0];
//position[2] *= parsecsToMetersFactor[0];
//position[3] += parsecsToMetersFactor[1];
p *= openspace::distanceconstants::Parsec;
switch (option) {
case ColorOption::Color:
{
union {
ColorVBOLayout value;
std::array<float, sizeof(ColorVBOLayout)> data;
std::array<float, sizeof(ColorVBOLayout) / sizeof(float)> data;
} layout;
layout.value.position = { {
position[0], position[1], position[2], position[3]
p[0], p[1], p[2], 1.0
} };
#ifdef USING_STELLAR_TEST_GRID
@@ -802,11 +777,11 @@ void RenderableStars::createDataSlice(ColorOption option) {
{
union {
VelocityVBOLayout value;
std::array<float, sizeof(VelocityVBOLayout)> data;
std::array<float, sizeof(VelocityVBOLayout) / sizeof(float)> data;
} layout;
layout.value.position = { {
position[0], position[1], position[2], position[3]
p[0], p[1], p[2], 1.0
} };
layout.value.bvColor = _fullData[i + 3];
@@ -826,11 +801,11 @@ void RenderableStars::createDataSlice(ColorOption option) {
{
union {
SpeedVBOLayout value;
std::array<float, sizeof(SpeedVBOLayout)> data;
std::array<float, sizeof(SpeedVBOLayout) / sizeof(float)> data;
} layout;
layout.value.position = { {
position[0], position[1], position[2], position[3]
p[0], p[1], p[2], 1.0
} };
layout.value.bvColor = _fullData[i + 3];

View File

@@ -86,13 +86,13 @@ private:
properties::OptionProperty _colorOption;
bool _dataIsDirty;
properties::FloatProperty _alphaValue;
properties::FloatProperty _scaleFactor;
properties::FloatProperty _minBillboardSize;
properties::FloatProperty _magnitudeExponent;
properties::FloatProperty _sharpness;
properties::FloatProperty _billboardSize;
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
UniformCache(view, projection, colorOption, alphaValue, scaleFactor,
minBillboardSize, screenSize, scaling, psfTexture, colorTexture) _uniformCache;
UniformCache(model, view, viewScaling, projection, colorOption, magnitudeExponent, sharpness,
billboardSize, screenSize, scaling, psfTexture, colorTexture) _uniformCache;
std::string _speckFile;

View File

@@ -23,7 +23,7 @@
****************************************************************************************/
#include "fragment.glsl"
#include "PowerScaling/powerScaling_fs.hglsl"
#include "floatoperations.glsl"
// keep in sync with renderablestars.h:ColorOption enum
const int COLOROPTION_COLOR = 0;
@@ -32,9 +32,9 @@ const int COLOROPTION_SPEED = 2;
uniform sampler2D psfTexture;
uniform sampler1D colorTexture;
uniform float minBillboardSize;
uniform float alphaValue;
uniform float magnitudeExponent;
uniform float sharpness;
uniform int colorOption;
in vec4 vs_position;
@@ -43,13 +43,7 @@ in vec3 ge_brightness;
in vec3 ge_velocity;
in float ge_speed;
in vec2 texCoord;
in float billboardSize;
#include "fragment.glsl"
//#include "PowerScaling/powerScaling_fs.hglsl"
uniform vec2 magnitudeClamp;
in float ge_observationDistance;
vec4 bv2rgb(float bv) {
// BV is [-0.4,2.0]
@@ -60,7 +54,7 @@ vec4 bv2rgb(float bv) {
Fragment getFragment() {
// Something in the color calculations need to be changed because before it was dependent
// on the gl blend functions since the abuffer was not involved
vec4 color = vec4(0.0);
switch (colorOption) {
case COLOROPTION_COLOR:
@@ -77,19 +71,15 @@ Fragment getFragment() {
vec4 textureColor = texture(psfTexture, texCoord);
vec4 fullColor = vec4(color.rgb, textureColor.a);
fullColor.a *= alphaValue;
fullColor.a = pow(fullColor.a, sharpness);
vec4 position = vs_position;
// This has to be fixed when the scale graph is in place ---emiax
position.w = 15;
float d = magnitudeExponent - log(ge_observationDistance) / log(10.0);
fullColor.a *= clamp(d, 0.0, 1.0);
Fragment frag;
frag.color = fullColor;
frag.depth = pscDepth(position);
// G-Buffer
frag.depth = safeLength(vs_position);
frag.gPosition = ge_gPosition;
// There is no normal here
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
if (fullColor.a == 0) {

View File

@@ -24,15 +24,14 @@
#version __CONTEXT__
#include "PowerScaling/powerScalingMath.hglsl"
#include "floatoperations.glsl"
layout(points) in;
in vec4 psc_position[];
in vec3 vs_brightness[];
in vec3 vs_velocity[];
in vec4 vs_gPosition[];
in float vs_speed[];
in vec4 cam_position[];
layout(triangle_strip, max_vertices = 4) out;
@@ -42,12 +41,11 @@ out vec3 ge_brightness;
out vec3 ge_velocity;
out float ge_speed;
out vec2 texCoord;
out float billboardSize;
uniform mat4 projection;
out float ge_observationDistance;
uniform float viewScaling;
uniform float scaleFactor;
uniform float minBillboardSize;
uniform float billboardSize;
uniform vec2 screenSize;
const vec2 corners[4] = vec2[4](
@@ -57,50 +55,27 @@ const vec2 corners[4] = vec2[4](
vec2(1.0, 0.0)
);
void main() {
// JCC: We want to display the Sun.
// if ((psc_position[0].x == 0.0) &&
// (psc_position[0].y == 0.0) &&
// (psc_position[0].z == 0.0))
// {
// return;
// }
ge_brightness = vs_brightness[0];
ge_velocity = vs_velocity[0];
ge_speed = vs_speed[0];
float absoluteMagnitude = vs_brightness[0].z;
float modifiedSpriteSize =
exp((-30.623 - absoluteMagnitude) * 0.462) * scaleFactor * 2000;
vec4 projPos[4];
for (int i = 0; i < 4; ++i) {
vec4 p1 = gl_in[0].gl_Position;
p1.xy += vec2(modifiedSpriteSize * (corners[i] - vec2(0.5)));
projPos[i] = projection * p1;
}
// Calculate the positions of the lower left and upper right corners of the
// billboard in screen-space
vec2 ll = (((projPos[1].xy / projPos[1].w) + 1.0) / 2.0) * screenSize;
vec2 ur = (((projPos[2].xy / projPos[2].w) + 1.0) / 2.0) * screenSize;
// The billboard is smaller than one pixel, we can discard it
float sizeInPixels = length(ll - ur);
if (sizeInPixels < minBillboardSize) {
return;
}
vec4 projectedPoint = gl_in[0].gl_Position;
vec2 starSize = vec2(billboardSize) / screenSize * projectedPoint.w;
for (int i = 0; i < 4; i++) {
vs_position = gl_in[0].gl_Position;
gl_Position = projPos[i];
gl_Position = projectedPoint + vec4(starSize * (corners[i] - 0.5), 0.0, 0.0);
gl_Position.z = 0.0;
texCoord = corners[i];
// G-Buffer
ge_gPosition = vs_gPosition[0];
billboardSize = sizeInPixels;
ge_observationDistance = safeLength(vs_gPosition[0] / viewScaling);
EmitVertex();
}

View File

@@ -31,30 +31,24 @@ in vec3 in_brightness;
in vec3 in_velocity;
in float in_speed;
out vec4 psc_position;
out vec3 vs_brightness;
out vec3 vs_velocity;
out float vs_speed;
out vec4 vs_gPosition;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main() {
vec4 p = in_position;
psc_position = p;
vs_brightness = in_brightness;
vs_velocity = in_velocity;
vs_speed = in_speed;
vec4 tmp = p;
vec4 position = pscTransform(tmp, mat4(1.0));
// G-Buffer
vs_gPosition = view * (vec4(1E19, 1E19, 1E19, 1.0) * position);
position = view * position;
gl_Position = position;
vec3 modelPosition = in_position.xyz;
vec4 viewPosition = view * model * vec4(modelPosition, 1.0);
vs_gPosition = viewPosition;
gl_Position = projection * vs_gPosition;
}