Copied changes from previous branch and added new size control system.

This commit is contained in:
Jonathas Costa
2018-04-21 15:17:41 -04:00
parent f7e5ba8fff
commit fc71ad1a83
5 changed files with 1506 additions and 1514 deletions
File diff suppressed because it is too large Load Diff
@@ -1,26 +1,26 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#ifndef __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEBILLBOARDSCLOUD___H__
#define __OPENSPACE_MODULE_DIGITALUNIVERSE___RENDERABLEBILLBOARDSCLOUD___H__
@@ -51,132 +51,134 @@ namespace ghoul::opengl {
namespace openspace {
namespace documentation { struct Documentation; }
namespace documentation { struct Documentation; }
class RenderableBillboardsCloud : public Renderable {
public:
explicit RenderableBillboardsCloud(const ghoul::Dictionary& dictionary);
~RenderableBillboardsCloud() = default;
class RenderableBillboardsCloud : public Renderable {
public:
explicit RenderableBillboardsCloud(const ghoul::Dictionary& dictionary);
~RenderableBillboardsCloud() = default;
void initialize() override;
void initializeGL() override;
void deinitializeGL() override;
void initialize() override;
void initializeGL() override;
void deinitializeGL() override;
bool isReady() const override;
bool isReady() const override;
void render(const RenderData& data, RendererTasks& rendererTask) override;
void update(const UpdateData& data) override;
void render(const RenderData& data, RendererTasks& rendererTask) override;
void update(const UpdateData& data) override;
static documentation::Documentation Documentation();
static documentation::Documentation Documentation();
private:
private:
enum Unit {
Meter = 0,
Kilometer = 1,
Parsec = 2,
Kiloparsec = 3,
Megaparsec = 4,
Gigaparsec = 5,
enum Unit {
Meter = 0,
Kilometer = 1,
Parsec = 2,
Kiloparsec = 3,
Megaparsec = 4,
Gigaparsec = 5,
GigalightYears = 6
GigalightYears = 6
};
void createDataSlice();
void createPolygonTexture();
void renderToTexture(std::function<void(void)> geometryLoadingFunction,
std::function<void(GLuint)> renderFunction,
GLuint textureToRenderTo, GLuint textureWidth, GLuint textureHeight);
void loadPolygonGeometryForRendering();
void renderPolygonGeometry(GLuint vao);
void renderBillboards(const RenderData& data, const glm::dmat4& modelMatrix,
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable);
void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable);
bool loadData();
bool loadSpeckData();
bool loadLabelData();
bool readSpeckFile();
bool readColorMapFile();
bool readLabelFile();
bool loadCachedFile(const std::string& file);
bool saveCachedFile(const std::string& file) const;
bool _hasSpeckFile;
bool _dataIsDirty;
bool _textColorIsDirty;
bool _hasSpriteTexture;
bool _spriteTextureIsDirty;
bool _hasColorMapFile;
bool _hasPolygon;
bool _hasLabel;
bool _labelDataIsDirty;
int _polygonSides;
GLuint _pTexture;
properties::FloatProperty _alphaValue;
properties::FloatProperty _scaleFactor;
properties::Vec3Property _pointColor;
properties::StringProperty _spriteTexturePath;
properties::Vec4Property _textColor;
properties::FloatProperty _textSize;
properties::FloatProperty _textMinSize;
properties::FloatProperty _textMaxSize;
properties::BoolProperty _drawElements;
properties::BoolProperty _drawLabels;
properties::OptionProperty _colorOption;
properties::Vec2Property _fadeInDistance;
properties::BoolProperty _disableFadeInDistance;
properties::FloatProperty _billboardMaxSize;
properties::FloatProperty _billboardMinSize;
properties::FloatProperty _correctionSizeEndDistance;
properties::FloatProperty _correctionSizeFactor;
// DEBUG:
properties::OptionProperty _renderOption;
std::unique_ptr<ghoul::opengl::Texture> _polygonTexture;
std::unique_ptr<ghoul::opengl::Texture> _spriteTexture;
std::unique_ptr<ghoul::filesystem::File> _spriteTextureFile;
//std::unique_ptr<ghoul::opengl::ProgramObject> _program;
ghoul::opengl::ProgramObject* _program;
ghoul::opengl::ProgramObject* _renderToPolygonProgram;
UniformCache(modelViewMatrix, projectionMatrix, cameraViewProjectionMatrix,
modelMatrix, cameraPos, cameraLookup, renderOption,
minBillboardSize, maxBillboardSize, color, sides, alphaValue,
scaleFactor, up, right, fadeInValue, screenSize,
spriteTexture, polygonTexture, hasPolygon, hasColormap) _uniformCache;
std::shared_ptr<ghoul::fontrendering::Font> _font;
std::string _speckFile;
std::string _colorMapFile;
std::string _labelFile;
std::string _colorOptionString;
Unit _unit;
std::vector<float> _slicedData;
std::vector<float> _fullData;
std::vector<glm::vec4> _colorMapData;
std::vector<std::pair<glm::vec3, std::string>> _labelData;
std::unordered_map<std::string, int> _variableDataPositionMap;
std::unordered_map<int, std::string> _optionConversionMap;
std::vector<glm::vec2> _colorRangeData;
int _nValuesPerAstronomicalObject;
glm::dmat4 _transformationMatrix;
GLuint _vao;
GLuint _vbo;
// For polygons
GLuint _polygonVao;
GLuint _polygonVbo;
};
void createDataSlice();
void createPolygonTexture();
void renderToTexture(std::function<void(void)> geometryLoadingFunction,
std::function<void(GLuint)> renderFunction,
GLuint textureToRenderTo, GLuint textureWidth, GLuint textureHeight);
void loadPolygonGeometryForRendering();
void renderPolygonGeometry(GLuint vao);
void renderBillboards(const RenderData& data, const glm::dmat4& modelViewMatrix,
const glm::dmat4& worldToModelTransform, const glm::dvec3& orthoRight,
const glm::dvec3& orthoUp, float fadeInVariable);
void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix,
const glm::dvec3& orthoRight, const glm::dvec3& orthoUp, float fadeInVariable);
bool loadData();
bool loadSpeckData();
bool loadLabelData();
bool readSpeckFile();
bool readColorMapFile();
bool readLabelFile();
bool loadCachedFile(const std::string& file);
bool saveCachedFile(const std::string& file) const;
bool _hasSpeckFile;
bool _dataIsDirty;
bool _textColorIsDirty;
bool _hasSpriteTexture;
bool _spriteTextureIsDirty;
bool _hasColorMapFile;
bool _hasPolygon;
bool _hasLabel;
bool _labelDataIsDirty;
int _polygonSides;
GLuint _pTexture;
properties::FloatProperty _alphaValue;
properties::FloatProperty _scaleFactor;
properties::Vec3Property _pointColor;
properties::StringProperty _spriteTexturePath;
properties::Vec4Property _textColor;
properties::FloatProperty _textSize;
properties::FloatProperty _textMinSize;
properties::FloatProperty _textMaxSize;
properties::BoolProperty _drawElements;
properties::BoolProperty _drawLabels;
properties::OptionProperty _colorOption;
properties::Vec2Property _fadeInDistance;
properties::BoolProperty _disableFadeInDistance;
properties::FloatProperty _billboardMaxSize;
properties::FloatProperty _billboardMinSize;
// DEBUG:
properties::OptionProperty _renderOption;
std::unique_ptr<ghoul::opengl::Texture> _polygonTexture;
std::unique_ptr<ghoul::opengl::Texture> _spriteTexture;
std::unique_ptr<ghoul::filesystem::File> _spriteTextureFile;
ghoul::opengl::ProgramObject* _program;
ghoul::opengl::ProgramObject* _renderToPolygonProgram;
UniformCache(modelViewProjection, cameraPos, cameraLookup,
renderOption, centerSceenInWorldPos, minBillboardSize, maxBillboardSize,
color, sides, alphaValue, scaleFactor, up, right, fadeInValue, screenSize,
spriteTexture, polygonTexture, hasPolygon, hasColormap) _uniformCache;
std::shared_ptr<ghoul::fontrendering::Font> _font;
std::string _speckFile;
std::string _colorMapFile;
std::string _labelFile;
std::string _colorOptionString;
Unit _unit;
std::vector<float> _slicedData;
std::vector<float> _fullData;
std::vector<glm::vec4> _colorMapData;
std::vector<std::pair<glm::vec3, std::string>> _labelData;
std::unordered_map<std::string, int> _variableDataPositionMap;
std::unordered_map<int, std::string> _optionConversionMap;
std::vector<glm::vec2> _colorRangeData;
int _nValuesPerAstronomicalObject;
glm::dmat4 _transformationMatrix;
GLuint _vao;
GLuint _vbo;
// For polygons
GLuint _polygonVao;
GLuint _polygonVbo;
};
} // namespace openspace
@@ -53,17 +53,18 @@ Fragment getFragment() {
}
fullColor.a *= fadeInValue * ta;
if (fullColor.a == 0.f) {
if (fullColor.a == 0.f ||
fullColor.rgb == vec3(0.0)) {
discard;
}
Fragment frag;
frag.color = fullColor;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vec4(1e32, 1e32, 1e32, 1.0);
frag.gPosition = vec4(-1e32, -1e32, -1e32, 1.0);
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
return frag;
}
}
+85 -102
View File
@@ -27,21 +27,26 @@
#include "PowerScaling/powerScalingMath.hglsl"
layout(points) in;
layout(triangle_strip, max_vertices = 6) out;
layout(triangle_strip, max_vertices = 4) out;
//uniform dmat4 transformMatrix;
uniform dmat4 modelViewProjectionTransform;
uniform float scaleFactor;
uniform dvec3 up;
uniform dvec3 up;
uniform dvec3 right;
uniform dvec3 cameraPosition;
uniform dvec3 cameraLookUp;
uniform dvec4 centerScreenInWorldPosition;
uniform dvec3 cameraPosition; // in world space (no SGCT View was considered)
uniform dvec3 cameraLookUp; // in world space (no SGCT View was considered)
uniform int renderOption;
uniform vec2 screenSize;
uniform float maxBillboardSize;
uniform float minBillboardSize;
uniform dmat4 modelViewMatrix;
uniform dmat4 projectionMatrix;
uniform dmat4 cameraViewProjectionMatrix;
uniform dmat4 modelMatrix;
uniform float correctionSizeFactor;
uniform float correctionSizeEndDistance;
in vec4 colorMap[];
out vec4 gs_colorMap;
@@ -60,30 +65,9 @@ const vec2 corners[4] = vec2[4](
void main() {
ta = 1.0f;
vec4 pos = gl_in[0].gl_Position;
ta = 1.0f;
vec4 pos = gl_in[0].gl_Position; // in object space
gs_colorMap = colorMap[0];
double scaleMultiply = exp(scaleFactor/10);
dvec3 scaledRight = dvec3(0.0);
dvec3 scaledUp = dvec3(0.0);
if (renderOption == 0) {
scaledRight = scaleMultiply * right/2.0f;
scaledUp = scaleMultiply * up/2.0f;
} else if (renderOption == 1) {
dvec3 normal = normalize(cameraPosition - dvec3(pos.xyz));
dvec3 newRight = normalize(cross(cameraLookUp, normal));
dvec3 newUp = cross(normal, newRight);
scaledRight = scaleMultiply * newRight/2.0f;
scaledUp = scaleMultiply * newUp/2.0f;
} else if (renderOption == 2) {
dvec3 normal = normalize(centerScreenInWorldPosition.xyz - dvec3(pos.xyz));
dvec3 newRight = normalize(cross(cameraLookUp, normal));
dvec3 newUp = cross(normal, newRight);
scaledRight = scaleMultiply * newRight/2.0f;
scaledUp = scaleMultiply * newUp/2.0f;
}
double unit = PARSEC;
@@ -101,91 +85,90 @@ void main() {
} else if (pos.w == 6.f) {
unit = 306391534.73091 * PARSEC;
}
//dvec4 dpos = transformMatrix * dvec4(dvec3(pos.xyz) * unit, 1.0);
dvec4 dpos = dvec4(dvec3(pos.xyz) * unit, 1.0);
// texCoord = corners[0];
vec4 initialPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w)));
vs_screenSpaceDepth = initialPosition.w;
dvec4 dpos = dvec4(dvec3(pos.xyz) * unit, 1.0);
dpos = modelMatrix * dpos;
double scaleMultiply = exp(scaleFactor * 0.10);
dvec3 scaledRight = dvec3(0.0);
dvec3 scaledUp = dvec3(0.0);
vec4 initialPosition, secondPosition, thirdPosition, crossCorner;
if (renderOption == 0) {
scaledRight = scaleMultiply * right * 0.5f;
scaledUp = scaleMultiply * up * 0.5f;
} else if (renderOption == 1) {
dvec3 normal = normalize(cameraPosition - dpos.xyz);
dvec3 newRight = normalize(cross(cameraLookUp, normal));
dvec3 newUp = cross(normal, newRight);
double distCamera = length(cameraPosition - dpos.xyz);
float expVar = float(-distCamera) / pow(10.f, correctionSizeEndDistance);
double factorVar = double(pow(10, correctionSizeFactor));
scaleMultiply *= 1.0 / (1.0 + factorVar * double(exp(expVar)));
scaledRight = scaleMultiply * newRight * 0.5f;
scaledUp = scaleMultiply * newUp * 0.5f;
}
// texCoord = corners[1];
vec4 secondPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledRight - scaledUp, dpos.w)));
//texCoord = corners[2];
vec4 crossCorner = z_normalization(vec4(modelViewProjectionTransform *
initialPosition = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w)));
vs_screenSpaceDepth = initialPosition.w;
crossCorner = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz + scaledUp + scaledRight, dpos.w)));
// texCoord = corners[3];
vec4 thirdPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp - scaledRight, dpos.w)));
// Testing size for rectangular viewport:
vec2 halfViewSize = vec2(screenSize.x, screenSize.y) * 0.5f;
vec2 topRight = crossCorner.xy/crossCorner.w;
vec2 bottomLeft = initialPosition.xy/initialPosition.w;
// Testing size:
vec4 topRight = secondPosition/secondPosition.w;
topRight = ((topRight + vec4(1.0)) / vec4(2.0)) * vec4(screenSize.x, screenSize.y, 1.0, 1.0);
vec4 bottomLeft = initialPosition/initialPosition.w;
bottomLeft = ((bottomLeft + vec4(1.0)) / vec4(2.0)) * vec4(screenSize.x, screenSize.y, 1.0, 1.0);
// width and height
vec2 sizes = abs(halfViewSize * (topRight - bottomLeft));
bool rectangularViewPort = false;
if (rectangularViewPort && ((sizes.y > maxBillboardSize) ||
(sizes.x > maxBillboardSize))) {
//Set maximum size as Carter's instructions
float correctionScale = sizes.y > maxBillboardSize ? maxBillboardSize / sizes.y :
maxBillboardSize / sizes.x;
scaledRight *= correctionScale;
scaledUp *= correctionScale;
} else {
if (sizes.x < 2.0f * minBillboardSize) {
float maxVar = 2.0f * minBillboardSize;
float minVar = minBillboardSize;
float var = (sizes.y + sizes.x);
ta = ( (var - minVar)/(maxVar - minVar) );
if (ta == 0.0f)
return;
}
}
float height = abs(topRight.y - bottomLeft.y);
float width = abs(topRight.x - bottomLeft.x);
float var = (height + width);
if ((height > maxBillboardSize) ||
(width > maxBillboardSize)) {
// Set maximum size as Carter's instructions
float correctionScale = height > maxBillboardSize ? maxBillboardSize / (topRight.y - bottomLeft.y) :
maxBillboardSize / (topRight.x - bottomLeft.x);
scaledRight = correctionScale * scaleMultiply * right/2.0f;
scaledUp = correctionScale * scaleMultiply * up/2.0f;
initialPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w)));
vs_screenSpaceDepth = initialPosition.w;
secondPosition = z_normalization(vec4(modelViewProjectionTransform *
initialPosition = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w)));
secondPosition = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz + scaledRight - scaledUp, dpos.w)));
crossCorner = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp + scaledRight, dpos.w)));
thirdPosition = z_normalization(vec4(modelViewProjectionTransform *
crossCorner = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz + scaledUp + scaledRight, dpos.w)));
thirdPosition = z_normalization(vec4(cameraViewProjectionMatrix *
dvec4(dpos.xyz + scaledUp - scaledRight, dpos.w)));
// Fade-out
// float maxVar = 2.0f * maxBillboardSize;
// float minVar = maxBillboardSize;
// ta = 1.0f - ( (var - minVar)/(maxVar - minVar) );
// if (ta == 0.0f)
// return;
}
else if (width < 2.0f * minBillboardSize) {
//return;
float maxVar = 2.0f * minBillboardSize;
float minVar = minBillboardSize;
ta = ( (var - minVar)/(maxVar - minVar) );
if (ta == 0.0f)
return;
}
// Build primitive
texCoord = corners[3];
gl_Position = thirdPosition;
EmitVertex();
texCoord = corners[0];
gl_Position = initialPosition;
EmitVertex();
texCoord = corners[2];
gl_Position = crossCorner;
EmitVertex();
texCoord = corners[1];
gl_Position = secondPosition;
EmitVertex();
texCoord = corners[2];
gl_Position = crossCorner;
EmitVertex();
EndPrimitive(); // First Triangle
texCoord = corners[0];
gl_Position = initialPosition;
EmitVertex();
texCoord = corners[2];
gl_Position = crossCorner;
EmitVertex();
texCoord = corners[3];
gl_Position = thirdPosition;
EmitVertex();
EndPrimitive(); // Second Triangle
}
EndPrimitive();
}
+1 -1
View File
@@ -15,7 +15,7 @@ SGCTConfig = sgct.config.single{}
-- SGCTConfig = sgct.config.single{1920, 1080, border=false, windowPos={0,0}, shared=true, name="WV_OBS_SPOUT1"}
-- A 1k fisheye rendering
-- SGCTConfig = sgct.config.fisheye{1024, 1024}
SGCTConfig = sgct.config.fisheye{1024, 1024}
-- A 4k fisheye rendering in a 1024x1024 window
-- SGCTConfig = sgct.config.fisheye{1024, 1024, res={4096, 4096}, quality="2k", tilt=27}