From 3688f3e71898cfa8e5155a17cc5238f49a1ecc87 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Tue, 25 Jun 2019 16:31:14 +0200 Subject: [PATCH 01/42] Work on Milky Way Galaxy volume rendering. Loading and raycasting works. Tonemapping and stars next. --- data/assets/base.asset | 1 + modules/galaxy/rendering/galaxyraycaster.cpp | 75 +++++++++---------- modules/galaxy/rendering/galaxyraycaster.h | 6 ++ modules/galaxy/rendering/renderablegalaxy.cpp | 55 ++++++++++---- modules/galaxy/rendering/renderablegalaxy.h | 8 +- modules/galaxy/shaders/galaxyraycast.glsl | 66 +++++++--------- modules/galaxy/shaders/raycasterbounds.fs | 17 ++--- modules/galaxy/shaders/raycasterbounds.vs | 23 +++--- 8 files changed, 127 insertions(+), 124 deletions(-) diff --git a/data/assets/base.asset b/data/assets/base.asset index 3b6e16d89f..a758852399 100644 --- a/data/assets/base.asset +++ b/data/assets/base.asset @@ -27,6 +27,7 @@ asset.require('util/default_joystick') asset.require('util/webgui') asset.request('customization/globebrowsing') +asset.request('customization/volumes') -- Keybindings that are specific for this scene local Keybindings = { diff --git a/modules/galaxy/rendering/galaxyraycaster.cpp b/modules/galaxy/rendering/galaxyraycaster.cpp index 29450d7903..44d960c011 100644 --- a/modules/galaxy/rendering/galaxyraycaster.cpp +++ b/modules/galaxy/rendering/galaxyraycaster.cpp @@ -55,14 +55,8 @@ void GalaxyRaycaster::initialize() { void GalaxyRaycaster::renderEntryPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) { - program.setUniform("modelTransform", _modelTransform); + program.setUniform("modelViewTransform", glm::mat4(modelViewTransform(data))); program.setUniform("viewProjection", data.camera.viewProjectionMatrix()); - program.setUniform("blendMode", static_cast(1)); - - program.setUniform("campos", glm::vec4(data.camera.positionVec3(), 1.f)); - program.setUniform("objpos", glm::vec4(data.modelTransform.translation, 0.f)); - program.setUniform("camrot", glm::mat4(data.camera.viewRotationMatrix())); - program.setUniform("scaling", glm::vec2(1.f, 0.f)); // Cull back face glEnable(GL_CULL_FACE); @@ -76,14 +70,8 @@ void GalaxyRaycaster::renderExitPoints(const RenderData& data, ghoul::opengl::ProgramObject& program) { // Uniforms - program.setUniform("modelTransform", _modelTransform); + program.setUniform("modelViewTransform", glm::mat4(modelViewTransform(data))); program.setUniform("viewProjection", data.camera.viewProjectionMatrix()); - program.setUniform("blendMode", static_cast(1)); - - program.setUniform("campos", glm::vec4(data.camera.positionVec3(), 1.f)); - program.setUniform("objpos", glm::vec4(data.modelTransform.translation, 0.f)); - program.setUniform("camrot", glm::mat4(data.camera.viewRotationMatrix())); - program.setUniform("scaling", glm::vec2(1.f, 0.f)); // Cull front face glEnable(GL_CULL_FACE); @@ -96,6 +84,16 @@ void GalaxyRaycaster::renderExitPoints(const RenderData& data, glCullFace(GL_BACK); } +glm::dmat4 GalaxyRaycaster::modelViewTransform(const RenderData& data) { + glm::dmat4 modelTransform = + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * + glm::dmat4(data.modelTransform.rotation) * + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)) * + glm::dmat4(_modelTransform); + + return data.camera.combinedViewMatrix() * modelTransform; +} + void GalaxyRaycaster::preRaycast(const RaycastData& data, ghoul::opengl::ProgramObject& program) { @@ -107,9 +105,17 @@ void GalaxyRaycaster::preRaycast(const RaycastData& data, const std::string opacityCoefficientUniformName = "opacityCoefficient" + std::to_string(data.id); + const std::string absorptionMultiplyUniformName = "absorptionMultiply" + + std::to_string(data.id); + + const std::string emissionMultiplyUniformName = "emissionMultiply" + + std::to_string(data.id); + program.setUniform(volumeAspectUniformName, _aspect); program.setUniform(stepSizeUniformName, _stepSize); program.setUniform(opacityCoefficientUniformName, _opacityCoefficient); + program.setUniform(absorptionMultiplyUniformName, _absorptionMultiply); + program.setUniform(emissionMultiplyUniformName, _emissionMultiply); _textureUnit = std::make_unique(); _textureUnit->activate(); @@ -122,35 +128,14 @@ void GalaxyRaycaster::postRaycast(const RaycastData&, ghoul::opengl::ProgramObje } bool GalaxyRaycaster::isCameraInside(const RenderData& data, glm::vec3& localPosition) { - // Camera rig position in world coordinates. - const glm::vec4 rigWorldPos = glm::vec4(data.camera.positionVec3(), 1.0); - //rigWorldPos /= data.camera.scaling().x * pow(10.0, data.camera.scaling().y); - //glm::mat4 invSgctMatrix = glm::inverse(data.camera.viewMatrix()); - - // Camera position in world coordinates. - const glm::vec4 camWorldPos = rigWorldPos; - const glm::vec3 objPos = static_cast(data.modelTransform.translation); - - const glm::mat4 modelTransform = glm::translate(_modelTransform, objPos); - - float divisor = 1.f; - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { - if (abs(modelTransform[i][j] > divisor)) { - divisor = modelTransform[i][j]; - } - } - } - - const glm::mat4 scaledModelTransform = modelTransform / divisor; - - const glm::vec4 modelPos = (glm::inverse(scaledModelTransform) / divisor) * - camWorldPos; + glm::vec4 modelPos = glm::inverse(modelViewTransform(data)) * + glm::vec4(0.f, 0.f, 0.f, 1.f); localPosition = (glm::vec3(modelPos) + glm::vec3(0.5)); - return (localPosition.x > 0 && localPosition.y > 0 && - localPosition.z > 0 && localPosition.x < 1 && - localPosition.y < 1 && localPosition.z < 1); + + return (localPosition.x > 0 && localPosition.x < 1 && + localPosition.y > 0 && localPosition.y < 1 && + localPosition.z > 0 && localPosition.z < 1); } std::string GalaxyRaycaster::boundsVertexShaderPath() const { @@ -181,6 +166,14 @@ void GalaxyRaycaster::setOpacityCoefficient(float opacityCoefficient) { _opacityCoefficient = opacityCoefficient; } +void GalaxyRaycaster::setAbsorptionMultiplier(float absorptionMultiply) { + _absorptionMultiply = absorptionMultiply; +} + +void GalaxyRaycaster::setEmissionMultiplier(float emissionMultiply) { + _emissionMultiply = emissionMultiply; +} + void GalaxyRaycaster::setTime(double time) { _time = time; } diff --git a/modules/galaxy/rendering/galaxyraycaster.h b/modules/galaxy/rendering/galaxyraycaster.h index 8337874c1a..4bf4e98f19 100644 --- a/modules/galaxy/rendering/galaxyraycaster.h +++ b/modules/galaxy/rendering/galaxyraycaster.h @@ -71,14 +71,20 @@ public: void setTime(double time); void setStepSize(float stepSize); void setOpacityCoefficient(float opacityCoefficient); + void setAbsorptionMultiplier(float absorptionMultiply); + void setEmissionMultiplier(float emissionMultiply); private: + glm::dmat4 modelViewTransform(const RenderData& data); + BoxGeometry _boundingBox; float _stepSize; glm::mat4 _modelTransform; glm::vec3 _aspect; double _time; float _opacityCoefficient; + float _absorptionMultiply; + float _emissionMultiply; ghoul::opengl::Texture& _texture; std::unique_ptr _textureUnit; diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index e4a589eac0..a4c9657e3f 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -45,9 +45,15 @@ #include namespace { - constexpr const char* GlslRayCastPath = "${MODULES}/toyvolume/shaders/rayCast.glsl"; + /*constexpr const char* GlslRayCastPath = "${MODULES}/toyvolume/shaders/rayCast.glsl"; constexpr const char* GlslBoundsVsPath = "${MODULES}/toyvolume/shaders/boundsVs.glsl"; - constexpr const char* GlslBoundsFsPath = "${MODULES}/toyvolume/shaders/boundsFs.glsl"; + constexpr const char* GlslBoundsFsPath = "${MODULES}/toyvolume/shaders/boundsFs.glsl";*/ + constexpr const char* GlslRaycastPath = + "${MODULES}/galaxy/shaders/galaxyraycast.glsl"; + constexpr const char* GlslBoundsVsPath = + "${MODULES}/galaxy/shaders/raycasterbounds.vs"; + constexpr const char* GlslBoundsFsPath = + "${MODULES}/galaxy/shaders/raycasterbounds.fs"; constexpr const char* _loggerCat = "Renderable Galaxy"; constexpr openspace::properties::Property::PropertyInfo StepSizeInfo = { @@ -56,6 +62,18 @@ namespace { "" // @TODO Missing documentation }; + constexpr openspace::properties::Property::PropertyInfo AbsorptionMultiplyInfo = { + "AbsorptionMultiply", + "Absorption Multiplier", + "" // @TODO Missing documentation + }; + + constexpr openspace::properties::Property::PropertyInfo EmissionMultiplyInfo = { + "EmissionMultiply", + "Emission Multiplier", + "" // @TODO Missing documentation + }; + constexpr openspace::properties::Property::PropertyInfo PointStepSizeInfo = { "PointStepSize", "Point Step Size", @@ -86,14 +104,18 @@ namespace openspace { RenderableGalaxy::RenderableGalaxy(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _stepSize(StepSizeInfo, 0.012f, 0.0005f, 0.05f) - , _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f) + , _absorptionMultiply(AbsorptionMultiplyInfo, 50.f, 0.0f, 500.0f) + , _emissionMultiply(EmissionMultiplyInfo, 1500.f, 0.0f, 3000.0f) + //, _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f) + //, _enabledPointsRatio(EnabledPointsRatioInfo, 0.2f, 0.f, 1.f) , _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(10.f)) , _rotation(RotationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(6.28f)) - , _enabledPointsRatio(EnabledPointsRatioInfo, 0.2f, 0.f, 1.f) { + dictionary.getValue("StepSize", _stepSize); + dictionary.getValue("AbsorptionMultiply", _absorptionMultiply); + dictionary.getValue("EmissionMultiply", _emissionMultiply); dictionary.getValue("Translation", _translation); dictionary.getValue("Rotation", _rotation); - dictionary.getValue("StepSize", _stepSize); if (!dictionary.hasKeyAndValue("Volume")) { LERROR("No volume dictionary specified."); @@ -121,7 +143,7 @@ namespace openspace { LERROR("No volume dimensions specified."); } - if (!dictionary.hasKeyAndValue("Points")) { + /*if (!dictionary.hasKeyAndValue("Points")) { LERROR("No points dictionary specified."); } @@ -132,7 +154,7 @@ namespace openspace { } else { LERROR("No points filename specified."); } - pointsDictionary.getValue("Scaling", _pointScaling); + pointsDictionary.getValue("Scaling", _pointScaling);*/ } void RenderableGalaxy::initializeGL() { @@ -140,7 +162,7 @@ void RenderableGalaxy::initializeGL() { _aspect = static_cast(_volumeDimensions); _aspect /= std::max(std::max(_aspect.x, _aspect.y), _aspect.z); - volume::RawVolumeReader> reader( + volume::RawVolumeReader> reader( _volumeFilename, _volumeDimensions ); @@ -149,8 +171,8 @@ void RenderableGalaxy::initializeGL() { _texture = std::make_unique( _volumeDimensions, ghoul::opengl::Texture::Format::RGBA, - GL_RGBA32F, - GL_FLOAT, + GL_RGBA, + GL_UNSIGNED_BYTE, ghoul::opengl::Texture::FilterMode::Linear, ghoul::opengl::Texture::WrappingMode::Clamp); @@ -179,13 +201,15 @@ void RenderableGalaxy::initializeGL() { onEnabledChange(onChange); addProperty(_stepSize); - addProperty(_pointStepSize); + addProperty(_absorptionMultiply); + addProperty(_emissionMultiply); + //addProperty(_pointStepSize); + //addProperty(_enabledPointsRatio); addProperty(_translation); addProperty(_rotation); - addProperty(_enabledPointsRatio); // initialize points. - std::ifstream pointFile(_pointsFilename, std::ios::in | std::ios::binary); + /*std::ifstream pointFile(_pointsFilename, std::ios::in | std::ios::binary); std::vector pointPositions; std::vector pointColors; @@ -262,7 +286,7 @@ void RenderableGalaxy::initializeGL() { glVertexAttribPointer(colorAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr); glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindVertexArray(0); + glBindVertexArray(0);*/ } void RenderableGalaxy::deinitializeGL() { @@ -301,7 +325,8 @@ void RenderableGalaxy::update(const UpdateData& data) { _raycaster->setStepSize(_stepSize); _raycaster->setAspect(_aspect); _raycaster->setModelTransform(volumeTransform); - // @EMIL: is this correct? ---abock + _raycaster->setAbsorptionMultiplier(_absorptionMultiply); + _raycaster->setEmissionMultiplier(_emissionMultiply); _raycaster->setTime(data.time.j2000Seconds()); } } diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index 3132524ad8..d0bc502922 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -55,17 +55,19 @@ private: glm::vec3 _volumeSize; glm::vec3 _pointScaling; properties::FloatProperty _stepSize; - properties::FloatProperty _pointStepSize; + properties::FloatProperty _absorptionMultiply; + properties::FloatProperty _emissionMultiply; + //properties::FloatProperty _pointStepSize; + //properties::FloatProperty _enabledPointsRatio; properties::Vec3Property _translation; properties::Vec3Property _rotation; - properties::FloatProperty _enabledPointsRatio; std::string _volumeFilename; glm::ivec3 _volumeDimensions; std::string _pointsFilename; std::unique_ptr _raycaster; - std::unique_ptr>> _volume; + std::unique_ptr>> _volume; std::unique_ptr _texture; glm::mat4 _pointTransform; glm::vec3 _aspect; diff --git a/modules/galaxy/shaders/galaxyraycast.glsl b/modules/galaxy/shaders/galaxyraycast.glsl index 852b5a31d7..1a4d41aa64 100644 --- a/modules/galaxy/shaders/galaxyraycast.glsl +++ b/modules/galaxy/shaders/galaxyraycast.glsl @@ -25,7 +25,8 @@ uniform float maxStepSize#{id} = 0.1; uniform vec3 aspect#{id} = vec3(1.0); uniform float opacityCoefficient#{id} = 1.0; - +uniform float absorptionMultiply#{id} = 50.0; +uniform float emissionMultiply#{id} = 1500.0; uniform sampler3D galaxyTexture#{id}; void sample#{id}(vec3 samplePos, @@ -44,48 +45,33 @@ void sample#{id}(vec3 samplePos, vec3 alphaTint = vec3(0.3, 0.54, 0.85); + // Source textures currently are square-rooted to avoid dithering in the shadows. + // So square them back sampledColor = sampledColor*sampledColor; + + // fudge for the dust "spreading" sampledColor.a = pow(sampledColor.a, 0.7); - //sampledColor.rgba = min(vec4(1.0), sampledColor.rgba); + + // absorption probability + float scaled_density = sampledColor.a * STEP_SIZE * absorptionMultiply#{id} * 10; + vec3 absorption = alphaTint * scaled_density; + + // extinction + vec3 extinction = exp(-absorption); + sampledColor.rgb = sampledColor.rgb * extinction; + + // emission + sampledColor.rgb += sampledColor.rgb * STEP_SIZE * emissionMultiply#{id}; + + //sampledColor.a = sampledColor.a * 50; //1.0; + + vec3 backAlpha = sampledColor.aaa * 10.0; + sampledColor.rgb = sampledColor.rgb * backAlpha; - //sampledColor.a = clamp(sampledColor.a * 10000000000.0, 0.0, 1.0); - //sampledColor.a = exp(-sampledColor.a); - // - - //sampledColor.rgb = pow(sampledColor.rgb, vec3(10.0)); - //sampledColor.a = pow(sampledColor.a, 10.0); - //sampledColor.a = pow(sampledColor.a, 100000000.0); - sampledColor.rgb *= 500.0; - sampledColor.a = sampledColor.a * 0.3; //1.0; - - - //float emissionCoefficient = 80; - //float absorptionCoefficient = 1; -// sampledColor = clamp(sampledColor, 0.0, 1.0); - - //backColor = vec3(1.0) - pow(vec3(1.0) - backColor, vec3(STEP_SIZE)); - /*if (sampledColor.a > 1.0) { - sampledColor.a = 1.0; - //accumulatedColor = vec3(1.0, 0.0, 0.0); - //accumulatedAlpha = vec3(1.0, 1.0, 1.0); - //return; - }*/ - //sampledColor.a = 1.2; - - //sampledColor.a *= 0.00001; - - vec3 backColor = sampledColor.rgb; - vec3 backAlpha = sampledColor.a * alphaTint; - - backColor *= STEP_SIZE * opacityCoefficient#{id}; - backAlpha *= STEP_SIZE * opacityCoefficient#{id}; - - backColor = clamp(backColor, 0.0, 1.0); - backAlpha = clamp(backAlpha, 0.0, 1.0); - - vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha; - accumulatedColor += oneMinusFrontAlpha * backColor; - accumulatedAlpha += oneMinusFrontAlpha * backAlpha; + sampledColor.a = clamp(sampledColor.a, 0.0, 1.0) * opacityCoefficient#{id}; + vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha; + accumulatedColor += oneMinusFrontAlpha * sampledColor.rgb; + accumulatedAlpha += oneMinusFrontAlpha * sampledColor.a; } float stepSize#{id}(vec3 samplePos, vec3 dir) { diff --git a/modules/galaxy/shaders/raycasterbounds.fs b/modules/galaxy/shaders/raycasterbounds.fs index e3a5d5beb5..6f1123a51d 100644 --- a/modules/galaxy/shaders/raycasterbounds.fs +++ b/modules/galaxy/shaders/raycasterbounds.fs @@ -22,22 +22,15 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include "PowerScaling/powerScaling_fs.hglsl" +#include "floatoperations.glsl" #include "fragment.glsl" -in vec3 vPosition; -in vec4 worldPosition; - -uniform uint blendMode; - +in vec3 modelPosition; +in vec4 viewPosition; Fragment getFragment() { - vec4 position = worldPosition; - float depth = pscDepth(position); - Fragment frag; - frag.color = vec4((vPosition + 0.5), 1.0); - frag.depth = depth; - frag.blend = blendMode; + frag.color = vec4(modelPosition + 0.5, 1.0); + frag.depth = safeLength(viewPosition); return frag; } diff --git a/modules/galaxy/shaders/raycasterbounds.vs b/modules/galaxy/shaders/raycasterbounds.vs index 8e6ddd4990..09ee0ef1c7 100644 --- a/modules/galaxy/shaders/raycasterbounds.vs +++ b/modules/galaxy/shaders/raycasterbounds.vs @@ -21,26 +21,23 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ - + #version __CONTEXT__ -#include "PowerScaling/powerScaling_vs.hglsl" - layout(location = 0) in vec4 vertPosition; -out vec3 vPosition; -out vec4 worldPosition; +out vec3 modelPosition; +out vec4 viewPosition; uniform mat4 viewProjection; -uniform mat4 modelTransform; +uniform mat4 modelViewTransform; void main() { - vPosition = vertPosition.xyz; - - worldPosition = modelTransform * vec4(vertPosition.xyz, 1.0); - worldPosition.w = 0.0; - vec4 position = pscTransform(worldPosition, mat4(1.0)); - - gl_Position = z_normalization(viewProjection * position); + modelPosition = vertPosition.xyz; + viewPosition = modelViewTransform*vertPosition; + + // project the position to view space + gl_Position = viewProjection * viewPosition; + gl_Position.z = 1.0; } From 7cc5765738f6fc301e31f8f1b0eaef2bab5a7439 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Tue, 25 Jun 2019 16:32:35 +0200 Subject: [PATCH 02/42] Added missing asset file --- data/assets/customization/volumes.asset | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 data/assets/customization/volumes.asset diff --git a/data/assets/customization/volumes.asset b/data/assets/customization/volumes.asset new file mode 100644 index 0000000000..3276f3f393 --- /dev/null +++ b/data/assets/customization/volumes.asset @@ -0,0 +1,25 @@ +-- asset.require('../examples/volume/generated/cartesian.asset') + +local assetHelper = asset.require("util/asset_helper") +local transforms = asset.require("scene/solarsystem/sun/transforms") + +local MilkyWayVolumeGalaxy = { + Identifier = "Milky Way Volume", + Parent = transforms.SolarSystemBarycenter.Identifier, + Renderable = { + Type = "RenderableGalaxy", + StepSize = 0.01, + Volume = { + Type = "Volume", + Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayRGBAVolume1024x1024x128.raw", + Dimensions = {1024, 1024, 128}, + Size = {9.2E21, 9.2E21, 1.15E21} + }, + }, + GUI = { + Path = "/Milky Way" + } +} + +local objects = { MilkyWayVolumeGalaxy } +assetHelper.registerSceneGraphNodesAndExport(asset, objects) \ No newline at end of file From b735115f329e55cf04d44c9c29b9ebbca30d0423 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Thu, 27 Jun 2019 15:59:06 +0200 Subject: [PATCH 03/42] Translation and parameter fixes. --- data/assets/customization/volumes.asset | 7 +++-- modules/galaxy/rendering/renderablegalaxy.cpp | 26 ++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/data/assets/customization/volumes.asset b/data/assets/customization/volumes.asset index 3276f3f393..c83a5ea4af 100644 --- a/data/assets/customization/volumes.asset +++ b/data/assets/customization/volumes.asset @@ -8,13 +8,16 @@ local MilkyWayVolumeGalaxy = { Parent = transforms.SolarSystemBarycenter.Identifier, Renderable = { Type = "RenderableGalaxy", - StepSize = 0.01, + StepSize = 0.015, + AbsorptionMultiply = 100, + EmissionMultiply = 500, + Translation = {0.17, 0, 0}, Volume = { Type = "Volume", Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayRGBAVolume1024x1024x128.raw", Dimensions = {1024, 1024, 128}, Size = {9.2E21, 9.2E21, 1.15E21} - }, + } }, GUI = { Path = "/Milky Way" diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index a4c9657e3f..c78074ea61 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -103,12 +103,12 @@ namespace openspace { RenderableGalaxy::RenderableGalaxy(const ghoul::Dictionary& dictionary) : Renderable(dictionary) - , _stepSize(StepSizeInfo, 0.012f, 0.0005f, 0.05f) + , _stepSize(StepSizeInfo, 0.01f, 0.0005f, 0.05f, 0.001f) , _absorptionMultiply(AbsorptionMultiplyInfo, 50.f, 0.0f, 500.0f) , _emissionMultiply(EmissionMultiplyInfo, 1500.f, 0.0f, 3000.0f) //, _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f) //, _enabledPointsRatio(EnabledPointsRatioInfo, 0.2f, 0.f, 1.f) - , _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(10.f)) + , _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(1.f)) , _rotation(RotationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(6.28f)) { dictionary.getValue("StepSize", _stepSize); @@ -117,6 +117,26 @@ namespace openspace { dictionary.getValue("Translation", _translation); dictionary.getValue("Rotation", _rotation); + if (dictionary.hasKeyAndValue(StepSizeInfo.identifier)) { + _stepSize = static_cast(dictionary.value(StepSizeInfo.identifier)); + } + + if (dictionary.hasKeyAndValue(AbsorptionMultiplyInfo.identifier)) { + _absorptionMultiply = static_cast(dictionary.value(AbsorptionMultiplyInfo.identifier)); + } + + if (dictionary.hasKeyAndValue(EmissionMultiplyInfo.identifier)) { + _emissionMultiply = static_cast(dictionary.value(EmissionMultiplyInfo.identifier)); + } + + if (dictionary.hasKeyAndValue(TranslationInfo.identifier)) { + _translation = dictionary.value(TranslationInfo.identifier); + } + + if (dictionary.hasKeyAndValue(RotationInfo.identifier)) { + _rotation = dictionary.value(RotationInfo.identifier); + } + if (!dictionary.hasKeyAndValue("Volume")) { LERROR("No volume dictionary specified."); } @@ -315,7 +335,7 @@ void RenderableGalaxy::update(const UpdateData& data) { glm::mat4 volumeTransform = glm::scale(transform, _volumeSize); _pointTransform = glm::scale(transform, _pointScaling); - const glm::vec4 translation = glm::vec4(_translation.value(), 0.0); + const glm::vec4 translation = glm::vec4(_translation.value()*_volumeSize, 0.0); // Todo: handle floating point overflow, to actually support translation. From a7dd591f54fc2de0e144404baf25d9a545f9f19e Mon Sep 17 00:00:00 2001 From: eriksunden Date: Fri, 28 Jun 2019 14:44:20 +0200 Subject: [PATCH 04/42] More tweaks on milky way galaxy volume rendering. --- data/assets/customization/volumes.asset | 6 +++--- modules/galaxy/rendering/renderablegalaxy.cpp | 4 ++-- modules/galaxy/shaders/galaxyraycast.glsl | 20 ++++++++----------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/data/assets/customization/volumes.asset b/data/assets/customization/volumes.asset index c83a5ea4af..5b9e5b711f 100644 --- a/data/assets/customization/volumes.asset +++ b/data/assets/customization/volumes.asset @@ -8,9 +8,9 @@ local MilkyWayVolumeGalaxy = { Parent = transforms.SolarSystemBarycenter.Identifier, Renderable = { Type = "RenderableGalaxy", - StepSize = 0.015, - AbsorptionMultiply = 100, - EmissionMultiply = 500, + StepSize = 0.01, + AbsorptionMultiply = 10, + EmissionMultiply = 100, Translation = {0.17, 0, 0}, Volume = { Type = "Volume", diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index c78074ea61..40b2d19c26 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -104,8 +104,8 @@ namespace openspace { RenderableGalaxy::RenderableGalaxy(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _stepSize(StepSizeInfo, 0.01f, 0.0005f, 0.05f, 0.001f) - , _absorptionMultiply(AbsorptionMultiplyInfo, 50.f, 0.0f, 500.0f) - , _emissionMultiply(EmissionMultiplyInfo, 1500.f, 0.0f, 3000.0f) + , _absorptionMultiply(AbsorptionMultiplyInfo, 40.f, 0.0f, 100.0f) + , _emissionMultiply(EmissionMultiplyInfo, 400.f, 0.0f, 1000.0f) //, _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f) //, _enabledPointsRatio(EnabledPointsRatioInfo, 0.2f, 0.f, 1.f) , _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(1.f)) diff --git a/modules/galaxy/shaders/galaxyraycast.glsl b/modules/galaxy/shaders/galaxyraycast.glsl index 1a4d41aa64..453ef60ae0 100644 --- a/modules/galaxy/shaders/galaxyraycast.glsl +++ b/modules/galaxy/shaders/galaxyraycast.glsl @@ -41,7 +41,8 @@ void sample#{id}(vec3 samplePos, vec4 sampledColor = texture(galaxyTexture#{id}, samplePos.xyz); - float STEP_SIZE = maxStepSize#{id}; + //float STEP_SIZE = maxStepSize#{id}*0.5; + float STEP_SIZE = 1 / 256.0; vec3 alphaTint = vec3(0.3, 0.54, 0.85); @@ -50,28 +51,23 @@ void sample#{id}(vec3 samplePos, sampledColor = sampledColor*sampledColor; // fudge for the dust "spreading" + sampledColor.a = clamp(sampledColor.a, 0.0, 1.0) * opacityCoefficient#{id}; sampledColor.a = pow(sampledColor.a, 0.7); // absorption probability - float scaled_density = sampledColor.a * STEP_SIZE * absorptionMultiply#{id} * 10; + float scaled_density = sampledColor.a * STEP_SIZE * absorptionMultiply#{id}; vec3 absorption = alphaTint * scaled_density; // extinction vec3 extinction = exp(-absorption); - sampledColor.rgb = sampledColor.rgb * extinction; + accumulatedColor.rgb *= extinction; // emission - sampledColor.rgb += sampledColor.rgb * STEP_SIZE * emissionMultiply#{id}; - - //sampledColor.a = sampledColor.a * 50; //1.0; - - vec3 backAlpha = sampledColor.aaa * 10.0; - sampledColor.rgb = sampledColor.rgb * backAlpha; + accumulatedColor.rgb += sampledColor.rgb * STEP_SIZE * emissionMultiply#{id}; - sampledColor.a = clamp(sampledColor.a, 0.0, 1.0) * opacityCoefficient#{id}; vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha; - accumulatedColor += oneMinusFrontAlpha * sampledColor.rgb; - accumulatedAlpha += oneMinusFrontAlpha * sampledColor.a; + //accumulatedColor += oneMinusFrontAlpha * sampledColor.rgb; + accumulatedAlpha += oneMinusFrontAlpha * sampledColor.rgb; } float stepSize#{id}(vec3 samplePos, vec3 dir) { From d60656c4ad966277efe8c4d079af4dc9319ba9cc Mon Sep 17 00:00:00 2001 From: eriksunden Date: Thu, 11 Jul 2019 14:17:30 +0200 Subject: [PATCH 05/42] Made reader for points for the stars. --- data/assets/customization/volumes.asset | 4 + modules/galaxy/rendering/renderablegalaxy.cpp | 142 +++++++++--------- modules/galaxy/shaders/points.vs | 4 +- 3 files changed, 77 insertions(+), 73 deletions(-) diff --git a/data/assets/customization/volumes.asset b/data/assets/customization/volumes.asset index 5b9e5b711f..ca685fb39f 100644 --- a/data/assets/customization/volumes.asset +++ b/data/assets/customization/volumes.asset @@ -17,6 +17,10 @@ local MilkyWayVolumeGalaxy = { Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayRGBAVolume1024x1024x128.raw", Dimensions = {1024, 1024, 128}, Size = {9.2E21, 9.2E21, 1.15E21} + }, + Points = { + Type = "Points", + Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayPoints.off" } }, GUI = { diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index 40b2d19c26..dbd71eab84 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -163,7 +163,7 @@ namespace openspace { LERROR("No volume dimensions specified."); } - /*if (!dictionary.hasKeyAndValue("Points")) { + if (!dictionary.hasKeyAndValue("Points")) { LERROR("No points dictionary specified."); } @@ -174,7 +174,7 @@ namespace openspace { } else { LERROR("No points filename specified."); } - pointsDictionary.getValue("Scaling", _pointScaling);*/ + //pointsDictionary.getValue("Scaling", _pointScaling); } void RenderableGalaxy::initializeGL() { @@ -229,84 +229,84 @@ void RenderableGalaxy::initializeGL() { addProperty(_rotation); // initialize points. - /*std::ifstream pointFile(_pointsFilename, std::ios::in | std::ios::binary); + if (!_pointsFilename.empty()) { + std::ifstream pointFile(_pointsFilename, std::ios::in); - std::vector pointPositions; - std::vector pointColors; + std::vector pointPositions; + std::vector pointColors; + int64_t nPoints; - int64_t nPoints; - pointFile.seekg(0, std::ios::beg); // read heder. - pointFile.read(reinterpret_cast(&nPoints), sizeof(int64_t)); + // Read header for OFF (Object File Format) + std::string line; + std::getline(pointFile, line); - _nPoints = static_cast(nPoints); + // Read point count + std::getline(pointFile, line); + std::istringstream iss(line); + iss >> nPoints; - size_t nFloats = _nPoints * 7; + // Prepare point reading + _nPoints = static_cast(nPoints); + float maxdist = 0; - std::vector pointData(nFloats); - pointFile.seekg(sizeof(int64_t), std::ios::beg); // read past heder. - pointFile.read(reinterpret_cast(pointData.data()), nFloats * sizeof(float)); - pointFile.close(); + // Read points + float x, y, z, r, g, b, a; + for (size_t i = 0; i < _nPoints; ++i) { + std::getline(pointFile, line); + std::istringstream iss(line); + iss >> x >> y >> z >> r >> g >> b >> a; + maxdist = std::max(maxdist, glm::length(glm::vec3(x, y, z))); + pointPositions.emplace_back(x, y, z); + pointColors.emplace_back(r, g, b); + } - float maxdist = 0; + pointFile.close(); - for (size_t i = 0; i < _nPoints; ++i) { - float x = pointData[i * 7 + 0]; - float y = pointData[i * 7 + 1]; - float z = pointData[i * 7 + 2]; - float r = pointData[i * 7 + 3]; - float g = pointData[i * 7 + 4]; - float b = pointData[i * 7 + 5]; - maxdist = std::max(maxdist, glm::length(glm::vec3(x, y, z))); - //float a = pointData[i * 7 + 6]; alpha is not used. + std::cout << maxdist << std::endl; - pointPositions.emplace_back(x, y, z); - pointColors.emplace_back(r, g, b); + glGenVertexArrays(1, &_pointsVao); + glGenBuffers(1, &_positionVbo); + glGenBuffers(1, &_colorVbo); + + glBindVertexArray(_pointsVao); + glBindBuffer(GL_ARRAY_BUFFER, _positionVbo); + glBufferData(GL_ARRAY_BUFFER, + pointPositions.size() * sizeof(glm::vec3), + pointPositions.data(), + GL_STATIC_DRAW + ); + + glBindBuffer(GL_ARRAY_BUFFER, _colorVbo); + glBufferData(GL_ARRAY_BUFFER, + pointColors.size() * sizeof(glm::vec3), + pointColors.data(), + GL_STATIC_DRAW + ); + + _pointsProgram = global::renderEngine.buildRenderProgram( + "Galaxy points", + absPath("${MODULE_GALAXY}/shaders/points.vs"), + absPath("${MODULE_GALAXY}/shaders/points.fs") + ); + + _pointsProgram->setIgnoreUniformLocationError( + ghoul::opengl::ProgramObject::IgnoreError::Yes + ); + + GLint positionAttrib = _pointsProgram->attributeLocation("inPosition"); + GLint colorAttrib = _pointsProgram->attributeLocation("inColor"); + + glBindBuffer(GL_ARRAY_BUFFER, _positionVbo); + glEnableVertexAttribArray(positionAttrib); + glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr); + + glBindBuffer(GL_ARRAY_BUFFER, _colorVbo); + glEnableVertexAttribArray(colorAttrib); + glVertexAttribPointer(colorAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); } - - std::cout << maxdist << std::endl; - - glGenVertexArrays(1, &_pointsVao); - glGenBuffers(1, &_positionVbo); - glGenBuffers(1, &_colorVbo); - - glBindVertexArray(_pointsVao); - glBindBuffer(GL_ARRAY_BUFFER, _positionVbo); - glBufferData(GL_ARRAY_BUFFER, - pointPositions.size() * sizeof(glm::vec3), - pointPositions.data(), - GL_STATIC_DRAW - ); - - glBindBuffer(GL_ARRAY_BUFFER, _colorVbo); - glBufferData(GL_ARRAY_BUFFER, - pointColors.size() * sizeof(glm::vec3), - pointColors.data(), - GL_STATIC_DRAW - ); - - _pointsProgram = global::renderEngine.buildRenderProgram( - "Galaxy points", - absPath("${MODULE_GALAXY}/shaders/points.vs"), - absPath("${MODULE_GALAXY}/shaders/points.fs") - ); - - _pointsProgram->setIgnoreUniformLocationError( - ghoul::opengl::ProgramObject::IgnoreError::Yes - ); - - GLint positionAttrib = _pointsProgram->attributeLocation("inPosition"); - GLint colorAttrib = _pointsProgram->attributeLocation("inColor"); - - glBindBuffer(GL_ARRAY_BUFFER, _positionVbo); - glEnableVertexAttribArray(positionAttrib); - glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr); - - glBindBuffer(GL_ARRAY_BUFFER, _colorVbo); - glEnableVertexAttribArray(colorAttrib); - glVertexAttribPointer(colorAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindVertexArray(0);*/ } void RenderableGalaxy::deinitializeGL() { diff --git a/modules/galaxy/shaders/points.vs b/modules/galaxy/shaders/points.vs index 666087bb2b..f756798273 100644 --- a/modules/galaxy/shaders/points.vs +++ b/modules/galaxy/shaders/points.vs @@ -26,8 +26,8 @@ #include "PowerScaling/powerScaling_vs.hglsl" -in vec3 inPosition; -in vec3 inColor; +layout(location = 0) in vec3 inPosition; +layout(location = 1) in vec3 inColor; out vec3 vsPosition; out vec3 vsColor; From 320a213a7b5544128c9198210dabda96ad44c118 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Mon, 5 Aug 2019 12:05:28 +0200 Subject: [PATCH 06/42] Minor shader compile fix --- modules/galaxy/shaders/points.fs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/galaxy/shaders/points.fs b/modules/galaxy/shaders/points.fs index 97a0bb32e9..d997f02c95 100644 --- a/modules/galaxy/shaders/points.fs +++ b/modules/galaxy/shaders/points.fs @@ -33,11 +33,13 @@ uniform float emittanceFactor; Fragment getFragment() { Fragment frag; + + float depth = pscDepth(vec4(vsPosition, 0.0)); float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(depth)); frag.color = vec4(vsColor.rgb * coefficient, 1.0); - frag.depth = pscDepth(vec4(vsPosition, 0.0)); + frag.depth = depth; return frag; } From 9a1a3e397b7860d6c75695b62717551a54d9f4ce Mon Sep 17 00:00:00 2001 From: eriksunden Date: Wed, 14 Aug 2019 14:59:58 +0200 Subject: [PATCH 07/42] PointCloud data rendered and location for volume and pc seems to be correct (need some cleanup). PSFtexture for billboards next thing. --- data/assets/customization/volumes.asset | 7 +- modules/galaxy/CMakeLists.txt | 11 +- modules/galaxy/rendering/galaxyraycaster.cpp | 4 +- modules/galaxy/rendering/renderablegalaxy.cpp | 244 +++++++++++++----- modules/galaxy/rendering/renderablegalaxy.h | 17 +- modules/galaxy/shaders/galaxyraycast.glsl | 22 +- .../shaders/{points.fs => points_fs.glsl} | 29 ++- .../shaders/{points.vs => points_vs.glsl} | 54 ++-- ...asterbounds.fs => raycasterbounds_fs.glsl} | 0 ...asterbounds.vs => raycasterbounds_vs.glsl} | 0 10 files changed, 288 insertions(+), 100 deletions(-) rename modules/galaxy/shaders/{points.fs => points_fs.glsl} (72%) rename modules/galaxy/shaders/{points.vs => points_vs.glsl} (64%) rename modules/galaxy/shaders/{raycasterbounds.fs => raycasterbounds_fs.glsl} (100%) rename modules/galaxy/shaders/{raycasterbounds.vs => raycasterbounds_vs.glsl} (100%) diff --git a/data/assets/customization/volumes.asset b/data/assets/customization/volumes.asset index ca685fb39f..4beb79b4a1 100644 --- a/data/assets/customization/volumes.asset +++ b/data/assets/customization/volumes.asset @@ -11,16 +11,17 @@ local MilkyWayVolumeGalaxy = { StepSize = 0.01, AbsorptionMultiply = 10, EmissionMultiply = 100, - Translation = {0.17, 0, 0}, + Translation = {0.2, 0, 0}, Volume = { Type = "Volume", Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayRGBAVolume1024x1024x128.raw", Dimensions = {1024, 1024, 128}, - Size = {9.2E21, 9.2E21, 1.15E21} + Size = {1.2E21, 1.2E21, 0.15E21} }, Points = { Type = "Points", - Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayPoints.off" + Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayPoints.off", + Scaling = {1.0, 1.0, 1.0} } }, GUI = { diff --git a/modules/galaxy/CMakeLists.txt b/modules/galaxy/CMakeLists.txt index f1bed8c93a..58719e8e65 100644 --- a/modules/galaxy/CMakeLists.txt +++ b/modules/galaxy/CMakeLists.txt @@ -42,9 +42,18 @@ set(SOURCE_FILES ) source_group("Source Files" FILES ${SOURCE_FILES}) +set(SHADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/galaxyraycast.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/points_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/points_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/raycasterbounds_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/raycasterbounds_vs.glsl +) +source_group("Shader Files" FILES ${SHADER_FILES}) + create_new_module( "Galaxy" galaxy STATIC - ${HEADER_FILES} ${SOURCE_FILES} + ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES} ) diff --git a/modules/galaxy/rendering/galaxyraycaster.cpp b/modules/galaxy/rendering/galaxyraycaster.cpp index 44d960c011..e203760f7a 100644 --- a/modules/galaxy/rendering/galaxyraycaster.cpp +++ b/modules/galaxy/rendering/galaxyraycaster.cpp @@ -35,9 +35,9 @@ namespace { constexpr const char* GlslRaycastPath = "${MODULES}/galaxy/shaders/galaxyraycast.glsl"; constexpr const char* GlslBoundsVsPath = - "${MODULES}/galaxy/shaders/raycasterbounds.vs"; + "${MODULES}/galaxy/shaders/raycasterbounds_vs.glsl"; constexpr const char* GlslBoundsFsPath = - "${MODULES}/galaxy/shaders/raycasterbounds.fs"; + "${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl"; } // namespace namespace openspace { diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index dbd71eab84..c0fde80d62 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -45,17 +46,19 @@ #include namespace { - /*constexpr const char* GlslRayCastPath = "${MODULES}/toyvolume/shaders/rayCast.glsl"; - constexpr const char* GlslBoundsVsPath = "${MODULES}/toyvolume/shaders/boundsVs.glsl"; - constexpr const char* GlslBoundsFsPath = "${MODULES}/toyvolume/shaders/boundsFs.glsl";*/ constexpr const char* GlslRaycastPath = "${MODULES}/galaxy/shaders/galaxyraycast.glsl"; constexpr const char* GlslBoundsVsPath = - "${MODULES}/galaxy/shaders/raycasterbounds.vs"; + "${MODULES}/galaxy/shaders/raycasterbounds_vs.glsl"; constexpr const char* GlslBoundsFsPath = - "${MODULES}/galaxy/shaders/raycasterbounds.fs"; + "${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl"; constexpr const char* _loggerCat = "Renderable Galaxy"; + constexpr const std::array UniformNames = { + "modelMatrix", "cameraUp", "eyePosition", "cameraViewProjectionMatrix", + "emittanceFactor" + }; + constexpr openspace::properties::Property::PropertyInfo StepSizeInfo = { "StepSize", "Step Size", @@ -80,6 +83,12 @@ namespace { "" // @TODO Missing documentation }; + constexpr openspace::properties::Property::PropertyInfo PointScaleFactorInfo = { + "PointScaleFactor", + "Point Scale Factor", + "" // @TODO Missing documentation + }; + constexpr openspace::properties::Property::PropertyInfo TranslationInfo = { "Translation", "Translation", @@ -106,14 +115,18 @@ namespace openspace { , _stepSize(StepSizeInfo, 0.01f, 0.0005f, 0.05f, 0.001f) , _absorptionMultiply(AbsorptionMultiplyInfo, 40.f, 0.0f, 100.0f) , _emissionMultiply(EmissionMultiplyInfo, 400.f, 0.0f, 1000.0f) - //, _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f) - //, _enabledPointsRatio(EnabledPointsRatioInfo, 0.2f, 0.f, 1.f) + , _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f) + , _pointScaleFactor(PointScaleFactorInfo, 1.f, 1.f, 64.f) + , _enabledPointsRatio(EnabledPointsRatioInfo, 0.02f, 0.001f, 0.1f) , _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(1.f)) , _rotation(RotationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(6.28f)) { dictionary.getValue("StepSize", _stepSize); dictionary.getValue("AbsorptionMultiply", _absorptionMultiply); dictionary.getValue("EmissionMultiply", _emissionMultiply); + dictionary.getValue("PointStepSize", _pointStepSize); + dictionary.getValue("PointScaleFactor", _pointScaleFactor); + dictionary.getValue("EnabledPointsRatio", _enabledPointsRatio); dictionary.getValue("Translation", _translation); dictionary.getValue("Rotation", _rotation); @@ -129,6 +142,18 @@ namespace openspace { _emissionMultiply = static_cast(dictionary.value(EmissionMultiplyInfo.identifier)); } + if (dictionary.hasKeyAndValue(PointStepSizeInfo.identifier)) { + _pointStepSize = static_cast(dictionary.value(PointStepSizeInfo.identifier)); + } + + if (dictionary.hasKeyAndValue(PointScaleFactorInfo.identifier)) { + _pointScaleFactor = static_cast(dictionary.value(PointScaleFactorInfo.identifier)); + } + + if (dictionary.hasKeyAndValue(EnabledPointsRatioInfo.identifier)) { + _enabledPointsRatio = static_cast(dictionary.value(EnabledPointsRatioInfo.identifier)); + } + if (dictionary.hasKeyAndValue(TranslationInfo.identifier)) { _translation = dictionary.value(TranslationInfo.identifier); } @@ -174,7 +199,6 @@ namespace openspace { } else { LERROR("No points filename specified."); } - //pointsDictionary.getValue("Scaling", _pointScaling); } void RenderableGalaxy::initializeGL() { @@ -223,13 +247,30 @@ void RenderableGalaxy::initializeGL() { addProperty(_stepSize); addProperty(_absorptionMultiply); addProperty(_emissionMultiply); - //addProperty(_pointStepSize); - //addProperty(_enabledPointsRatio); + addProperty(_pointStepSize); + addProperty(_pointScaleFactor); + addProperty(_enabledPointsRatio); addProperty(_translation); addProperty(_rotation); // initialize points. if (!_pointsFilename.empty()) { + _pointsProgram = global::renderEngine.buildRenderProgram( + "Galaxy points", + absPath("${MODULE_GALAXY}/shaders/points_vs.glsl"), + absPath("${MODULE_GALAXY}/shaders/points_fs.glsl"), + absPath("${MODULE_GALAXY}/shaders/points_ge.glsl") + ); + + ghoul::opengl::updateUniformLocations(*_pointsProgram, _uniformCache, UniformNames); + + _pointsProgram->setIgnoreUniformLocationError( + ghoul::opengl::ProgramObject::IgnoreError::Yes + ); + + GLint positionAttrib = _pointsProgram->attributeLocation("in_position"); + GLint colorAttrib = _pointsProgram->attributeLocation("in_color"); + std::ifstream pointFile(_pointsFilename, std::ios::in); std::vector pointPositions; @@ -251,12 +292,18 @@ void RenderableGalaxy::initializeGL() { // Read points float x, y, z, r, g, b, a; - for (size_t i = 0; i < _nPoints; ++i) { + for (size_t i = 0; i < static_cast(_nPoints * 0.1) + 1; ++i) { std::getline(pointFile, line); - std::istringstream iss(line); - iss >> x >> y >> z >> r >> g >> b >> a; - maxdist = std::max(maxdist, glm::length(glm::vec3(x, y, z))); - pointPositions.emplace_back(x, y, z); + std::istringstream issp(line); + issp >> x >> y >> z >> r >> g >> b >> a; + + //Convert klioparsec to meters + glm::vec3 position = glm::vec3(x, y, z); + position *= (openspace::distanceconstants::Parsec * 100); + + maxdist = std::max(maxdist, glm::length(position)); + + pointPositions.emplace_back(position); pointColors.emplace_back(r, g, b); } @@ -283,19 +330,6 @@ void RenderableGalaxy::initializeGL() { GL_STATIC_DRAW ); - _pointsProgram = global::renderEngine.buildRenderProgram( - "Galaxy points", - absPath("${MODULE_GALAXY}/shaders/points.vs"), - absPath("${MODULE_GALAXY}/shaders/points.fs") - ); - - _pointsProgram->setIgnoreUniformLocationError( - ghoul::opengl::ProgramObject::IgnoreError::Yes - ); - - GLint positionAttrib = _pointsProgram->attributeLocation("inPosition"); - GLint colorAttrib = _pointsProgram->attributeLocation("inColor"); - glBindBuffer(GL_ARRAY_BUFFER, _positionVbo); glEnableVertexAttribArray(positionAttrib); glVertexAttribPointer(positionAttrib, 3, GL_FLOAT, GL_FALSE, 0, nullptr); @@ -333,7 +367,8 @@ void RenderableGalaxy::update(const UpdateData& data) { transform = glm::rotate(transform, eulerRotation.z, glm::vec3(0, 0, 1)); glm::mat4 volumeTransform = glm::scale(transform, _volumeSize); - _pointTransform = glm::scale(transform, _pointScaling); + _pointTransform = transform; + //_pointTransform = glm::scale(transform, _pointScaling); const glm::vec4 translation = glm::vec4(_translation.value()*_volumeSize, 0.0); @@ -352,43 +387,136 @@ void RenderableGalaxy::update(const UpdateData& data) { } void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { - RaycasterTask task { _raycaster.get(), data }; + if (_raycaster) { + RaycasterTask task { _raycaster.get(), data }; - const glm::vec3 position = data.camera.positionVec3(); - const float length = safeLength(position); - const glm::vec3 galaxySize = _volumeSize; + const glm::vec3 position = data.camera.positionVec3(); + const float length = safeLength(position); + const glm::vec3 galaxySize = _volumeSize; - const float maxDim = std::max(std::max(galaxySize.x, galaxySize.y), galaxySize.z); + const float maxDim = std::max(std::max(galaxySize.x, galaxySize.y), galaxySize.z); - const float lowerRampStart = maxDim * 0.02f; - const float lowerRampEnd = maxDim * 0.5f; + const float lowerRampStart = maxDim * 0.02f; + const float lowerRampEnd = maxDim * 0.5f; - const float upperRampStart = maxDim * 2.f; - const float upperRampEnd = maxDim * 10.f; + const float upperRampStart = maxDim * 2.f; + const float upperRampEnd = maxDim * 10.f; - float opacityCoefficient = 1.f; + float opacityCoefficient = 1.f; - if (length < lowerRampStart) { - opacityCoefficient = 0.f; // camera really close - } else if (length < lowerRampEnd) { - opacityCoefficient = (length - lowerRampStart) / (lowerRampEnd - lowerRampStart); - } else if (length < upperRampStart) { - opacityCoefficient = 1.f; // sweet spot (max) - } else if (length < upperRampEnd) { - opacityCoefficient = 1.f - (length - upperRampStart) / - (upperRampEnd - upperRampStart); //fade out - } else { - opacityCoefficient = 0; + if (length < lowerRampStart) { + opacityCoefficient = 0.f; // camera really close + } else if (length < lowerRampEnd) { + opacityCoefficient = (length - lowerRampStart) / (lowerRampEnd - lowerRampStart); + } else if (length < upperRampStart) { + opacityCoefficient = 1.f; // sweet spot (max) + } else if (length < upperRampEnd) { + opacityCoefficient = 1.f - (length - upperRampStart) / + (upperRampEnd - upperRampStart); //fade out + } else { + opacityCoefficient = 0; + } + + _opacityCoefficient = opacityCoefficient; + ghoul_assert( + _opacityCoefficient >= 0.f && _opacityCoefficient <= 1.f, + "Opacity coefficient was not between 0 and 1" + ); + if (opacityCoefficient > 0) { + _raycaster->setOpacityCoefficient(_opacityCoefficient); + tasks.raycasterTasks.push_back(task); + } } - _opacityCoefficient = opacityCoefficient; - ghoul_assert( - _opacityCoefficient >= 0.f && _opacityCoefficient <= 1.f, - "Opacity coefficient was not between 0 and 1" - ); - if (opacityCoefficient > 0) { - _raycaster->setOpacityCoefficient(_opacityCoefficient); - tasks.raycasterTasks.push_back(task); + if (_pointsProgram) { + // Saving current OpenGL state + GLenum blendEquationRGB; + GLenum blendEquationAlpha; + GLenum blendDestAlpha; + GLenum blendDestRGB; + GLenum blendSrcAlpha; + GLenum blendSrcRGB; + GLboolean depthMask; + + glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB); + glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha); + glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha); + glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB); + glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha); + glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB); + + glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glDepthMask(false); + + _pointsProgram->activate(); + + glm::dvec3 eyePosition = glm::dvec3( + glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0) + ); + _pointsProgram->setUniform(_uniformCache.eyePosition, eyePosition); + + glm::dvec3 cameraUp = data.camera.lookUpVectorWorldSpace(); + _pointsProgram->setUniform(_uniformCache.cameraUp, cameraUp); + + const glm::dvec3 dtranslation = glm::dvec3((double)_translation.value().x, (double)_translation.value().y, (double)_translation.value().z); + + glm::dmat4 modelMatrix = + 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))); + + glm::dmat4 projectionMatrix = glm::dmat4(data.camera.projectionMatrix()); + + glm::dmat4 cameraViewProjectionMatrix = projectionMatrix * + data.camera.combinedViewMatrix(); + + + /*glm::mat4 modelMatrix = _pointTransform; + glm::mat4 viewMatrix = data.camera.combinedViewMatrix(); + glm::mat4 projectionMatrix = data.camera.projectionMatrix(); + + _pointsProgram->setUniform("model", modelMatrix); + _pointsProgram->setUniform("view", viewMatrix); + _pointsProgram->setUniform("projection", projectionMatrix);*/ + + /*glm::dmat4 modelTransform = + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * + glm::dmat4(data.modelTransform.rotation) * + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)) * + glm::dmat4(_pointTransform); + + glm::mat4 modelViewTransform = viewMatrix * modelMatrix; + + _pointsProgram->setUniform("modelViewTransform", modelViewTransform); + _pointsProgram->setUniform("viewProjection", data.camera.viewProjectionMatrix());*/ + + _pointsProgram->setUniform(_uniformCache.modelMatrix, modelMatrix); + _pointsProgram->setUniform( + _uniformCache.cameraViewProjectionMatrix, + cameraViewProjectionMatrix + ); + float emittanceFactor = _opacityCoefficient * static_cast(_volumeSize).x; + _pointsProgram->setUniform(_uniformCache.emittanceFactor, emittanceFactor); + + /*_pointsProgram->setUniform("scaleFactor", _pointScaleFactor); + _pointsProgram->setUniform("emittanceFactor", emittanceFactor);*/ + + glBindVertexArray(_pointsVao); + glDrawArrays(GL_POINTS, 0, static_cast(_nPoints * _enabledPointsRatio)); + + glBindVertexArray(0); + + _pointsProgram->deactivate(); + + glDepthMask(true); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + // Restores OpenGL blending state + glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha); + glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha); + glDepthMask(depthMask); } } diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index d0bc502922..b4ae9c57f4 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -30,6 +30,11 @@ #include #include #include +#include + +namespace ghoul::opengl { + class ProgramObject; +} // namespace ghoul::opengl namespace openspace { @@ -40,7 +45,7 @@ struct RenderData; class RenderableGalaxy : public Renderable { public: - RenderableGalaxy(const ghoul::Dictionary& dictionary); + explicit RenderableGalaxy(const ghoul::Dictionary& dictionary); virtual ~RenderableGalaxy() = default; void initializeGL() override; @@ -57,8 +62,9 @@ private: properties::FloatProperty _stepSize; properties::FloatProperty _absorptionMultiply; properties::FloatProperty _emissionMultiply; - //properties::FloatProperty _pointStepSize; - //properties::FloatProperty _enabledPointsRatio; + properties::FloatProperty _pointStepSize; + properties::FloatProperty _pointScaleFactor; + properties::FloatProperty _enabledPointsRatio; properties::Vec3Property _translation; properties::Vec3Property _rotation; @@ -74,6 +80,11 @@ private: float _opacityCoefficient; std::unique_ptr _pointsProgram; + UniformCache( + modelMatrix, cameraUp, eyePosition, cameraViewProjectionMatrix, + emittanceFactor + ) _uniformCache; + std::vector _pointsData; size_t _nPoints; GLuint _pointsVao; GLuint _positionVbo; diff --git a/modules/galaxy/shaders/galaxyraycast.glsl b/modules/galaxy/shaders/galaxyraycast.glsl index 453ef60ae0..7135a08c13 100644 --- a/modules/galaxy/shaders/galaxyraycast.glsl +++ b/modules/galaxy/shaders/galaxyraycast.glsl @@ -24,8 +24,8 @@ uniform float maxStepSize#{id} = 0.1; uniform vec3 aspect#{id} = vec3(1.0); -uniform float opacityCoefficient#{id} = 1.0; -uniform float absorptionMultiply#{id} = 50.0; +uniform float opacityCoefficient#{id} = 1.0; +uniform float absorptionMultiply#{id} = 50.0; uniform float emissionMultiply#{id} = 1500.0; uniform sampler3D galaxyTexture#{id}; @@ -35,33 +35,39 @@ void sample#{id}(vec3 samplePos, inout vec3 accumulatedAlpha, inout float maxStepSize) { + //Speed up and border edge artifact fix + vec3 normalizedPos = (samplePos*2.0)-1.0; + if(abs(normalizedPos.x) > 0.8 || abs(normalizedPos.y) > 0.8){ + //accumulatedAlpha = vec3(0.0); + return; + } vec3 aspect = aspect#{id}; maxStepSize = maxStepSize#{id} / length(dir / aspect); - + vec4 sampledColor = texture(galaxyTexture#{id}, samplePos.xyz); //float STEP_SIZE = maxStepSize#{id}*0.5; - float STEP_SIZE = 1 / 256.0; + float STEP_SIZE = 1 / 256.0; vec3 alphaTint = vec3(0.3, 0.54, 0.85); // Source textures currently are square-rooted to avoid dithering in the shadows. // So square them back sampledColor = sampledColor*sampledColor; - + // fudge for the dust "spreading" sampledColor.a = clamp(sampledColor.a, 0.0, 1.0) * opacityCoefficient#{id}; sampledColor.a = pow(sampledColor.a, 0.7); - + // absorption probability float scaled_density = sampledColor.a * STEP_SIZE * absorptionMultiply#{id}; vec3 absorption = alphaTint * scaled_density; - + // extinction vec3 extinction = exp(-absorption); accumulatedColor.rgb *= extinction; - + // emission accumulatedColor.rgb += sampledColor.rgb * STEP_SIZE * emissionMultiply#{id}; diff --git a/modules/galaxy/shaders/points.fs b/modules/galaxy/shaders/points_fs.glsl similarity index 72% rename from modules/galaxy/shaders/points.fs rename to modules/galaxy/shaders/points_fs.glsl index d997f02c95..b9f49f7c0d 100644 --- a/modules/galaxy/shaders/points.fs +++ b/modules/galaxy/shaders/points_fs.glsl @@ -23,23 +23,34 @@ ****************************************************************************************/ #include "fragment.glsl" -#include "PowerScaling/powerScaling_fs.hglsl" +#include "floatoperations.glsl" -in vec3 vsPosition; -in vec3 vsColor; +in vec4 vs_position; +in vec3 ge_color; +in float ge_screenSpaceDepth; uniform float emittanceFactor; - Fragment getFragment() { Fragment frag; - - float depth = pscDepth(vec4(vsPosition, 0.0)); - float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(depth)); - frag.color = vec4(vsColor.rgb * coefficient, 1.0); + //frag.depth = vs_screenSpaceDepth; - frag.depth = depth; + //float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(ge_screenSpaceDepth)); + float coefficient = exp(1.38 * log(0.2) - 2*log(ge_screenSpaceDepth)); + frag.color = vec4(ge_color, 1.0)*emittanceFactor; + //frag.gPosition = vec4(vs_position, 1.0); + //frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); + + //frag.color = vec4(1.0, 0.0, 0.0, 1.0); + //frag.depth = depth; + //frag.blend = BLEND_MODE_ADDITIVE; + + //float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(ge_screenSpaceDepth)); + //frag.color = vec4(ge_color.rgb * coefficient, 1.0); + frag.depth = ge_screenSpaceDepth; + frag.gPosition = vs_position; + frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); return frag; } diff --git a/modules/galaxy/shaders/points.vs b/modules/galaxy/shaders/points_vs.glsl similarity index 64% rename from modules/galaxy/shaders/points.vs rename to modules/galaxy/shaders/points_vs.glsl index f756798273..90ee876d6f 100644 --- a/modules/galaxy/shaders/points.vs +++ b/modules/galaxy/shaders/points_vs.glsl @@ -24,30 +24,52 @@ #version __CONTEXT__ -#include "PowerScaling/powerScaling_vs.hglsl" +//#include "PowerScaling/powerScaling_vs.hglsl" -layout(location = 0) in vec3 inPosition; -layout(location = 1) in vec3 inColor; +layout(location = 0) in vec3 in_position; +layout(location = 1) in vec3 in_color; -out vec3 vsPosition; -out vec3 vsColor; +//out vec3 vs_position; +out vec3 vs_color; +//out float vs_screenSpaceDepth; -uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; +//uniform mat4 model; +//uniform mat4 view; +//uniform mat4 projection; +//uniform float scaleFactor; +//uniform mat4 viewProjection; +//uniform mat4 modelViewTransform; void main() { - vec4 p = vec4(inPosition, 1.0); - - vec4 worldPosition = model * vec4(inPosition, 1.0); + /*vec4 worldPosition = model * vec4(in_position, 1.0); worldPosition.w = 0.0; vec4 position = worldPosition; //pscTransform(worldPosition, model); - - position = pscTransform(position, mat4(1.0)); - vsPosition = position.xyz; + vs_position = position.xyz; position = projection * view * position; - gl_Position = z_normalization(position); - vsColor = inColor; + gl_Position = position;*/ + + /*vec4 tmp = vec4(inPosition, 0.0); + vsPosition = inPosition; + vec4 position = pscTransform(tmp, model); + position = projection * view * position; + gl_Position = z_normalization(position);*/ + + //vs_position = (modelViewTransform * vec4(in_position, 1.0)).xyz; + //vs_position = in_position; + vs_color = in_color; + + /*vec4 positionClipSpace = vec4(projection * view * model * vec4(in_position, 1.0)); + vec4 positionScreenSpace = vec4(z_normalization(positionClipSpace)); + vs_screenSpaceDepth = positionScreenSpace.w;*/ + //vs_screenSpaceDepth = 1.0; + + //gl_PointSize = scaleFactor; + //gl_Position = positionScreenSpace; + + // project the position to view space + //gl_Position = viewProjection * vec4(vs_position, 1.0); + gl_Position = vec4(in_position, 1.0); + //gl_Position.z = 1.0; } diff --git a/modules/galaxy/shaders/raycasterbounds.fs b/modules/galaxy/shaders/raycasterbounds_fs.glsl similarity index 100% rename from modules/galaxy/shaders/raycasterbounds.fs rename to modules/galaxy/shaders/raycasterbounds_fs.glsl diff --git a/modules/galaxy/shaders/raycasterbounds.vs b/modules/galaxy/shaders/raycasterbounds_vs.glsl similarity index 100% rename from modules/galaxy/shaders/raycasterbounds.vs rename to modules/galaxy/shaders/raycasterbounds_vs.glsl From a966457641beed6d50f95664987f0c6c2f5306fe Mon Sep 17 00:00:00 2001 From: eriksunden Date: Thu, 15 Aug 2019 14:48:19 +0200 Subject: [PATCH 08/42] Star rendering with halo texture implemented. --- data/assets/customization/volumes.asset | 3 +- modules/galaxy/rendering/renderablegalaxy.cpp | 122 ++++++------------ modules/galaxy/rendering/renderablegalaxy.h | 8 +- modules/galaxy/shaders/galaxyraycast.glsl | 104 +++++++-------- modules/galaxy/shaders/points_fs.glsl | 25 ++-- 5 files changed, 107 insertions(+), 155 deletions(-) diff --git a/data/assets/customization/volumes.asset b/data/assets/customization/volumes.asset index 4beb79b4a1..da77323480 100644 --- a/data/assets/customization/volumes.asset +++ b/data/assets/customization/volumes.asset @@ -21,7 +21,8 @@ local MilkyWayVolumeGalaxy = { Points = { Type = "Points", Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayPoints.off", - Scaling = {1.0, 1.0, 1.0} + Scaling = {1.0, 1.0, 1.0}, + Texture = "${BASE}/../OpenSpaceData/Milkyway/halo.png" } }, GUI = { diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index c0fde80d62..be8bb1df03 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -54,9 +54,9 @@ namespace { "${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl"; constexpr const char* _loggerCat = "Renderable Galaxy"; - constexpr const std::array UniformNames = { + constexpr const std::array UniformNames = { "modelMatrix", "cameraUp", "eyePosition", "cameraViewProjectionMatrix", - "emittanceFactor" + "emittanceFactor", "psfTexture" }; constexpr openspace::properties::Property::PropertyInfo StepSizeInfo = { @@ -77,18 +77,6 @@ namespace { "" // @TODO Missing documentation }; - constexpr openspace::properties::Property::PropertyInfo PointStepSizeInfo = { - "PointStepSize", - "Point Step Size", - "" // @TODO Missing documentation - }; - - constexpr openspace::properties::Property::PropertyInfo PointScaleFactorInfo = { - "PointScaleFactor", - "Point Scale Factor", - "" // @TODO Missing documentation - }; - constexpr openspace::properties::Property::PropertyInfo TranslationInfo = { "Translation", "Translation", @@ -115,8 +103,6 @@ namespace openspace { , _stepSize(StepSizeInfo, 0.01f, 0.0005f, 0.05f, 0.001f) , _absorptionMultiply(AbsorptionMultiplyInfo, 40.f, 0.0f, 100.0f) , _emissionMultiply(EmissionMultiplyInfo, 400.f, 0.0f, 1000.0f) - , _pointStepSize(PointStepSizeInfo, 0.01f, 0.01f, 0.1f) - , _pointScaleFactor(PointScaleFactorInfo, 1.f, 1.f, 64.f) , _enabledPointsRatio(EnabledPointsRatioInfo, 0.02f, 0.001f, 0.1f) , _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(1.f)) , _rotation(RotationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(6.28f)) @@ -124,8 +110,6 @@ namespace openspace { dictionary.getValue("StepSize", _stepSize); dictionary.getValue("AbsorptionMultiply", _absorptionMultiply); dictionary.getValue("EmissionMultiply", _emissionMultiply); - dictionary.getValue("PointStepSize", _pointStepSize); - dictionary.getValue("PointScaleFactor", _pointScaleFactor); dictionary.getValue("EnabledPointsRatio", _enabledPointsRatio); dictionary.getValue("Translation", _translation); dictionary.getValue("Rotation", _rotation); @@ -142,14 +126,6 @@ namespace openspace { _emissionMultiply = static_cast(dictionary.value(EmissionMultiplyInfo.identifier)); } - if (dictionary.hasKeyAndValue(PointStepSizeInfo.identifier)) { - _pointStepSize = static_cast(dictionary.value(PointStepSizeInfo.identifier)); - } - - if (dictionary.hasKeyAndValue(PointScaleFactorInfo.identifier)) { - _pointScaleFactor = static_cast(dictionary.value(PointScaleFactorInfo.identifier)); - } - if (dictionary.hasKeyAndValue(EnabledPointsRatioInfo.identifier)) { _enabledPointsRatio = static_cast(dictionary.value(EnabledPointsRatioInfo.identifier)); } @@ -199,6 +175,15 @@ namespace openspace { } else { LERROR("No points filename specified."); } + + std::string pointSpreadFunctionTexturePath; + if (pointsDictionary.getValue("Texture", pointSpreadFunctionTexturePath)) { + _pointSpreadFunctionTexturePath = absPath(pointSpreadFunctionTexturePath); + _pointSpreadFunctionFile = std::make_unique(_pointSpreadFunctionTexturePath); + } + else { + LERROR("No points filename specified."); + } } void RenderableGalaxy::initializeGL() { @@ -247,8 +232,6 @@ void RenderableGalaxy::initializeGL() { addProperty(_stepSize); addProperty(_absorptionMultiply); addProperty(_emissionMultiply); - addProperty(_pointStepSize); - addProperty(_pointScaleFactor); addProperty(_enabledPointsRatio); addProperty(_translation); addProperty(_rotation); @@ -262,6 +245,27 @@ void RenderableGalaxy::initializeGL() { absPath("${MODULE_GALAXY}/shaders/points_ge.glsl") ); + if (!_pointSpreadFunctionTexturePath.empty()) { + _pointSpreadFunctionTexture = ghoul::io::TextureReader::ref().loadTexture( + absPath(_pointSpreadFunctionTexturePath) + ); + + if (_pointSpreadFunctionTexture) { + LDEBUG(fmt::format( + "Loaded texture from '{}'", + absPath(_pointSpreadFunctionTexturePath) + )); + _pointSpreadFunctionTexture->uploadTexture(); + } + _pointSpreadFunctionTexture->setFilter( + ghoul::opengl::Texture::FilterMode::AnisotropicMipMap + ); + + _pointSpreadFunctionFile = std::make_unique( + _pointSpreadFunctionTexturePath + ); + } + ghoul::opengl::updateUniformLocations(*_pointsProgram, _uniformCache, UniformNames); _pointsProgram->setIgnoreUniformLocationError( @@ -292,7 +296,7 @@ void RenderableGalaxy::initializeGL() { // Read points float x, y, z, r, g, b, a; - for (size_t i = 0; i < static_cast(_nPoints * 0.1) + 1; ++i) { + for (size_t i = 0; i < static_cast(_nPoints * _enabledPointsRatio.maxValue()) + 1; ++i) { std::getline(pointFile, line); std::istringstream issp(line); issp >> x >> y >> z >> r >> g >> b >> a; @@ -472,37 +476,18 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { glm::dmat4 cameraViewProjectionMatrix = projectionMatrix * data.camera.combinedViewMatrix(); - - /*glm::mat4 modelMatrix = _pointTransform; - glm::mat4 viewMatrix = data.camera.combinedViewMatrix(); - glm::mat4 projectionMatrix = data.camera.projectionMatrix(); - - _pointsProgram->setUniform("model", modelMatrix); - _pointsProgram->setUniform("view", viewMatrix); - _pointsProgram->setUniform("projection", projectionMatrix);*/ - - /*glm::dmat4 modelTransform = - glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * - glm::dmat4(data.modelTransform.rotation) * - glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)) * - glm::dmat4(_pointTransform); - - glm::mat4 modelViewTransform = viewMatrix * modelMatrix; - - _pointsProgram->setUniform("modelViewTransform", modelViewTransform); - _pointsProgram->setUniform("viewProjection", data.camera.viewProjectionMatrix());*/ - _pointsProgram->setUniform(_uniformCache.modelMatrix, modelMatrix); _pointsProgram->setUniform( _uniformCache.cameraViewProjectionMatrix, cameraViewProjectionMatrix ); float emittanceFactor = _opacityCoefficient * static_cast(_volumeSize).x; + ghoul::opengl::TextureUnit psfUnit; + psfUnit.activate(); + _pointSpreadFunctionTexture->bind(); + _pointsProgram->setUniform(_uniformCache.psfTexture, psfUnit); _pointsProgram->setUniform(_uniformCache.emittanceFactor, emittanceFactor); - /*_pointsProgram->setUniform("scaleFactor", _pointScaleFactor); - _pointsProgram->setUniform("emittanceFactor", emittanceFactor);*/ - glBindVertexArray(_pointsVao); glDrawArrays(GL_POINTS, 0, static_cast(_nPoints * _enabledPointsRatio)); @@ -527,37 +512,4 @@ float RenderableGalaxy::safeLength(const glm::vec3& vector) const { return glm::length(vector / maxComponent) * maxComponent; } -/*void RenderableGalaxy::postRender(const RenderData& data) { - - _raycaster->setStepSize(_pointStepSize); - - _pointsProgram->activate(); - setPscUniforms(*_pointsProgram.get(), data.camera, data.position); - - OsEng.ref().renderEngine().preRaycast(*_pointsProgram); - - glm::mat4 modelMatrix = _pointTransform; - glm::mat4 viewMatrix = data.camera.viewMatrix(); - glm::mat4 projectionMatrix = data.camera.projectionMatrix(); - - _pointsProgram->setUniform("model", modelMatrix); - _pointsProgram->setUniform("view", viewMatrix); - _pointsProgram->setUniform("projection", projectionMatrix); - - float emittanceFactor = _opacityCoefficient * static_cast(_volumeSize).x; - _pointsProgram->setUniform("emittanceFactor", emittanceFactor); - - glBindVertexArray(_pointsVao); - glDisable(GL_DEPTH_TEST); - glDepthMask(false); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glDrawArrays(GL_POINTS, 0, _nPoints * _enabledPointsRatio); - glBindVertexArray(0); - glDepthMask(true); - glEnable(GL_DEPTH_TEST); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - OsEng.ref().renderEngine().postRaycast(*_pointsProgram); -}*/ - } // namespace openspace diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index b4ae9c57f4..3bb36b8fad 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -62,15 +62,17 @@ private: properties::FloatProperty _stepSize; properties::FloatProperty _absorptionMultiply; properties::FloatProperty _emissionMultiply; - properties::FloatProperty _pointStepSize; - properties::FloatProperty _pointScaleFactor; properties::FloatProperty _enabledPointsRatio; properties::Vec3Property _translation; properties::Vec3Property _rotation; + std::unique_ptr _pointSpreadFunctionTexture; + std::unique_ptr _pointSpreadFunctionFile; + std::string _volumeFilename; glm::ivec3 _volumeDimensions; std::string _pointsFilename; + std::string _pointSpreadFunctionTexturePath; std::unique_ptr _raycaster; std::unique_ptr>> _volume; @@ -82,7 +84,7 @@ private: std::unique_ptr _pointsProgram; UniformCache( modelMatrix, cameraUp, eyePosition, cameraViewProjectionMatrix, - emittanceFactor + emittanceFactor, psfTexture ) _uniformCache; std::vector _pointsData; size_t _nPoints; diff --git a/modules/galaxy/shaders/galaxyraycast.glsl b/modules/galaxy/shaders/galaxyraycast.glsl index 7135a08c13..d3da09d2b4 100644 --- a/modules/galaxy/shaders/galaxyraycast.glsl +++ b/modules/galaxy/shaders/galaxyraycast.glsl @@ -1,26 +1,26 @@ /***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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-2019 * +* * +* 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. * +****************************************************************************************/ uniform float maxStepSize#{id} = 0.1; uniform vec3 aspect#{id} = vec3(1.0); @@ -30,52 +30,52 @@ uniform float emissionMultiply#{id} = 1500.0; uniform sampler3D galaxyTexture#{id}; void sample#{id}(vec3 samplePos, - vec3 dir, - inout vec3 accumulatedColor, - inout vec3 accumulatedAlpha, - inout float maxStepSize) -{ - //Speed up and border edge artifact fix - vec3 normalizedPos = (samplePos*2.0)-1.0; - if(abs(normalizedPos.x) > 0.8 || abs(normalizedPos.y) > 0.8){ - //accumulatedAlpha = vec3(0.0); - return; - } + vec3 dir, + inout vec3 accumulatedColor, + inout vec3 accumulatedAlpha, + inout float maxStepSize) + { + //Speed up and border edge artifact fix + vec3 normalizedPos = (samplePos*2.0)-1.0; + if(abs(normalizedPos.x) > 0.8 || abs(normalizedPos.y) > 0.8){ + //accumulatedAlpha = vec3(0.0); + return; + } vec3 aspect = aspect#{id}; maxStepSize = maxStepSize#{id} / length(dir / aspect); vec4 sampledColor = texture(galaxyTexture#{id}, samplePos.xyz); - //float STEP_SIZE = maxStepSize#{id}*0.5; - float STEP_SIZE = 1 / 256.0; + float STEP_SIZE = maxStepSize#{id}*0.5; + //float STEP_SIZE = 1 / 256.0; vec3 alphaTint = vec3(0.3, 0.54, 0.85); - // Source textures currently are square-rooted to avoid dithering in the shadows. - // So square them back + // Source textures currently are square-rooted to avoid dithering in the shadows. + // So square them back sampledColor = sampledColor*sampledColor; - // fudge for the dust "spreading" - sampledColor.a = clamp(sampledColor.a, 0.0, 1.0) * opacityCoefficient#{id}; + // fudge for the dust "spreading" + sampledColor.a = clamp(sampledColor.a, 0.0, 1.0) * opacityCoefficient#{id}; sampledColor.a = pow(sampledColor.a, 0.7); - // absorption probability - float scaled_density = sampledColor.a * STEP_SIZE * absorptionMultiply#{id}; - vec3 absorption = alphaTint * scaled_density; + // absorption probability + float scaled_density = sampledColor.a * STEP_SIZE * absorptionMultiply#{id}; + vec3 absorption = alphaTint * scaled_density; - // extinction - vec3 extinction = exp(-absorption); - accumulatedColor.rgb *= extinction; + // extinction + vec3 extinction = exp(-absorption); + accumulatedColor.rgb *= extinction; - // emission - accumulatedColor.rgb += sampledColor.rgb * STEP_SIZE * emissionMultiply#{id}; + // emission + accumulatedColor.rgb += sampledColor.rgb * STEP_SIZE * emissionMultiply#{id}; - vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha; + vec3 oneMinusFrontAlpha = vec3(1.0) - accumulatedAlpha; //accumulatedColor += oneMinusFrontAlpha * sampledColor.rgb; - accumulatedAlpha += oneMinusFrontAlpha * sampledColor.rgb; -} + accumulatedAlpha += oneMinusFrontAlpha * sampledColor.rgb; + } -float stepSize#{id}(vec3 samplePos, vec3 dir) { + float stepSize#{id}(vec3 samplePos, vec3 dir) { return maxStepSize#{id} * length(dir * 1.0 / aspect#{id}); -} + } diff --git a/modules/galaxy/shaders/points_fs.glsl b/modules/galaxy/shaders/points_fs.glsl index b9f49f7c0d..beb563f8e1 100644 --- a/modules/galaxy/shaders/points_fs.glsl +++ b/modules/galaxy/shaders/points_fs.glsl @@ -25,29 +25,26 @@ #include "fragment.glsl" #include "floatoperations.glsl" +uniform sampler2D psfTexture; +uniform float emittanceFactor; + in vec4 vs_position; +in vec2 psfCoords; in vec3 ge_color; in float ge_screenSpaceDepth; -uniform float emittanceFactor; - Fragment getFragment() { Fragment frag; - //frag.depth = vs_screenSpaceDepth; - //float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(ge_screenSpaceDepth)); - float coefficient = exp(1.38 * log(0.2) - 2*log(ge_screenSpaceDepth)); - frag.color = vec4(ge_color, 1.0)*emittanceFactor; - //frag.gPosition = vec4(vs_position, 1.0); - //frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); + vec4 textureColor = texture(psfTexture, 0.5*psfCoords + 0.5); + vec4 fullColor = vec4(ge_color*textureColor.a, textureColor.a); + fullColor.a *= emittanceFactor; + if (fullColor.a == 0) { + discard; + } + frag.color = fullColor; - //frag.color = vec4(1.0, 0.0, 0.0, 1.0); - //frag.depth = depth; - //frag.blend = BLEND_MODE_ADDITIVE; - - //float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(ge_screenSpaceDepth)); - //frag.color = vec4(ge_color.rgb * coefficient, 1.0); frag.depth = ge_screenSpaceDepth; frag.gPosition = vs_position; frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); From 03543d8fe475942581e235eacb6b99cb1c4ef96c Mon Sep 17 00:00:00 2001 From: eriksunden Date: Fri, 16 Aug 2019 13:35:46 +0200 Subject: [PATCH 09/42] Can now choose point or billboard for star rendering in galaxy module, point is preferred due to massive better performance. Time for HDR :). --- modules/galaxy/CMakeLists.txt | 3 + modules/galaxy/rendering/renderablegalaxy.cpp | 190 +++++++++++++++--- modules/galaxy/rendering/renderablegalaxy.h | 16 +- modules/galaxy/shaders/billboard_fs.glsl | 52 +++++ modules/galaxy/shaders/billboard_ge.glsl | 101 ++++++++++ modules/galaxy/shaders/billboard_vs.glsl | 36 ++++ modules/galaxy/shaders/points_fs.glsl | 16 +- modules/galaxy/shaders/points_vs.glsl | 52 ++--- 8 files changed, 389 insertions(+), 77 deletions(-) create mode 100644 modules/galaxy/shaders/billboard_fs.glsl create mode 100644 modules/galaxy/shaders/billboard_ge.glsl create mode 100644 modules/galaxy/shaders/billboard_vs.glsl diff --git a/modules/galaxy/CMakeLists.txt b/modules/galaxy/CMakeLists.txt index 58719e8e65..48b3d68d12 100644 --- a/modules/galaxy/CMakeLists.txt +++ b/modules/galaxy/CMakeLists.txt @@ -44,6 +44,9 @@ source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/shaders/galaxyraycast.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/billboard_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/billboard_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/billboard_ge.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/points_fs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/points_vs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/raycasterbounds_fs.glsl diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index be8bb1df03..90bc81450b 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -54,9 +54,24 @@ namespace { "${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl"; constexpr const char* _loggerCat = "Renderable Galaxy"; - constexpr const std::array UniformNames = { - "modelMatrix", "cameraUp", "eyePosition", "cameraViewProjectionMatrix", - "emittanceFactor", "psfTexture" + constexpr const std::array UniformNamesPoints = { + "modelMatrix", "cameraViewProjectionMatrix", "emittanceFactor" + }; + constexpr const std::array UniformNamesBillboards = { + "modelMatrix", "cameraViewProjectionMatrix", "emittanceFactor", + "cameraUp", "eyePosition", "psfTexture" + }; + + constexpr openspace::properties::Property::PropertyInfo VolumeRenderingEnabledInfo = { + "VolumeRenderingEnabled", + "Volume Rendering", + "" // @TODO Missing documentation + }; + + constexpr openspace::properties::Property::PropertyInfo StarRenderingEnabledInfo = { + "StarRenderingEnabled", + "Star Rendering", + "" // @TODO Missing documentation }; constexpr openspace::properties::Property::PropertyInfo StepSizeInfo = { @@ -89,6 +104,12 @@ namespace { "" // @TODO Missing documentation }; + constexpr openspace::properties::Property::PropertyInfo StarRenderingMethodInfo = { + "StarRenderingMethod", + "Star Rendering Method", + "This value determines which rendering method is used for visualization of the stars." + }; + constexpr openspace::properties::Property::PropertyInfo EnabledPointsRatioInfo = { "NEnabledPointsRatio", "Enabled points", @@ -100,20 +121,34 @@ namespace openspace { RenderableGalaxy::RenderableGalaxy(const ghoul::Dictionary& dictionary) : Renderable(dictionary) + , _volumeRenderingEnabled(VolumeRenderingEnabledInfo, true) + , _starRenderingEnabled(StarRenderingEnabledInfo, true) , _stepSize(StepSizeInfo, 0.01f, 0.0005f, 0.05f, 0.001f) , _absorptionMultiply(AbsorptionMultiplyInfo, 40.f, 0.0f, 100.0f) , _emissionMultiply(EmissionMultiplyInfo, 400.f, 0.0f, 1000.0f) - , _enabledPointsRatio(EnabledPointsRatioInfo, 0.02f, 0.001f, 0.1f) + , _starRenderingMethod(StarRenderingMethodInfo, properties::OptionProperty::DisplayType::Dropdown) + , _enabledPointsRatio(EnabledPointsRatioInfo, 0.5f, 0.01f, 1.0f) , _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(1.f)) , _rotation(RotationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(6.28f)) { + dictionary.getValue("VolumeRenderingEnabled", _volumeRenderingEnabled); + dictionary.getValue("StarRenderingEnabled", _starRenderingEnabled); dictionary.getValue("StepSize", _stepSize); dictionary.getValue("AbsorptionMultiply", _absorptionMultiply); dictionary.getValue("EmissionMultiply", _emissionMultiply); + dictionary.getValue("StarRenderingMethod", _starRenderingMethod); dictionary.getValue("EnabledPointsRatio", _enabledPointsRatio); dictionary.getValue("Translation", _translation); dictionary.getValue("Rotation", _rotation); + if (dictionary.hasKeyAndValue(VolumeRenderingEnabledInfo.identifier)) { + _volumeRenderingEnabled = dictionary.value(VolumeRenderingEnabledInfo.identifier); + } + + if (dictionary.hasKeyAndValue(StarRenderingEnabledInfo.identifier)) { + _starRenderingEnabled = static_cast(StarRenderingEnabledInfo.identifier); + } + if (dictionary.hasKeyAndValue(StepSizeInfo.identifier)) { _stepSize = static_cast(dictionary.value(StepSizeInfo.identifier)); } @@ -126,6 +161,22 @@ namespace openspace { _emissionMultiply = static_cast(dictionary.value(EmissionMultiplyInfo.identifier)); } + _starRenderingMethod.addOptions({ + { 0, "Points" }, + { 1, "Billboards" } + }); + if (dictionary.hasKey(StarRenderingMethodInfo.identifier)) { + const std::string starRenderingMethod = dictionary.value( + StarRenderingMethodInfo.identifier + ); + if (starRenderingMethod == "Points") { + _starRenderingMethod = 0; + } + else if (starRenderingMethod == "Billboards") { + _starRenderingMethod = 1; + } + } + if (dictionary.hasKeyAndValue(EnabledPointsRatioInfo.identifier)) { _enabledPointsRatio = static_cast(dictionary.value(EnabledPointsRatioInfo.identifier)); } @@ -229,9 +280,12 @@ void RenderableGalaxy::initializeGL() { onEnabledChange(onChange); + addProperty(_volumeRenderingEnabled); + addProperty(_starRenderingEnabled); addProperty(_stepSize); addProperty(_absorptionMultiply); addProperty(_emissionMultiply); + addProperty(_starRenderingMethod); addProperty(_enabledPointsRatio); addProperty(_translation); addProperty(_rotation); @@ -241,8 +295,13 @@ void RenderableGalaxy::initializeGL() { _pointsProgram = global::renderEngine.buildRenderProgram( "Galaxy points", absPath("${MODULE_GALAXY}/shaders/points_vs.glsl"), - absPath("${MODULE_GALAXY}/shaders/points_fs.glsl"), - absPath("${MODULE_GALAXY}/shaders/points_ge.glsl") + absPath("${MODULE_GALAXY}/shaders/points_fs.glsl") + ); + _billboardsProgram = global::renderEngine.buildRenderProgram( + "Galaxy billboard", + absPath("${MODULE_GALAXY}/shaders/billboard_vs.glsl"), + absPath("${MODULE_GALAXY}/shaders/billboard_fs.glsl"), + absPath("${MODULE_GALAXY}/shaders/billboard_ge.glsl") ); if (!_pointSpreadFunctionTexturePath.empty()) { @@ -266,7 +325,8 @@ void RenderableGalaxy::initializeGL() { ); } - ghoul::opengl::updateUniformLocations(*_pointsProgram, _uniformCache, UniformNames); + ghoul::opengl::updateUniformLocations(*_pointsProgram, _uniformCachePoints, UniformNamesPoints); + ghoul::opengl::updateUniformLocations(*_billboardsProgram, _uniformCacheBillboards, UniformNamesBillboards); _pointsProgram->setIgnoreUniformLocationError( ghoul::opengl::ProgramObject::IgnoreError::Yes @@ -391,7 +451,8 @@ void RenderableGalaxy::update(const UpdateData& data) { } void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { - if (_raycaster) { + // Render the volume + if (_raycaster && _volumeRenderingEnabled) { RaycasterTask task { _raycaster.get(), data }; const glm::vec3 position = data.camera.positionVec3(); @@ -432,6 +493,18 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { } } + // Render the stars + if (_starRenderingEnabled) { + if (_starRenderingMethod == 1) { + renderBillboards(data); + } + else { + renderPoints(data); + } + } +} + +void RenderableGalaxy::renderPoints(const RenderData& data) { if (_pointsProgram) { // Saving current OpenGL state GLenum blendEquationRGB; @@ -453,19 +526,10 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { glBlendFunc(GL_SRC_ALPHA, GL_ONE); glDepthMask(false); + glDisable(GL_DEPTH_TEST); _pointsProgram->activate(); - glm::dvec3 eyePosition = glm::dvec3( - glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0) - ); - _pointsProgram->setUniform(_uniformCache.eyePosition, eyePosition); - - glm::dvec3 cameraUp = data.camera.lookUpVectorWorldSpace(); - _pointsProgram->setUniform(_uniformCache.cameraUp, cameraUp); - - const glm::dvec3 dtranslation = glm::dvec3((double)_translation.value().x, (double)_translation.value().y, (double)_translation.value().z); - glm::dmat4 modelMatrix = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * glm::dmat4(data.modelTransform.rotation) * @@ -476,25 +540,99 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { glm::dmat4 cameraViewProjectionMatrix = projectionMatrix * data.camera.combinedViewMatrix(); - _pointsProgram->setUniform(_uniformCache.modelMatrix, modelMatrix); + _pointsProgram->setUniform(_uniformCachePoints.modelMatrix, modelMatrix); _pointsProgram->setUniform( - _uniformCache.cameraViewProjectionMatrix, + _uniformCachePoints.cameraViewProjectionMatrix, cameraViewProjectionMatrix ); + float emittanceFactor = _opacityCoefficient * static_cast(_volumeSize).x; - ghoul::opengl::TextureUnit psfUnit; - psfUnit.activate(); - _pointSpreadFunctionTexture->bind(); - _pointsProgram->setUniform(_uniformCache.psfTexture, psfUnit); - _pointsProgram->setUniform(_uniformCache.emittanceFactor, emittanceFactor); + _pointsProgram->setUniform(_uniformCachePoints.emittanceFactor, emittanceFactor); glBindVertexArray(_pointsVao); glDrawArrays(GL_POINTS, 0, static_cast(_nPoints * _enabledPointsRatio)); glBindVertexArray(0); - + _pointsProgram->deactivate(); + glEnable(GL_DEPTH_TEST); + glDepthMask(true); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + // Restores OpenGL blending state + glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha); + glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha); + glDepthMask(depthMask); + } +} + +void RenderableGalaxy::renderBillboards(const RenderData& data) { + if (_billboardsProgram) { + // Saving current OpenGL state + GLenum blendEquationRGB; + GLenum blendEquationAlpha; + GLenum blendDestAlpha; + GLenum blendDestRGB; + GLenum blendSrcAlpha; + GLenum blendSrcRGB; + GLboolean depthMask; + + glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB); + glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha); + glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha); + glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB); + glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha); + glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB); + + glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glDepthMask(false); + glDisable(GL_DEPTH_TEST); + + _billboardsProgram->activate(); + + glm::dmat4 modelMatrix = + 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))); + + glm::dmat4 projectionMatrix = glm::dmat4(data.camera.projectionMatrix()); + + glm::dmat4 cameraViewProjectionMatrix = projectionMatrix * + data.camera.combinedViewMatrix(); + + _billboardsProgram->setUniform(_uniformCacheBillboards.modelMatrix, modelMatrix); + _billboardsProgram->setUniform( + _uniformCacheBillboards.cameraViewProjectionMatrix, + cameraViewProjectionMatrix + ); + + float emittanceFactor = _opacityCoefficient * static_cast(_volumeSize).x; + _billboardsProgram->setUniform(_uniformCacheBillboards.emittanceFactor, emittanceFactor); + + glm::dvec3 eyePosition = glm::dvec3( + glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0) + ); + _billboardsProgram->setUniform(_uniformCacheBillboards.eyePosition, eyePosition); + + glm::dvec3 cameraUp = data.camera.lookUpVectorWorldSpace(); + _billboardsProgram->setUniform(_uniformCacheBillboards.cameraUp, cameraUp); + + ghoul::opengl::TextureUnit psfUnit; + psfUnit.activate(); + _pointSpreadFunctionTexture->bind(); + _billboardsProgram->setUniform(_uniformCacheBillboards.psfTexture, psfUnit); + + glBindVertexArray(_pointsVao); + glDrawArrays(GL_POINTS, 0, static_cast(_nPoints * _enabledPointsRatio)); + + glBindVertexArray(0); + + _billboardsProgram->deactivate(); + + glEnable(GL_DEPTH_TEST); glDepthMask(true); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index 3bb36b8fad..777e15918b 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -55,13 +56,18 @@ public: void update(const UpdateData& data) override; private: + void renderPoints(const RenderData& data); + void renderBillboards(const RenderData& data); float safeLength(const glm::vec3& vector) const; glm::vec3 _volumeSize; glm::vec3 _pointScaling; + properties::BoolProperty _volumeRenderingEnabled; + properties::BoolProperty _starRenderingEnabled; properties::FloatProperty _stepSize; properties::FloatProperty _absorptionMultiply; properties::FloatProperty _emissionMultiply; + properties::OptionProperty _starRenderingMethod; properties::FloatProperty _enabledPointsRatio; properties::Vec3Property _translation; properties::Vec3Property _rotation; @@ -82,10 +88,14 @@ private: float _opacityCoefficient; std::unique_ptr _pointsProgram; + std::unique_ptr _billboardsProgram; UniformCache( - modelMatrix, cameraUp, eyePosition, cameraViewProjectionMatrix, - emittanceFactor, psfTexture - ) _uniformCache; + modelMatrix, cameraViewProjectionMatrix, emittanceFactor + ) _uniformCachePoints; + UniformCache( + modelMatrix, cameraViewProjectionMatrix, emittanceFactor, + cameraUp, eyePosition, psfTexture + ) _uniformCacheBillboards; std::vector _pointsData; size_t _nPoints; GLuint _pointsVao; diff --git a/modules/galaxy/shaders/billboard_fs.glsl b/modules/galaxy/shaders/billboard_fs.glsl new file mode 100644 index 0000000000..9e873c4575 --- /dev/null +++ b/modules/galaxy/shaders/billboard_fs.glsl @@ -0,0 +1,52 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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. * + ****************************************************************************************/ + +#include "fragment.glsl" +#include "floatoperations.glsl" + +uniform sampler2D psfTexture; +uniform float emittanceFactor; + +in vec4 vs_position; +in vec2 psfCoords; +in vec3 ge_color; +in float ge_screenSpaceDepth; + +Fragment getFragment() { + Fragment frag; + + vec4 textureColor = texture(psfTexture, 0.5*psfCoords + 0.5); + vec4 fullColor = vec4(ge_color*textureColor.a, textureColor.a); + fullColor.a *= emittanceFactor; + if (fullColor.a == 0) { + discard; + } + frag.color = fullColor; + + frag.depth = ge_screenSpaceDepth; + frag.gPosition = vs_position; + frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); + + return frag; +} diff --git a/modules/galaxy/shaders/billboard_ge.glsl b/modules/galaxy/shaders/billboard_ge.glsl new file mode 100644 index 0000000000..d57daee59a --- /dev/null +++ b/modules/galaxy/shaders/billboard_ge.glsl @@ -0,0 +1,101 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ + +#include "floatoperations.glsl" +#include "PowerScaling/powerScalingMath.hglsl" + +uniform dvec3 eyePosition; +uniform dvec3 cameraUp; +uniform dmat4 cameraViewProjectionMatrix; +uniform dmat4 modelMatrix; + +layout(points) in; +layout(triangle_strip, max_vertices = 4) out; + +in vec4 vs_gPosition[]; +in vec3 vs_color[]; + +out vec4 vs_position; +out vec2 psfCoords; +flat out vec3 ge_color; +flat out float ge_screenSpaceDepth; + +const double PARSEC = 3.08567756E16; + +void main() { + vs_position = gl_in[0].gl_Position; // in object space + ge_color = vs_color[0]; + + double scaleMultiply = 8.0; + + dvec4 dpos = dvec4(vs_position); + dpos.xyz *= scaleMultiply; + dpos = modelMatrix * dpos; + dpos /= PARSEC; + //It lies about 8 kpc from the center on what is known as the Orion Arm of the Milky Way + dpos.x += 8000; + + scaleMultiply *= 4.0; + dvec3 scaledRight = dvec3(0.0); + dvec3 scaledUp = dvec3(0.0); + vec4 bottomLeftVertex, bottomRightVertex, topLeftVertex, topRightVertex; + + dvec3 normal = normalize(eyePosition - dpos.xyz); + dvec3 newRight = normalize(cross(cameraUp, normal)); + dvec3 newUp = cross(normal, newRight); + scaledRight = scaleMultiply * newRight; + scaledUp = scaleMultiply * newUp; + + bottomLeftVertex = z_normalization(vec4(cameraViewProjectionMatrix * + dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w))); + + //dvec4 dposCamera = cameraViewProjectionMatrix * dpos; + //ge_screenSpaceDepth = float(length(eyePosition - dposCamera.xyz)/PARSEC); + ge_screenSpaceDepth = bottomLeftVertex.w; + + topRightVertex = z_normalization(vec4(cameraViewProjectionMatrix * + dvec4(dpos.xyz + scaledUp + scaledRight, dpos.w))); + + bottomRightVertex = z_normalization(vec4(cameraViewProjectionMatrix * + dvec4(dpos.xyz + scaledRight - scaledUp, dpos.w))); + topLeftVertex = z_normalization(vec4(cameraViewProjectionMatrix * + dvec4(dpos.xyz + scaledUp - scaledRight, dpos.w))); + + // Build primitive + gl_Position = topLeftVertex; + psfCoords = vec2(-1.0, 1.0); + EmitVertex(); + gl_Position = bottomLeftVertex; + psfCoords = vec2(-1.0, -1.0); + EmitVertex(); + gl_Position = topRightVertex; + psfCoords = vec2(1.0, 1.0); + EmitVertex(); + gl_Position = bottomRightVertex; + psfCoords = vec2(1.0, -1.0); + EmitVertex(); + EndPrimitive(); +} diff --git a/modules/galaxy/shaders/billboard_vs.glsl b/modules/galaxy/shaders/billboard_vs.glsl new file mode 100644 index 0000000000..2893bccdd7 --- /dev/null +++ b/modules/galaxy/shaders/billboard_vs.glsl @@ -0,0 +1,36 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ + +layout(location = 0) in vec3 in_position; +layout(location = 1) in vec3 in_color; + +out vec3 vs_color; + +void main() { + vs_color = in_color; + + gl_Position = vec4(in_position, 1.0); +} diff --git a/modules/galaxy/shaders/points_fs.glsl b/modules/galaxy/shaders/points_fs.glsl index beb563f8e1..4b89541b83 100644 --- a/modules/galaxy/shaders/points_fs.glsl +++ b/modules/galaxy/shaders/points_fs.glsl @@ -25,27 +25,19 @@ #include "fragment.glsl" #include "floatoperations.glsl" -uniform sampler2D psfTexture; uniform float emittanceFactor; in vec4 vs_position; -in vec2 psfCoords; -in vec3 ge_color; -in float ge_screenSpaceDepth; +in vec3 vs_color; +in float vs_screenSpaceDepth; Fragment getFragment() { Fragment frag; - //float coefficient = exp(1.38 * log(emittanceFactor) - 2*log(ge_screenSpaceDepth)); - vec4 textureColor = texture(psfTexture, 0.5*psfCoords + 0.5); - vec4 fullColor = vec4(ge_color*textureColor.a, textureColor.a); - fullColor.a *= emittanceFactor; - if (fullColor.a == 0) { - discard; - } + vec4 fullColor = vec4(vs_color, emittanceFactor); frag.color = fullColor; - frag.depth = ge_screenSpaceDepth; + frag.depth = vs_screenSpaceDepth; frag.gPosition = vs_position; frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/modules/galaxy/shaders/points_vs.glsl b/modules/galaxy/shaders/points_vs.glsl index 90ee876d6f..38283272cb 100644 --- a/modules/galaxy/shaders/points_vs.glsl +++ b/modules/galaxy/shaders/points_vs.glsl @@ -24,52 +24,32 @@ #version __CONTEXT__ -//#include "PowerScaling/powerScaling_vs.hglsl" +#include "PowerScaling/powerScaling_vs.hglsl" layout(location = 0) in vec3 in_position; layout(location = 1) in vec3 in_color; -//out vec3 vs_position; +out vec4 vs_position; out vec3 vs_color; -//out float vs_screenSpaceDepth; +out float vs_screenSpaceDepth; -//uniform mat4 model; -//uniform mat4 view; -//uniform mat4 projection; -//uniform float scaleFactor; +uniform dmat4 cameraViewProjectionMatrix; +uniform dmat4 modelMatrix; -//uniform mat4 viewProjection; -//uniform mat4 modelViewTransform; +const double PARSEC = 3.08567756E16; void main() { - /*vec4 worldPosition = model * vec4(in_position, 1.0); - worldPosition.w = 0.0; - vec4 position = worldPosition; //pscTransform(worldPosition, model); - position = pscTransform(position, mat4(1.0)); - vs_position = position.xyz; - position = projection * view * position; - gl_Position = position;*/ + vs_position = vec4(in_position, 1.0); + dvec4 dpos = dvec4(vs_position); + dpos.xyz *= 8.0; + dpos = modelMatrix * dpos; + dpos /= PARSEC; + //It lies about 8 kpc from the center on what is known as the Orion Arm of the Milky Way + dpos.x += 8000; - /*vec4 tmp = vec4(inPosition, 0.0); - vsPosition = inPosition; - vec4 position = pscTransform(tmp, model); - position = projection * view * position; - gl_Position = z_normalization(position);*/ + vec4 positionScreenSpace = z_normalization(vec4(cameraViewProjectionMatrix * dpos)); - //vs_position = (modelViewTransform * vec4(in_position, 1.0)).xyz; - //vs_position = in_position; vs_color = in_color; - - /*vec4 positionClipSpace = vec4(projection * view * model * vec4(in_position, 1.0)); - vec4 positionScreenSpace = vec4(z_normalization(positionClipSpace)); - vs_screenSpaceDepth = positionScreenSpace.w;*/ - //vs_screenSpaceDepth = 1.0; - - //gl_PointSize = scaleFactor; - //gl_Position = positionScreenSpace; - - // project the position to view space - //gl_Position = viewProjection * vec4(vs_position, 1.0); - gl_Position = vec4(in_position, 1.0); - //gl_Position.z = 1.0; + vs_screenSpaceDepth = positionScreenSpace.w; + gl_Position = positionScreenSpace; } From 3d0d44649799e632e527fcde556f528a3c0d012b Mon Sep 17 00:00:00 2001 From: eriksunden Date: Fri, 16 Aug 2019 14:58:08 +0200 Subject: [PATCH 10/42] Fixes for emiitance and volume cut (still weird that it disappears). --- modules/galaxy/rendering/renderablegalaxy.cpp | 14 ++++---------- modules/galaxy/rendering/renderablegalaxy.h | 4 ++-- modules/galaxy/shaders/billboard_fs.glsl | 2 -- modules/galaxy/shaders/points_fs.glsl | 4 +--- modules/galaxy/shaders/raycasterbounds_vs.glsl | 6 +++--- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index 90bc81450b..e6893af17b 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -54,11 +54,11 @@ namespace { "${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl"; constexpr const char* _loggerCat = "Renderable Galaxy"; - constexpr const std::array UniformNamesPoints = { - "modelMatrix", "cameraViewProjectionMatrix", "emittanceFactor" + constexpr const std::array UniformNamesPoints = { + "modelMatrix", "cameraViewProjectionMatrix" }; - constexpr const std::array UniformNamesBillboards = { - "modelMatrix", "cameraViewProjectionMatrix", "emittanceFactor", + constexpr const std::array UniformNamesBillboards = { + "modelMatrix", "cameraViewProjectionMatrix", "cameraUp", "eyePosition", "psfTexture" }; @@ -546,9 +546,6 @@ void RenderableGalaxy::renderPoints(const RenderData& data) { cameraViewProjectionMatrix ); - float emittanceFactor = _opacityCoefficient * static_cast(_volumeSize).x; - _pointsProgram->setUniform(_uniformCachePoints.emittanceFactor, emittanceFactor); - glBindVertexArray(_pointsVao); glDrawArrays(GL_POINTS, 0, static_cast(_nPoints * _enabledPointsRatio)); @@ -609,9 +606,6 @@ void RenderableGalaxy::renderBillboards(const RenderData& data) { cameraViewProjectionMatrix ); - float emittanceFactor = _opacityCoefficient * static_cast(_volumeSize).x; - _billboardsProgram->setUniform(_uniformCacheBillboards.emittanceFactor, emittanceFactor); - glm::dvec3 eyePosition = glm::dvec3( glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0) ); diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index 777e15918b..2b6e0510dd 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -90,10 +90,10 @@ private: std::unique_ptr _pointsProgram; std::unique_ptr _billboardsProgram; UniformCache( - modelMatrix, cameraViewProjectionMatrix, emittanceFactor + modelMatrix, cameraViewProjectionMatrix ) _uniformCachePoints; UniformCache( - modelMatrix, cameraViewProjectionMatrix, emittanceFactor, + modelMatrix, cameraViewProjectionMatrix, cameraUp, eyePosition, psfTexture ) _uniformCacheBillboards; std::vector _pointsData; diff --git a/modules/galaxy/shaders/billboard_fs.glsl b/modules/galaxy/shaders/billboard_fs.glsl index 9e873c4575..18fb39df76 100644 --- a/modules/galaxy/shaders/billboard_fs.glsl +++ b/modules/galaxy/shaders/billboard_fs.glsl @@ -26,7 +26,6 @@ #include "floatoperations.glsl" uniform sampler2D psfTexture; -uniform float emittanceFactor; in vec4 vs_position; in vec2 psfCoords; @@ -38,7 +37,6 @@ Fragment getFragment() { vec4 textureColor = texture(psfTexture, 0.5*psfCoords + 0.5); vec4 fullColor = vec4(ge_color*textureColor.a, textureColor.a); - fullColor.a *= emittanceFactor; if (fullColor.a == 0) { discard; } diff --git a/modules/galaxy/shaders/points_fs.glsl b/modules/galaxy/shaders/points_fs.glsl index 4b89541b83..cd667cf320 100644 --- a/modules/galaxy/shaders/points_fs.glsl +++ b/modules/galaxy/shaders/points_fs.glsl @@ -25,8 +25,6 @@ #include "fragment.glsl" #include "floatoperations.glsl" -uniform float emittanceFactor; - in vec4 vs_position; in vec3 vs_color; in float vs_screenSpaceDepth; @@ -34,7 +32,7 @@ in float vs_screenSpaceDepth; Fragment getFragment() { Fragment frag; - vec4 fullColor = vec4(vs_color, emittanceFactor); + vec4 fullColor = vec4(vs_color, 1.0); frag.color = fullColor; frag.depth = vs_screenSpaceDepth; diff --git a/modules/galaxy/shaders/raycasterbounds_vs.glsl b/modules/galaxy/shaders/raycasterbounds_vs.glsl index 09ee0ef1c7..304eaec1a2 100644 --- a/modules/galaxy/shaders/raycasterbounds_vs.glsl +++ b/modules/galaxy/shaders/raycasterbounds_vs.glsl @@ -21,7 +21,7 @@ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ - + #version __CONTEXT__ layout(location = 0) in vec4 vertPosition; @@ -36,8 +36,8 @@ uniform mat4 modelViewTransform; void main() { modelPosition = vertPosition.xyz; viewPosition = modelViewTransform*vertPosition; - + // project the position to view space gl_Position = viewProjection * viewPosition; - gl_Position.z = 1.0; + gl_Position.z = 0.0; } From 61157cb2e67fce92757d74045bb587f0dda03fa1 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Mon, 19 Aug 2019 11:05:03 +0200 Subject: [PATCH 11/42] Data moved to sync folder. Did set higher absorption/emission on the volume rendering as well. --- data/assets/customization/volumes.asset | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/data/assets/customization/volumes.asset b/data/assets/customization/volumes.asset index da77323480..01cc2ce054 100644 --- a/data/assets/customization/volumes.asset +++ b/data/assets/customization/volumes.asset @@ -3,26 +3,33 @@ local assetHelper = asset.require("util/asset_helper") local transforms = asset.require("scene/solarsystem/sun/transforms") +local data = asset.syncedResource({ + Name = "Milkyway Volume Data", + Type = "HttpSynchronization", + Identifier = "milkyway_volume_data", + Version = 1 +}) + local MilkyWayVolumeGalaxy = { Identifier = "Milky Way Volume", Parent = transforms.SolarSystemBarycenter.Identifier, Renderable = { Type = "RenderableGalaxy", StepSize = 0.01, - AbsorptionMultiply = 10, - EmissionMultiply = 100, + AbsorptionMultiply = 75, + EmissionMultiply = 200, Translation = {0.2, 0, 0}, Volume = { Type = "Volume", - Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayRGBAVolume1024x1024x128.raw", + Filename = data .. "/MilkyWayRGBAVolume1024x1024x128.raw", Dimensions = {1024, 1024, 128}, Size = {1.2E21, 1.2E21, 0.15E21} }, Points = { Type = "Points", - Filename = "${BASE}/../OpenSpaceData/Milkyway/MilkyWayPoints.off", + Filename = data .. "/MilkyWayPoints.off", Scaling = {1.0, 1.0, 1.0}, - Texture = "${BASE}/../OpenSpaceData/Milkyway/halo.png" + Texture = data .. "/halo.png" } }, GUI = { From a9fd242386d695de717fd5d964fe53de24d96824 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Mon, 19 Aug 2019 14:16:36 +0200 Subject: [PATCH 12/42] Fixed boundary artifacts in general for volume rendering. Look and feel of rendering is now very nice. Also the stars fade nicely now. --- data/assets/customization/volumes.asset | 2 +- modules/galaxy/rendering/renderablegalaxy.cpp | 13 +++++++---- modules/galaxy/rendering/renderablegalaxy.h | 2 +- modules/galaxy/shaders/galaxyraycast.glsl | 15 ++++++------ modules/galaxy/shaders/points_fs.glsl | 4 +++- modules/galaxy/shaders/points_vs.glsl | 23 ++++++++++++++----- .../galaxy/shaders/raycasterbounds_fs.glsl | 12 +++++++++- shaders/framebuffer/raycastframebuffer.frag | 8 ++++++- 8 files changed, 56 insertions(+), 23 deletions(-) diff --git a/data/assets/customization/volumes.asset b/data/assets/customization/volumes.asset index 01cc2ce054..29d1bd1773 100644 --- a/data/assets/customization/volumes.asset +++ b/data/assets/customization/volumes.asset @@ -28,7 +28,7 @@ local MilkyWayVolumeGalaxy = { Points = { Type = "Points", Filename = data .. "/MilkyWayPoints.off", - Scaling = {1.0, 1.0, 1.0}, + EnabledPointsRatio = 0.3, Texture = data .. "/halo.png" } }, diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index e6893af17b..7d14646e6f 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -54,8 +54,8 @@ namespace { "${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl"; constexpr const char* _loggerCat = "Renderable Galaxy"; - constexpr const std::array UniformNamesPoints = { - "modelMatrix", "cameraViewProjectionMatrix" + constexpr const std::array UniformNamesPoints = { + "modelMatrix", "cameraViewProjectionMatrix", "eyePosition" }; constexpr const std::array UniformNamesBillboards = { "modelMatrix", "cameraViewProjectionMatrix", @@ -111,7 +111,7 @@ namespace { }; constexpr openspace::properties::Property::PropertyInfo EnabledPointsRatioInfo = { - "NEnabledPointsRatio", + "EnabledPointsRatio", "Enabled points", "" // @TODO Missing documentation }; @@ -254,7 +254,7 @@ void RenderableGalaxy::initializeGL() { GL_RGBA, GL_UNSIGNED_BYTE, ghoul::opengl::Texture::FilterMode::Linear, - ghoul::opengl::Texture::WrappingMode::Clamp); + ghoul::opengl::Texture::WrappingMode::ClampToEdge); _texture->setPixelData(reinterpret_cast( _volume->data()), @@ -546,6 +546,11 @@ void RenderableGalaxy::renderPoints(const RenderData& data) { cameraViewProjectionMatrix ); + glm::dvec3 eyePosition = glm::dvec3( + glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0) + ); + _pointsProgram->setUniform(_uniformCachePoints.eyePosition, eyePosition); + glBindVertexArray(_pointsVao); glDrawArrays(GL_POINTS, 0, static_cast(_nPoints * _enabledPointsRatio)); diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index 2b6e0510dd..3bfd02163a 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -90,7 +90,7 @@ private: std::unique_ptr _pointsProgram; std::unique_ptr _billboardsProgram; UniformCache( - modelMatrix, cameraViewProjectionMatrix + modelMatrix, cameraViewProjectionMatrix, eyePosition ) _uniformCachePoints; UniformCache( modelMatrix, cameraViewProjectionMatrix, diff --git a/modules/galaxy/shaders/galaxyraycast.glsl b/modules/galaxy/shaders/galaxyraycast.glsl index d3da09d2b4..de987360bb 100644 --- a/modules/galaxy/shaders/galaxyraycast.glsl +++ b/modules/galaxy/shaders/galaxyraycast.glsl @@ -35,23 +35,22 @@ void sample#{id}(vec3 samplePos, inout vec3 accumulatedAlpha, inout float maxStepSize) { - //Speed up and border edge artifact fix - vec3 normalizedPos = (samplePos*2.0)-1.0; - if(abs(normalizedPos.x) > 0.8 || abs(normalizedPos.y) > 0.8){ - //accumulatedAlpha = vec3(0.0); - return; - } - vec3 aspect = aspect#{id}; maxStepSize = maxStepSize#{id} / length(dir / aspect); - vec4 sampledColor = texture(galaxyTexture#{id}, samplePos.xyz); + //Early ray termination on black parts of the data + vec3 normalizedPos = (samplePos*2.0)-1.0; + if(abs(normalizedPos.x) > 0.8 || abs(normalizedPos.y) > 0.8){ + return; + } float STEP_SIZE = maxStepSize#{id}*0.5; //float STEP_SIZE = 1 / 256.0; vec3 alphaTint = vec3(0.3, 0.54, 0.85); + vec4 sampledColor = texture(galaxyTexture#{id}, samplePos.xyz); + // Source textures currently are square-rooted to avoid dithering in the shadows. // So square them back sampledColor = sampledColor*sampledColor; diff --git a/modules/galaxy/shaders/points_fs.glsl b/modules/galaxy/shaders/points_fs.glsl index cd667cf320..368d4a1b79 100644 --- a/modules/galaxy/shaders/points_fs.glsl +++ b/modules/galaxy/shaders/points_fs.glsl @@ -28,11 +28,13 @@ in vec4 vs_position; in vec3 vs_color; in float vs_screenSpaceDepth; +in float vs_starBrightness; Fragment getFragment() { Fragment frag; - vec4 fullColor = vec4(vs_color, 1.0); + vec3 extinction = exp(vec3(0.6, 0.2, 0.3)-vs_color); + vec4 fullColor = vec4(vs_color*extinction*vs_starBrightness, 1.0); frag.color = fullColor; frag.depth = vs_screenSpaceDepth; diff --git a/modules/galaxy/shaders/points_vs.glsl b/modules/galaxy/shaders/points_vs.glsl index 38283272cb..8d9635921f 100644 --- a/modules/galaxy/shaders/points_vs.glsl +++ b/modules/galaxy/shaders/points_vs.glsl @@ -32,23 +32,34 @@ layout(location = 1) in vec3 in_color; out vec4 vs_position; out vec3 vs_color; out float vs_screenSpaceDepth; +out float vs_starBrightness; uniform dmat4 cameraViewProjectionMatrix; uniform dmat4 modelMatrix; +uniform dvec3 eyePosition; const double PARSEC = 3.08567756E16; void main() { vs_position = vec4(in_position, 1.0); dvec4 dpos = dvec4(vs_position); - dpos.xyz *= 8.0; - dpos = modelMatrix * dpos; - dpos /= PARSEC; - //It lies about 8 kpc from the center on what is known as the Orion Arm of the Milky Way - dpos.x += 8000; + + double distanceToStar = length((dpos.xyz - eyePosition)); + vs_starBrightness = clamp(float(8000*PARSEC/distanceToStar), 0.0, 1.0); + + // Discard stars if we are not seing the milky way volume + if(length(vec3(0.0)-eyePosition)<780*PARSEC){ + vs_starBrightness = 0.0; + } + else{ + dpos.xyz *= 8.0; + dpos = modelMatrix * dpos; + dpos /= PARSEC; + //It lies about 8 kpc from the center on what is known as the Orion Arm of the Milky Way + dpos.x += 8000; + } vec4 positionScreenSpace = z_normalization(vec4(cameraViewProjectionMatrix * dpos)); - vs_color = in_color; vs_screenSpaceDepth = positionScreenSpace.w; gl_Position = positionScreenSpace; diff --git a/modules/galaxy/shaders/raycasterbounds_fs.glsl b/modules/galaxy/shaders/raycasterbounds_fs.glsl index 6f1123a51d..7b54a237a2 100644 --- a/modules/galaxy/shaders/raycasterbounds_fs.glsl +++ b/modules/galaxy/shaders/raycasterbounds_fs.glsl @@ -30,7 +30,17 @@ in vec4 viewPosition; Fragment getFragment() { Fragment frag; - frag.color = vec4(modelPosition + 0.5, 1.0); + //Early ray termination on black parts of the data + /*vec3 normalizedPos = (modelPosition*2.0)-1.0; + if(abs(modelPosition.x) > 0.9 || abs(modelPosition.y) > 0.9){ + frag.color = vec4(0.0, 0.0, 0.0, 1.0); + } + else{*/ + vec3 pos = modelPosition + 0.5; + //vec3 posClamp = clamp(pos, vec3(0.0), vec3(1.0)); + frag.color = vec4(pos, 1.0); + //} + frag.depth = safeLength(viewPosition); return frag; } diff --git a/shaders/framebuffer/raycastframebuffer.frag b/shaders/framebuffer/raycastframebuffer.frag index a4ee03faf4..8b928888e0 100644 --- a/shaders/framebuffer/raycastframebuffer.frag +++ b/shaders/framebuffer/raycastframebuffer.frag @@ -56,7 +56,9 @@ void main() { vec2 texCoord = vec2(gl_FragCoord.xy / windowSize); vec4 exitColorTexture = texture(exitColorTexture, texCoord); - if (exitColorTexture.a < 1.0) { + + // if we don't have an exit, discard the ray + if (exitColorTexture.a < 1.0 || exitColorTexture.rgb == vec3(0.0)) { discard; } @@ -69,6 +71,10 @@ void main() { vec3 entryPos; float entryDepth; getEntry(entryPos, entryDepth); + // if we don't have an entry, discard the ray + if (entryPos == vec3(0.0)) { + discard; + } vec3 position = entryPos; vec3 diff = exitPos - entryPos; From ebb433584e76846ad93f66178498b1d1a5ecfa1b Mon Sep 17 00:00:00 2001 From: eriksunden Date: Mon, 19 Aug 2019 14:25:39 +0200 Subject: [PATCH 13/42] Dictionary fix. --- modules/galaxy/rendering/renderablegalaxy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index 7d14646e6f..1c74457af5 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -177,10 +177,6 @@ namespace openspace { } } - if (dictionary.hasKeyAndValue(EnabledPointsRatioInfo.identifier)) { - _enabledPointsRatio = static_cast(dictionary.value(EnabledPointsRatioInfo.identifier)); - } - if (dictionary.hasKeyAndValue(TranslationInfo.identifier)) { _translation = dictionary.value(TranslationInfo.identifier); } @@ -227,6 +223,10 @@ namespace openspace { LERROR("No points filename specified."); } + if (pointsDictionary.hasKeyAndValue(EnabledPointsRatioInfo.identifier)) { + _enabledPointsRatio = static_cast(pointsDictionary.value(EnabledPointsRatioInfo.identifier)); + } + std::string pointSpreadFunctionTexturePath; if (pointsDictionary.getValue("Texture", pointSpreadFunctionTexturePath)) { _pointSpreadFunctionTexturePath = absPath(pointSpreadFunctionTexturePath); From 799d9e8cdfaa3e78c1fac86ac7c73ff72d04cf4f Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Mon, 19 Aug 2019 16:16:20 -0400 Subject: [PATCH 14/42] Changes in volume rendering for FXAA. --- shaders/framebuffer/raycastframebuffer.frag | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shaders/framebuffer/raycastframebuffer.frag b/shaders/framebuffer/raycastframebuffer.frag index 93c588bd4d..be6614e658 100644 --- a/shaders/framebuffer/raycastframebuffer.frag +++ b/shaders/framebuffer/raycastframebuffer.frag @@ -79,9 +79,6 @@ void main() { vec3 direction = normalize(diff); float raycastDepth = length(diff); - int i, j; - float tmp; - float geoDepth = denormalizeFloat(texelFetch(mainDepthTexture, ivec2(gl_FragCoord), 0).x); float geoRatio = clamp((geoDepth - entryDepth) / (exitDepth - entryDepth), 0.0, 1.0); raycastDepth = geoRatio * raycastDepth; @@ -102,11 +99,14 @@ void main() { vec3 accumulatedAlpha = vec3(0.0); - for (steps = 0; (accumulatedAlpha.r < ALPHA_LIMIT || accumulatedAlpha.g < ALPHA_LIMIT || - accumulatedAlpha.b < ALPHA_LIMIT) && steps < RAYCAST_MAX_STEPS; ++steps) { - if (currentDepth + nextStepSize * jitterFactor > raycastDepth) { - aaOpacity -= opacityDecay; - } + for (steps = 0; + (accumulatedAlpha.r < ALPHA_LIMIT || accumulatedAlpha.g < ALPHA_LIMIT || + accumulatedAlpha.b < ALPHA_LIMIT) && steps < RAYCAST_MAX_STEPS; + ++steps) + { + // if (currentDepth + nextStepSize * jitterFactor > raycastDepth) { + // aaOpacity -= opacityDecay; + // } bool shortStepSize = nextStepSize < raycastDepth / 10000000000.0; if (shortStepSize) { From 7509d1abd64f1b3144eec145f98ea0ff884828e3 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Tue, 20 Aug 2019 10:59:42 +0200 Subject: [PATCH 15/42] Proper discard of stars if the volume is not visible. --- modules/galaxy/rendering/renderablegalaxy.cpp | 9 +++++---- modules/galaxy/rendering/renderablegalaxy.h | 3 ++- modules/galaxy/shaders/points_fs.glsl | 4 +++- modules/galaxy/shaders/points_vs.glsl | 16 +++++----------- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index 1c74457af5..bcfcc0994f 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -54,8 +54,9 @@ namespace { "${MODULES}/galaxy/shaders/raycasterbounds_fs.glsl"; constexpr const char* _loggerCat = "Renderable Galaxy"; - constexpr const std::array UniformNamesPoints = { - "modelMatrix", "cameraViewProjectionMatrix", "eyePosition" + constexpr const std::array UniformNamesPoints = { + "modelMatrix", "cameraViewProjectionMatrix", "eyePosition", + "opacityCoefficient" }; constexpr const std::array UniformNamesBillboards = { "modelMatrix", "cameraViewProjectionMatrix", @@ -468,7 +469,6 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { const float upperRampEnd = maxDim * 10.f; float opacityCoefficient = 1.f; - if (length < lowerRampStart) { opacityCoefficient = 0.f; // camera really close } else if (length < lowerRampEnd) { @@ -494,7 +494,7 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { } // Render the stars - if (_starRenderingEnabled) { + if (_starRenderingEnabled && _opacityCoefficient > 0.f) { if (_starRenderingMethod == 1) { renderBillboards(data); } @@ -550,6 +550,7 @@ void RenderableGalaxy::renderPoints(const RenderData& data) { glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0) ); _pointsProgram->setUniform(_uniformCachePoints.eyePosition, eyePosition); + _pointsProgram->setUniform(_uniformCachePoints.opacityCoefficient, _opacityCoefficient); glBindVertexArray(_pointsVao); glDrawArrays(GL_POINTS, 0, static_cast(_nPoints * _enabledPointsRatio)); diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index 3bfd02163a..0b49d848c4 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -90,7 +90,8 @@ private: std::unique_ptr _pointsProgram; std::unique_ptr _billboardsProgram; UniformCache( - modelMatrix, cameraViewProjectionMatrix, eyePosition + modelMatrix, cameraViewProjectionMatrix, eyePosition, + opacityCoefficient ) _uniformCachePoints; UniformCache( modelMatrix, cameraViewProjectionMatrix, diff --git a/modules/galaxy/shaders/points_fs.glsl b/modules/galaxy/shaders/points_fs.glsl index 368d4a1b79..0028d1d4a5 100644 --- a/modules/galaxy/shaders/points_fs.glsl +++ b/modules/galaxy/shaders/points_fs.glsl @@ -30,11 +30,13 @@ in vec3 vs_color; in float vs_screenSpaceDepth; in float vs_starBrightness; +uniform float opacityCoefficient; + Fragment getFragment() { Fragment frag; vec3 extinction = exp(vec3(0.6, 0.2, 0.3)-vs_color); - vec4 fullColor = vec4(vs_color*extinction*vs_starBrightness, 1.0); + vec4 fullColor = vec4(vs_color*extinction*vs_starBrightness*opacityCoefficient, 1.0); frag.color = fullColor; frag.depth = vs_screenSpaceDepth; diff --git a/modules/galaxy/shaders/points_vs.glsl b/modules/galaxy/shaders/points_vs.glsl index 8d9635921f..ecfd7b3d15 100644 --- a/modules/galaxy/shaders/points_vs.glsl +++ b/modules/galaxy/shaders/points_vs.glsl @@ -47,17 +47,11 @@ void main() { double distanceToStar = length((dpos.xyz - eyePosition)); vs_starBrightness = clamp(float(8000*PARSEC/distanceToStar), 0.0, 1.0); - // Discard stars if we are not seing the milky way volume - if(length(vec3(0.0)-eyePosition)<780*PARSEC){ - vs_starBrightness = 0.0; - } - else{ - dpos.xyz *= 8.0; - dpos = modelMatrix * dpos; - dpos /= PARSEC; - //It lies about 8 kpc from the center on what is known as the Orion Arm of the Milky Way - dpos.x += 8000; - } + dpos.xyz *= 8.0; + dpos = modelMatrix * dpos; + dpos /= PARSEC; + //It lies about 8 kpc from the center on what is known as the Orion Arm of the Milky Way + dpos.x += 8000; vec4 positionScreenSpace = z_normalization(vec4(cameraViewProjectionMatrix * dpos)); vs_color = in_color; From 33ce712e3ae419f745d201ca5fc372fb7e66ce1c Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Tue, 20 Aug 2019 15:34:48 -0400 Subject: [PATCH 16/42] Fixed Model rendering to work with the new HDR. --- .../shaders/atmosphere_deferred_fs.glsl | 14 ++++++- modules/base/shaders/model_fs.glsl | 9 ++-- .../shaders/globalrenderer_vs.glsl | 2 - .../shaders/localrenderer_vs.glsl | 3 -- .../globebrowsing/shaders/renderer_fs.glsl | 18 ++------ modules/globebrowsing/src/renderableglobe.cpp | 41 ++----------------- 6 files changed, 23 insertions(+), 64 deletions(-) diff --git a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl index d8d1d4e28b..7832680740 100644 --- a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl +++ b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl @@ -577,12 +577,22 @@ void main() { // Fragments positions into G-Buffer are written in SGCT Eye Space (View plus Camera Rig Coords) // when using their positions later, one must convert them to the planet's coords + // ======================= // Get data from G-Buffer - vec4 normal = texelFetch(mainNormalTexture, fragCoords, i); + // ======================= + + // Normal is stored in SGCT View Space and transformed to the current object space + vec4 normalViewSpaceAndWaterReflectance = texelFetch(mainNormalTexture, fragCoords, i); + dvec4 normalViewSpace = vec4(normalViewSpaceAndWaterReflectance.xyz, 0.0); + dvec4 normalWorldSpace = dSGCTViewToWorldMatrix * normalViewSpace; + vec4 normal = vec4(dInverseModelTransformMatrix * normalWorldSpace); + normal.xyz = normalize(normal.xyz); + normal.w = normalViewSpaceAndWaterReflectance.w; + // Data in the mainPositionTexture are written in view space (view plus camera rig) vec4 position = texelFetch(mainPositionTexture, fragCoords, i); - // OS Eye to World coords + // OS Eye to World coords dvec4 positionWorldCoords = dSGCTViewToWorldMatrix * position; // World to Object (Normal and Position in meters) diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index d507183856..db7eea1c32 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -84,10 +84,11 @@ Fragment getFragment() { frag.color.rgb = diffuseAlbedo; } - frag.color.a = opacity; - frag.depth = vs_screenSpaceDepth; - frag.gPosition = vs_positionCameraSpace; - frag.gNormal = vec4(vs_normalViewSpace, 1.0); + frag.color.a = opacity; + frag.depth = vs_screenSpaceDepth; + frag.gPosition = vs_positionCameraSpace; + frag.gNormal = vec4(vs_normalViewSpace, 0.0); + frag.disableLDR2HDR = true; return frag; diff --git a/modules/globebrowsing/shaders/globalrenderer_vs.glsl b/modules/globebrowsing/shaders/globalrenderer_vs.glsl index fc0ec6620a..8e91e2e6a4 100644 --- a/modules/globebrowsing/shaders/globalrenderer_vs.glsl +++ b/modules/globebrowsing/shaders/globalrenderer_vs.glsl @@ -33,7 +33,6 @@ layout(location = 1) in vec2 in_uv; out vec4 fs_position; -out vec3 fs_normal; out vec2 fs_uv; out vec3 ellipsoidNormalCameraSpace; out vec3 levelWeights; @@ -126,7 +125,6 @@ void main() { fs_position = z_normalization(positionClippingSpace); gl_Position = fs_position; ellipsoidNormalCameraSpace = mat3(modelViewTransform) * pair.normal; - fs_normal = pair.normal; positionCameraSpace = vec3(modelViewTransform * vec4(pair.position, 1.0)); #if USE_ECLIPSE_SHADOWS diff --git a/modules/globebrowsing/shaders/localrenderer_vs.glsl b/modules/globebrowsing/shaders/localrenderer_vs.glsl index 7a2e661320..5e6ef0e12b 100644 --- a/modules/globebrowsing/shaders/localrenderer_vs.glsl +++ b/modules/globebrowsing/shaders/localrenderer_vs.glsl @@ -34,7 +34,6 @@ layout(location = 1) in vec2 in_uv; out vec2 fs_uv; out vec4 fs_position; -out vec3 fs_normal; out vec3 ellipsoidNormalCameraSpace; out vec3 levelWeights; out vec3 positionCameraSpace; @@ -56,7 +55,6 @@ uniform vec3 p10; uniform vec3 p01; uniform vec3 p11; uniform vec3 patchNormalCameraSpace; -uniform vec3 patchNormalModelSpace; uniform float chunkMinHeight; uniform float distanceScaleFactor; @@ -110,7 +108,6 @@ void main() { fs_position = z_normalization(positionClippingSpace); gl_Position = fs_position; ellipsoidNormalCameraSpace = patchNormalCameraSpace; - fs_normal = patchNormalModelSpace; positionCameraSpace = p; #if USE_ECLIPSE_SHADOWS diff --git a/modules/globebrowsing/shaders/renderer_fs.glsl b/modules/globebrowsing/shaders/renderer_fs.glsl index 388f1f1fb6..f0408f7941 100644 --- a/modules/globebrowsing/shaders/renderer_fs.glsl +++ b/modules/globebrowsing/shaders/renderer_fs.glsl @@ -129,7 +129,6 @@ vec4 calcShadow(const ShadowRenderingStruct shadowInfoArray[numberOfShadows], #endif in vec4 fs_position; -in vec3 fs_normal; in vec2 fs_uv; in vec3 ellipsoidNormalCameraSpace; in vec3 levelWeights; @@ -138,10 +137,6 @@ in vec3 positionCameraSpace; #if USE_ACCURATE_NORMALS in vec3 ellipsoidTangentThetaCameraSpace; in vec3 ellipsoidTangentPhiCameraSpace; - - // Once deferred light calculations are done in view space this can be removed - // so that we only need one normal; in view space. - uniform mat4 invViewModelTransform; #endif // USE_ACCURATE_NORMALS #if USE_ECLIPSE_SHADOWS @@ -152,11 +147,10 @@ in vec3 positionWorldSpace; Fragment getFragment() { Fragment frag; - frag.color = vec4(0.3, 0.3, 0.3, 1.0); vec3 normal = normalize(ellipsoidNormalCameraSpace); - vec3 normalModelSpace = normalize(fs_normal); + #if USE_ACCURATE_NORMALS normal = getTileNormal( fs_uv, @@ -165,9 +159,6 @@ Fragment getFragment() { normalize(ellipsoidTangentThetaCameraSpace), normalize(ellipsoidTangentPhiCameraSpace) ); - // Once deferred light calculations are done in view space this can be removed - // so that we only need one normal; in view space. - normalModelSpace = normalize(mat3(invViewModelTransform) * normal); #endif /// USE_ACCURATE_NORMALS #if USE_COLORTEXTURE @@ -243,11 +234,8 @@ Fragment getFragment() { #else frag.gNormal.w = 0; #endif - // Normal is written Object Space. - // Right now the only renderable using this info is the atm and, - // because all calculation for light interactions are done in Object - // Space, we avoid a new computation saving the normals in Object Space. - frag.gNormal.xyz = normalModelSpace; + // Normal is written View Space (Including SGCT View Matrix). + frag.gNormal.xyz = normal; if (dot(positionCameraSpace, vec3(1.0)) != 0.0) { frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space diff --git a/modules/globebrowsing/src/renderableglobe.cpp b/modules/globebrowsing/src/renderableglobe.cpp index 285c19c13a..35c29731cc 100644 --- a/modules/globebrowsing/src/renderableglobe.cpp +++ b/modules/globebrowsing/src/renderableglobe.cpp @@ -761,8 +761,7 @@ void RenderableGlobe::update(const UpdateData& data) { ghoul::opengl::updateUniformLocations( *_localRenderer.program, _localRenderer.uniformCache, - { "skirtLength", "p01", "p11", "p00", "p10", "patchNormalModelSpace", - "patchNormalCameraSpace" } + { "skirtLength", "p01", "p11", "p00", "p10", "patchNormalCameraSpace" } ); } @@ -1024,27 +1023,6 @@ void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&) { ); } - if (_generalProperties.useAccurateNormals && - !_layerManager.layerGroup(layergroupid::HeightLayers).activeLayers().empty()) - { - // This should not be needed once the light calculations for the atmosphere - // is performed in view space.. - _localRenderer.program->setUniform( - "invViewModelTransform", - glm::inverse( - glm::mat4(data.camera.combinedViewMatrix()) * - glm::mat4(_cachedModelTransform) - ) - ); - _globalRenderer.program->setUniform( - "invViewModelTransform", - glm::inverse( - glm::mat4(data.camera.combinedViewMatrix()) * - glm::mat4(_cachedModelTransform) - ) - ); - } - constexpr const int ChunkBufferSize = 2048; std::array global; int globalCount = 0; @@ -1274,6 +1252,7 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d // TODO: Patch normal can be calculated for all corners and then linearly // interpolated on the GPU to avoid cracks for high altitudes. + // JCC: Camera space includes the SGCT View transformation. const glm::vec3 patchNormalCameraSpace = normalize( cross( cornersCameraSpace[Quad::SOUTH_EAST] - cornersCameraSpace[Quad::SOUTH_WEST], @@ -1281,19 +1260,6 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d ) ); - // In order to improve performance, lets use the normal in object space (model space) - // for deferred rendering. - const glm::vec3 patchNormalModelSpace = normalize( - cross( - cornersModelSpace[Quad::SOUTH_EAST] - cornersModelSpace[Quad::SOUTH_WEST], - cornersModelSpace[Quad::NORTH_EAST] - cornersModelSpace[Quad::SOUTH_WEST] - ) - ); - - program.setUniform( - _localRenderer.uniformCache.patchNormalModelSpace, - patchNormalModelSpace - ); program.setUniform( _localRenderer.uniformCache.patchNormalCameraSpace, patchNormalCameraSpace @@ -1598,8 +1564,7 @@ void RenderableGlobe::recompileShaders() { ghoul::opengl::updateUniformLocations( *_localRenderer.program, _localRenderer.uniformCache, - { "skirtLength", "p01", "p11", "p00", "p10", "patchNormalModelSpace", - "patchNormalCameraSpace" } + { "skirtLength", "p01", "p11", "p00", "p10", "patchNormalCameraSpace" } ); From 8bfea472d58efa9bcab949c878bcf6778f928900 Mon Sep 17 00:00:00 2001 From: eriksunden Date: Wed, 21 Aug 2019 10:23:18 +0200 Subject: [PATCH 17/42] Increased shine of galaxy stars to match volume nicer. --- modules/galaxy/shaders/points_fs.glsl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/galaxy/shaders/points_fs.glsl b/modules/galaxy/shaders/points_fs.glsl index 0028d1d4a5..ae76e7dbfa 100644 --- a/modules/galaxy/shaders/points_fs.glsl +++ b/modules/galaxy/shaders/points_fs.glsl @@ -35,8 +35,9 @@ uniform float opacityCoefficient; Fragment getFragment() { Fragment frag; + float multipliedOpacityCoefficient = clamp(opacityCoefficient*opacityCoefficient*20.0, 0.0, 1.0); vec3 extinction = exp(vec3(0.6, 0.2, 0.3)-vs_color); - vec4 fullColor = vec4(vs_color*extinction*vs_starBrightness*opacityCoefficient, 1.0); + vec4 fullColor = vec4(vs_color*extinction*vs_starBrightness*multipliedOpacityCoefficient, 1.0); frag.color = fullColor; frag.depth = vs_screenSpaceDepth; From 21d799dd29bdfb3d70d1bada996518ba76f50f99 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Aug 2019 09:31:07 +0200 Subject: [PATCH 18/42] Force an even number of vertices for the RenderableSpheres (closes #957) --- modules/base/rendering/renderablesphericalgrid.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/base/rendering/renderablesphericalgrid.cpp b/modules/base/rendering/renderablesphericalgrid.cpp index 8fb5c1491b..054c83fa6c 100644 --- a/modules/base/rendering/renderablesphericalgrid.cpp +++ b/modules/base/rendering/renderablesphericalgrid.cpp @@ -137,7 +137,12 @@ RenderableSphericalGrid::RenderableSphericalGrid(const ghoul::Dictionary& dictio if (dictionary.hasKey(SegmentsInfo.identifier)) { _segments = static_cast(dictionary.value(SegmentsInfo.identifier)); } - _segments.onChange([&]() { _gridIsDirty = true; }); + _segments.onChange([&]() { + if (_segments.value() % 2 == 1) { + _segments = _segments - 1; + } + _gridIsDirty = true; + }); addProperty(_segments); if (dictionary.hasKey(LineWidthInfo.identifier)) { @@ -259,7 +264,10 @@ void RenderableSphericalGrid::update(const UpdateData&) { _isize = 6 * _segments * _segments; _vsize = (_segments + 1) * (_segments + 1); _varray.resize(_vsize); + Vertex v = { 0.f, 0.f, 0.f }; + std::fill(_varray.begin(), _varray.end(), v); _iarray.resize(_isize); + std::fill(_iarray.begin(), _iarray.end(), 0); int nr = 0; const float fsegments = static_cast(_segments); From 5675a495b076a49785c3f852dba744940ef612b0 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Aug 2019 09:39:01 +0200 Subject: [PATCH 19/42] GCC compile fix --- src/interaction/externinteraction.cpp | 49 ++++++++++++------------- src/interaction/websocketinputstate.cpp | 1 + 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/interaction/externinteraction.cpp b/src/interaction/externinteraction.cpp index 13f6915a34..ab383a67ff 100644 --- a/src/interaction/externinteraction.cpp +++ b/src/interaction/externinteraction.cpp @@ -40,42 +40,39 @@ #include namespace { -const uint32_t ProtocolVersion = 3; -const size_t MaxLatencyDiffs = 64; -const char* _loggerCat = "ExternInteraction"; + constexpr const uint32_t ProtocolVersion = 3; + constexpr const size_t MaxLatencyDiffs = 64; -constexpr openspace::properties::Property::PropertyInfo BufferTimeInfo = { - "BufferTime", - "Buffer Time", - "" // @TODO Missing documentation -}; + constexpr openspace::properties::Property::PropertyInfo BufferTimeInfo = { + "BufferTime", + "Buffer Time", + "" // @TODO Missing documentation + }; -constexpr openspace::properties::Property::PropertyInfo TimeKeyFrameInfo = { - "TimeKeyframeInterval", - "Time keyframe interval", - "" // @TODO Missing documentation -}; + constexpr openspace::properties::Property::PropertyInfo TimeKeyFrameInfo = { + "TimeKeyframeInterval", + "Time keyframe interval", + "" // @TODO Missing documentation + }; -constexpr openspace::properties::Property::PropertyInfo CameraKeyFrameInfo = { - "CameraKeyframeInterval", - "Camera Keyframe interval", - "" // @TODO Missing documentation -}; - -constexpr openspace::properties::Property::PropertyInfo TimeToleranceInfo = { - "TimeTolerance", - "Time tolerance", - "" // @TODO Missing documentation -}; + constexpr openspace::properties::Property::PropertyInfo CameraKeyFrameInfo = { + "CameraKeyframeInterval", + "Camera Keyframe interval", + "" // @TODO Missing documentation + }; + constexpr openspace::properties::Property::PropertyInfo TimeToleranceInfo = { + "TimeTolerance", + "Time tolerance", + "" // @TODO Missing documentation + }; } // namespace namespace openspace { ExternInteraction::ExternInteraction() : properties::PropertyOwner({ "ExternInteration", "External Interaction" }) -{ -} +{} void ExternInteraction::cameraInteraction(datamessagestructures::CameraKeyframe kf) { interaction::KeyframeNavigator::CameraPose pose; diff --git a/src/interaction/websocketinputstate.cpp b/src/interaction/websocketinputstate.cpp index e49989147c..4a531c83bf 100644 --- a/src/interaction/websocketinputstate.cpp +++ b/src/interaction/websocketinputstate.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include From 0f36cf0dd42578d9c927165c0c8b8aaaf2150626 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Aug 2019 09:52:35 +0200 Subject: [PATCH 20/42] Always add transformation property owners, even if the defaults are not overwritten --- src/scene/scenegraphnode.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 914242cf9a..21b8c06d26 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -123,11 +123,13 @@ std::unique_ptr SceneGraphNode::createFromDictionary( )); return nullptr; } - result->addPropertySubOwner(result->_transform.translation.get()); LDEBUG(fmt::format( "Successfully created ephemeris for '{}'", result->identifier() )); } + if (result->_transform.translation) { + result->addPropertySubOwner(result->_transform.translation.get()); + } if (dictionary.hasKey(KeyTransformRotation)) { ghoul::Dictionary rotationDictionary; @@ -139,11 +141,13 @@ std::unique_ptr SceneGraphNode::createFromDictionary( )); return nullptr; } - result->addPropertySubOwner(result->_transform.rotation.get()); LDEBUG(fmt::format( "Successfully created rotation for '{}'", result->identifier() )); } + if (result->_transform.rotation) { + result->addPropertySubOwner(result->_transform.rotation.get()); + } if (dictionary.hasKey(KeyTransformScale)) { ghoul::Dictionary scaleDictionary; @@ -155,9 +159,11 @@ std::unique_ptr SceneGraphNode::createFromDictionary( )); return nullptr; } - result->addPropertySubOwner(result->_transform.scale.get()); LDEBUG(fmt::format("Successfully created scale for '{}'", result->identifier())); } + if (result->_transform.scale) { + result->addPropertySubOwner(result->_transform.scale.get()); + } if (dictionary.hasKey(KeyTimeFrame)) { ghoul::Dictionary timeFrameDictionary; From 13cb950480310e570127892096b8f623699e0f61 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Thu, 22 Aug 2019 10:27:59 +0200 Subject: [PATCH 21/42] Fix bug with camera following anchor node --- include/openspace/interaction/orbitalnavigator.h | 6 +++--- src/interaction/orbitalnavigator.cpp | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/openspace/interaction/orbitalnavigator.h b/include/openspace/interaction/orbitalnavigator.h index 520608b90a..4ec4ced185 100644 --- a/include/openspace/interaction/orbitalnavigator.h +++ b/include/openspace/interaction/orbitalnavigator.h @@ -83,7 +83,7 @@ public: ScriptCameraStates& scriptStates(); const ScriptCameraStates& scriptStates() const; - bool shouldFollowAnchorRotation() const; + bool shouldFollowAnchorRotation(const glm::dvec3& cameraPosition) const; bool followingAnchorRotation() const; const SceneGraphNode* anchorNode() const; const SceneGraphNode* aimNode() const; @@ -290,8 +290,8 @@ private: /** * Interpolates between rotationDiff and a 0 rotation. */ - glm::dquat interpolateRotationDifferential(double deltaTime, - double interpolationTime, const glm::dquat& rotationDiff); + glm::dquat interpolateRotationDifferential(double deltaTime, double interpolationTime, + const glm::dvec3 cameraPosition, const glm::dquat& rotationDiff); /** * Get the vector from the camera to the surface of the anchor object in world space. diff --git a/src/interaction/orbitalnavigator.cpp b/src/interaction/orbitalnavigator.cpp index ea267548d1..ea817396b4 100644 --- a/src/interaction/orbitalnavigator.cpp +++ b/src/interaction/orbitalnavigator.cpp @@ -369,7 +369,7 @@ void OrbitalNavigator::resetVelocities() { _websocketStates.resetVelocities(); _scriptStates.resetVelocities(); - if (shouldFollowAnchorRotation()) { + if (shouldFollowAnchorRotation(_camera->positionVec3())) { _followRotationInterpolator.end(); } else { @@ -459,6 +459,7 @@ void OrbitalNavigator::updateCameraStateFromStates(double deltaTime) { anchorNodeRotationDiff = interpolateRotationDifferential( deltaTime, _followRotationInterpolationTime, + pose.position, anchorNodeRotationDiff ); @@ -701,7 +702,8 @@ void OrbitalNavigator::setRetargetInterpolationTime(float durationInSeconds) { _retargetInterpolationTime = durationInSeconds; } -bool OrbitalNavigator::shouldFollowAnchorRotation() const { +bool OrbitalNavigator::shouldFollowAnchorRotation(const glm::dvec3& cameraPosition) const +{ if (!_anchorNode) { return false; } @@ -709,7 +711,7 @@ bool OrbitalNavigator::shouldFollowAnchorRotation() const { const glm::dmat4 modelTransform = _anchorNode->modelTransform(); const glm::dmat4 inverseModelTransform = _anchorNode->inverseModelTransform(); const glm::dvec3 cameraPositionModelSpace = glm::dvec3(inverseModelTransform * - glm::dvec4(_camera->positionVec3(), 1.0)); + glm::dvec4(cameraPosition, 1.0)); const SurfacePositionHandle positionHandle = _anchorNode->calculateSurfacePositionHandle(cameraPositionModelSpace); @@ -719,7 +721,7 @@ bool OrbitalNavigator::shouldFollowAnchorRotation() const { ) * _followAnchorNodeRotationDistance; const double distanceToCamera = - glm::distance(_camera->positionVec3(), _anchorNode->worldPosition()); + glm::distance(cameraPosition, _anchorNode->worldPosition()); return distanceToCamera < maximumDistanceForRotation; } @@ -1277,10 +1279,12 @@ glm::dvec3 OrbitalNavigator::pushToSurface(double minHeightAboveGround, glm::dquat OrbitalNavigator::interpolateRotationDifferential(double deltaTime, double interpolationTime, + const glm::dvec3 cameraPosition, const glm::dquat& rotationDiff) { // Interpolate with a negative delta time if distance is too large to follow - const double interpolationSign = shouldFollowAnchorRotation() ? 1.0 : -1.0; + const double interpolationSign = + shouldFollowAnchorRotation(cameraPosition) ? 1.0 : -1.0; _followRotationInterpolator.setInterpolationTime(static_cast( interpolationTime From 3fd6cd5ae698ae738e7d06aac561460c162fa6f0 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Thu, 22 Aug 2019 13:55:06 +0200 Subject: [PATCH 22/42] Update webgui --- data/assets/util/webgui.asset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/assets/util/webgui.asset b/data/assets/util/webgui.asset index 29a6437b42..9ecd45606a 100644 --- a/data/assets/util/webgui.asset +++ b/data/assets/util/webgui.asset @@ -3,7 +3,7 @@ asset.require('./static_server') local guiCustomization = asset.require('customization/gui') -- Select which commit hashes to use for the frontend and backend -local frontendHash = "2d1bb8d8d8478b6ed025ccc6f1e0ceacf04b6114" +local frontendHash = "129a2c70ec8179b193fdb3a689c37bd65418ac22" local dataProvider = "data.openspaceproject.com/files/webgui" local frontend = asset.syncedResource({ From d32b4d9f1f0e1653d57c8722d78e34a075d177b7 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Aug 2019 14:34:45 +0200 Subject: [PATCH 23/42] Update Ghoul to fix the commandline parsing (closes #950) --- apps/OpenSpace/main.cpp | 2 +- ext/ghoul | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 87bceea835..1be2584abe 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -1131,7 +1131,7 @@ int main(int argc, char** argv) { "evaluated before it is passed to OpenSpace." )); - // setCommandLine returns a referece to the vector that will be filled later + // setCommandLine returns a reference to the vector that will be filled later const std::vector& sgctArguments = parser.setCommandLine( { argv, argv + argc } ); diff --git a/ext/ghoul b/ext/ghoul index 526b27cb65..e91413398b 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 526b27cb653fe9befc324278debc701297694207 +Subproject commit e91413398bf7a1e2e0f61dfd7edb1656e354945c From 8ce9fde91b3b81663a33574a6bbed5920ccc8674 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Aug 2019 15:37:08 +0200 Subject: [PATCH 24/42] Enable the user to specify a custom temporary folder to keep the OS's temp folder clean Change the configuration file to point the temp folder into the OpenSpace folder Update Ghoul to not overwrite default font files (closes #944) --- ext/ghoul | 2 +- openspace.cfg | 3 ++- src/engine/openspaceengine.cpp | 14 ++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index e91413398b..d73b914734 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit e91413398bf7a1e2e0f61dfd7edb1656e354945c +Subproject commit d73b9147347140932bf0691788183db92ccfaf14 diff --git a/openspace.cfg b/openspace.cfg index d34aae67c9..51b091a9a4 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -78,7 +78,8 @@ Paths = { LOGS = "${BASE}/logs", MODULES = "${BASE}/modules", SCRIPTS = "${BASE}/scripts", - SHADERS = "${BASE}/shaders" + SHADERS = "${BASE}/shaders", + TEMPORARY = "${BASE}/temp" } ModuleConfigurations = { diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 6c2042961e..a204b7e44c 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -104,10 +104,7 @@ namespace openspace { class Scene; -OpenSpaceEngine::OpenSpaceEngine() - : _scene(nullptr) - , _loadingScreen(nullptr) -{ +OpenSpaceEngine::OpenSpaceEngine() { FactoryManager::initialize(); FactoryManager::ref().addFactory( std::make_unique>(), @@ -164,19 +161,20 @@ void OpenSpaceEngine::registerPathTokens() { ghoul::filesystem::FileSystem::TokenClosingBraces; LDEBUG(fmt::format("Registering path {}: {}", fullKey, path.second)); - const bool override = (fullKey == "${BASE}"); - if (override) { + const bool overrideBase = (fullKey == "${BASE}"); + if (overrideBase) { LINFO(fmt::format("Overriding base path with '{}'", path.second)); } + const bool overrideTemporary = (fullKey == "${TEMPORARY}"); + using Override = ghoul::filesystem::FileSystem::Override; FileSys.registerPathToken( std::move(fullKey), std::move(path.second), - Override(override) + Override(overrideBase || overrideTemporary) ); } - LTRACE("OpenSpaceEngine::initialize(end)"); } From 071d4af9dc82bd9a6135c069b82a73cb9e1b11f3 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Aug 2019 16:09:54 +0200 Subject: [PATCH 25/42] Remove warnings duplicating property initialization for renderabletrails --- modules/base/rendering/renderabletrail.cpp | 26 +++++++++------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/modules/base/rendering/renderabletrail.cpp b/modules/base/rendering/renderabletrail.cpp index 4ff75279d2..23ab9b9263 100644 --- a/modules/base/rendering/renderabletrail.cpp +++ b/modules/base/rendering/renderabletrail.cpp @@ -202,7 +202,6 @@ RenderableTrail::Appearance::Appearance() RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) : Renderable(dictionary) { - setRenderBin(RenderBin::Overlay); addProperty(_opacity); @@ -212,35 +211,28 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) addPropertySubOwner(_translation.get()); _appearance.lineColor = dictionary.value(LineColorInfo.identifier); - addProperty(_appearance.lineColor); if (dictionary.hasKeyAndValue(EnableFadeInfo.identifier)) { _appearance.useLineFade = dictionary.value(EnableFadeInfo.identifier); } - addProperty(_appearance.useLineFade); if (dictionary.hasKeyAndValue(FadeInfo.identifier)) { - _appearance.lineFade = static_cast(dictionary.value(FadeInfo.identifier)); + _appearance.lineFade = static_cast( + dictionary.value(FadeInfo.identifier) + ); } - addProperty(_appearance.lineFade); if (dictionary.hasKeyAndValue(LineWidthInfo.identifier)) { _appearance.lineWidth = static_cast(dictionary.value( LineWidthInfo.identifier )); } - addProperty(_appearance.lineWidth); if (dictionary.hasKeyAndValue(PointSizeInfo.identifier)) { - _appearance.pointSize = static_cast(dictionary.value(PointSizeInfo.identifier)); + _appearance.pointSize = static_cast( + dictionary.value(PointSizeInfo.identifier) + ); } - addProperty(_appearance.pointSize); - - _appearance.renderingModes.addOptions({ - { RenderingModeLines, "Lines" }, - { RenderingModePoints, "Points" }, - { RenderingModeLinesPoints, "Lines+Points" } - }); // This map is not accessed out of order as long as the Documentation is adapted // whenever the map changes. The documentation will check for valid values @@ -252,7 +244,8 @@ RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary) else { _appearance.renderingModes = RenderingModeLines; } - addProperty(_appearance.renderingModes); + + addPropertySubOwner(_appearance); } void RenderableTrail::initializeGL() { @@ -331,7 +324,8 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) { } auto render = [renderLines, renderPoints, p = _programObject, &data, - &modelTransform, pointSize = _appearance.pointSize.value(), c = _uniformCache] + &modelTransform, pointSize = _appearance.pointSize.value(), + c = _uniformCache] (RenderInformation& info, int nVertices, int offset) { // We pass in the model view transformation matrix as double in order to maintain From 40545d99e5e1c2b24dfcf9bcef85c0cae45a5d93 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Aug 2019 16:31:55 +0200 Subject: [PATCH 26/42] Make Screenspace renderable work again (closes #959) --- include/openspace/rendering/renderengine.h | 3 +++ src/rendering/renderengine.cpp | 8 ++++++++ src/rendering/screenspacerenderable.cpp | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/openspace/rendering/renderengine.h b/include/openspace/rendering/renderengine.h index b529926ee1..b848712074 100644 --- a/include/openspace/rendering/renderengine.h +++ b/include/openspace/rendering/renderengine.h @@ -92,6 +92,9 @@ public: float globalBlackOutFactor(); void setGlobalBlackOutFactor(float opacity); + float hdrExposure() const; + bool isHdrDisabled() const; + void addScreenSpaceRenderable(std::unique_ptr s); void removeScreenSpaceRenderable(ScreenSpaceRenderable* s); void removeScreenSpaceRenderable(const std::string& identifier); diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index ccfbb5a739..de5ed0052a 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -938,6 +938,14 @@ void RenderEngine::setGlobalBlackOutFactor(float opacity) { _globalBlackOutFactor = opacity; } +float RenderEngine::hdrExposure() const { + return _hdrExposure; +} + +bool RenderEngine::isHdrDisabled() const { + return _disableHDRPipeline; +} + /** * Build a program object for rendering with the used renderer */ diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index d8aa117073..9a3b01f0dc 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -500,7 +500,9 @@ void ScreenSpaceRenderable::createShaders() { ghoul::Dictionary rendererData = { { "fragmentRendererPath", "${SHADERS}/framebuffer/renderframebuffer.frag" }, { "windowWidth" , res.x }, - { "windowHeight" , res.y } + { "windowHeight" , res.y }, + { "hdrExposure", global::renderEngine.hdrExposure() }, + { "disableHDR", global::renderEngine.isHdrDisabled() } }; dict.setValue("rendererData", rendererData); From 6ae42d0b2fc909685af4bfddd14a335d088a9fd9 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Aug 2019 17:08:53 +0200 Subject: [PATCH 27/42] Update version number for the release candidate --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 724729bcad..085fdbafc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,9 +27,9 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) project(OpenSpace) set(OPENSPACE_VERSION_MAJOR 0) -set(OPENSPACE_VERSION_MINOR 14) -set(OPENSPACE_VERSION_PATCH 1) -set(OPENSPACE_VERSION_STRING "Beta-4") +set(OPENSPACE_VERSION_MINOR 15) +set(OPENSPACE_VERSION_PATCH -1) +set(OPENSPACE_VERSION_STRING "Beta-5") set(OPENSPACE_BASE_DIR "${PROJECT_SOURCE_DIR}") From f7860b4311f909be10e31f868588404c90a7fee2 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 22 Aug 2019 17:44:33 +0200 Subject: [PATCH 28/42] Use the correct version number --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 085fdbafc3..5766af7da5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ # # # OpenSpace # # # -# Copyright (c) 2014-2018 # +# Copyright (c) 2014-2019 # # # # 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 # @@ -29,7 +29,7 @@ project(OpenSpace) set(OPENSPACE_VERSION_MAJOR 0) set(OPENSPACE_VERSION_MINOR 15) set(OPENSPACE_VERSION_PATCH -1) -set(OPENSPACE_VERSION_STRING "Beta-5") +set(OPENSPACE_VERSION_STRING "Beta-5 RC1") set(OPENSPACE_BASE_DIR "${PROJECT_SOURCE_DIR}") From 54a57468153a9ab0c607118e0ead8c8142960a43 Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Thu, 22 Aug 2019 13:02:02 -0400 Subject: [PATCH 29/42] Changes in DU for have back old Stars colors and align Constellations and stars. --- modules/digitaluniverse/rendering/renderabledumeshes.cpp | 8 +++++--- modules/space/shaders/star_fs.glsl | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index ccaa706c03..72ee2ebca1 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -710,14 +710,16 @@ bool RenderableDUMeshes::readSpeckFile() { continue; } - if (line.substr(0, 4) != "mesh") { + std::size_t found = line.find("mesh"); + if (found == std::string::npos) { + //if (line.substr(0, 4) != "mesh") { // we read a line that doesn't belong to the header, so we have to jump back // before the beginning of the current line file.seekg(position); break; - } + } else { - if (line.substr(0, 4) == "mesh") { + //if (line.substr(0, 4) == "mesh") { // mesh lines are structured as follows: // mesh -t texnum -c colorindex -s style { // where textnum is the index of the texture; diff --git a/modules/space/shaders/star_fs.glsl b/modules/space/shaders/star_fs.glsl index 0595d6dff4..63479d5f64 100644 --- a/modules/space/shaders/star_fs.glsl +++ b/modules/space/shaders/star_fs.glsl @@ -104,6 +104,7 @@ Fragment getFragment() { frag.depth = gs_screenSpaceDepth; frag.gPosition = vs_position; frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); + frag.disableLDR2HDR = true; return frag; } From e25ceb579efb895def2df2f97af16ecfe34c42f4 Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Thu, 22 Aug 2019 13:44:46 -0400 Subject: [PATCH 30/42] fix for gpus that dont support const return values --- shaders/hdr.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shaders/hdr.glsl b/shaders/hdr.glsl index c9909b03ea..2fca4496c5 100644 --- a/shaders/hdr.glsl +++ b/shaders/hdr.glsl @@ -41,7 +41,7 @@ const mat3 XYZ2RGB = mat3( // Gamma correction for linear RGB to sRGB // See wiki: https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_.28.22gamma.22.29 -const float gammaF(const float u) { +float gammaF(const float u) { if (u < 0.0031308) { return 12.92 * u; } else { From 766051c837e0913904e9129c9bc1230807bdf567 Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Thu, 22 Aug 2019 16:01:04 -0400 Subject: [PATCH 31/42] Changes to correct orient the Milky Way. --- data/assets/customization/volumes.asset | 1 + modules/galaxy/rendering/renderablegalaxy.cpp | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/data/assets/customization/volumes.asset b/data/assets/customization/volumes.asset index 29d1bd1773..ad53d6ac6b 100644 --- a/data/assets/customization/volumes.asset +++ b/data/assets/customization/volumes.asset @@ -19,6 +19,7 @@ local MilkyWayVolumeGalaxy = { AbsorptionMultiply = 75, EmissionMultiply = 200, Translation = {0.2, 0, 0}, + Rotation = {3.1415926, 3.1248, 4.45741}, Volume = { Type = "Volume", Filename = data .. "/MilkyWayRGBAVolume1024x1024x128.raw", diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index bcfcc0994f..40877451ef 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -454,7 +454,7 @@ void RenderableGalaxy::update(const UpdateData& data) { void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { // Render the volume if (_raycaster && _volumeRenderingEnabled) { - RaycasterTask task { _raycaster.get(), data }; + RaycasterTask task{ _raycaster.get(), data }; const glm::vec3 position = data.camera.positionVec3(); const float length = safeLength(position); @@ -530,9 +530,13 @@ void RenderableGalaxy::renderPoints(const RenderData& data) { _pointsProgram->activate(); + glm::dmat4 rotMatrix = glm::rotate(glm::dmat4(1.0), 3.1415926, glm::dvec3(1.0, 0.0, 0.0)) * + glm::rotate(glm::dmat4(1.0), 3.1248, glm::dvec3(0.0, 1.0, 0.0)) * + glm::rotate(glm::dmat4(1.0), 4.45741, glm::dvec3(0.0, 0.0, 1.0)); + glm::dmat4 modelMatrix = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * - glm::dmat4(data.modelTransform.rotation) * + glm::dmat4(data.modelTransform.rotation) * rotMatrix * glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale))); glm::dmat4 projectionMatrix = glm::dmat4(data.camera.projectionMatrix()); @@ -596,9 +600,13 @@ void RenderableGalaxy::renderBillboards(const RenderData& data) { _billboardsProgram->activate(); + glm::dmat4 rotMatrix = glm::rotate(glm::dmat4(1.0), 3.1415926, glm::dvec3(1.0, 0.0, 0.0)) * + glm::rotate(glm::dmat4(1.0), 3.1248, glm::dvec3(0.0, 1.0, 0.0)) * + glm::rotate(glm::dmat4(1.0), 4.45741, glm::dvec3(0.0, 0.0, 1.0)); + glm::dmat4 modelMatrix = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * - glm::dmat4(data.modelTransform.rotation) * + glm::dmat4(data.modelTransform.rotation) * rotMatrix * glm::dmat4(glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale))); glm::dmat4 projectionMatrix = glm::dmat4(data.camera.projectionMatrix()); From fea10b358d0b62f0601eebaaf29fc3c018c20eae Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Thu, 22 Aug 2019 17:03:12 -0400 Subject: [PATCH 32/42] Clean up. --- shaders/framebuffer/fxaa.frag | 177 ++++++++++++++-------------------- 1 file changed, 70 insertions(+), 107 deletions(-) diff --git a/shaders/framebuffer/fxaa.frag b/shaders/framebuffer/fxaa.frag index 1d6d9a362e..90c7674897 100644 --- a/shaders/framebuffer/fxaa.frag +++ b/shaders/framebuffer/fxaa.frag @@ -53,25 +53,21 @@ void main() { // Detecting where to apply AA: // ============================ - // Luma at the current fragment - float lumaCenter = getLum(colorCenter.rgb); - - // Luma at the four direct neighbours of the current fragment. - float lumaDown = getLum(textureOffset(renderedTexture, texCoord, ivec2(0,-1)).rgb); - float lumaUp = getLum(textureOffset(renderedTexture, texCoord, ivec2(0,1)).rgb); - float lumaLeft = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,0)).rgb); - float lumaRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,0)).rgb); + float pixelLumCenter = getLum(colorCenter.rgb); + float pixelLumDown = getLum(textureOffset(renderedTexture, texCoord, ivec2(0,-1)).rgb); + float pixelLumUp = getLum(textureOffset(renderedTexture, texCoord, ivec2(0,1)).rgb); + float pixelLumLeft = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,0)).rgb); + float pixelLumRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,0)).rgb); - // Find the maximum and minimum luma around the current fragment. - float lumaMin = min(lumaCenter, min(min(lumaDown, lumaUp), min(lumaLeft, lumaRight))); - float lumaMax = max(lumaCenter, max(max(lumaDown, lumaUp), max(lumaLeft, lumaRight))); + float pixelLumMin = min(pixelLumCenter, min(min(pixelLumDown, pixelLumUp), min(pixelLumLeft, pixelLumRight))); + float pixelLumMax = max(pixelLumCenter, max(max(pixelLumDown, pixelLumUp), max(pixelLumLeft, pixelLumRight))); - // Compute the delta. - float lumaRange = lumaMax - lumaMin; + // Delta. + float pixelLumRange = pixelLumMax - pixelLumMin; - // If the luma variation is lower that a threshold (or if we are in a really dark area), + // If the pixelLum variation is lower that a threshold (or if we are in a really dark area), // we are not on an edge, don't perform any AA. - if (lumaRange < max(EDGE_THRESHOLD_MIN, lumaMax * EDGE_THRESHOLD_MAX)) { + if (pixelLumRange < max(EDGE_THRESHOLD_MIN, pixelLumMax * EDGE_THRESHOLD_MAX)) { aaFinalColor = colorCenter; return; } @@ -79,64 +75,50 @@ void main() { // ============================ // Estimating the gradient: // ============================ - // Query the 4 remaining corners lumas. - float lumaDownLeft = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,-1)).rgb); - float lumaUpRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,1)).rgb); - float lumaUpLeft = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,1)).rgb); - float lumaDownRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,-1)).rgb); + float pixelLumDownLeft = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,-1)).rgb); + float pixelLumUpRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,1)).rgb); + float pixelLumUpLeft = getLum(textureOffset(renderedTexture, texCoord, ivec2(-1,1)).rgb); + float pixelLumDownRight = getLum(textureOffset(renderedTexture, texCoord, ivec2(1,-1)).rgb); - // Combine the four edges lumas (using intermediary variables for future computations - // with the same values). - float lumaDownUp = lumaDown + lumaUp; - float lumaLeftRight = lumaLeft + lumaRight; + float pixelLumDownUp = pixelLumDown + pixelLumUp; + float pixelLumLeftRight = pixelLumLeft + pixelLumRight; + float pixelLumLeftCorners = pixelLumDownLeft + pixelLumUpLeft; + float pixelLumDownCorners = pixelLumDownLeft + pixelLumDownRight; + float pixelLumRightCorners = pixelLumDownRight + pixelLumUpRight; + float pixelLumUpCorners = pixelLumUpRight + pixelLumUpLeft; - // Same for corners - float lumaLeftCorners = lumaDownLeft + lumaUpLeft; - float lumaDownCorners = lumaDownLeft + lumaDownRight; - float lumaRightCorners = lumaDownRight + lumaUpRight; - float lumaUpCorners = lumaUpRight + lumaUpLeft; - - // Compute an estimation of the gradient along the horizontal and vertical axis. - float edgeHorizontal = abs(-2.0 * lumaLeft + lumaLeftCorners) + - abs(-2.0 * lumaCenter + lumaDownUp ) * 2.0 + abs(-2.0 * lumaRight + lumaRightCorners); - float edgeVertical = abs(-2.0 * lumaUp + lumaUpCorners) + - abs(-2.0 * lumaCenter + lumaLeftRight) * 2.0 + abs(-2.0 * lumaDown + lumaDownCorners); - - // Is the local edge horizontal or vertical ? - bool isHorizontal = (edgeHorizontal >= edgeVertical); + // Compute an estimation of the gradient + float edgeHorizontal = abs(-2.0 * pixelLumLeft + pixelLumLeftCorners) + + abs(-2.0 * pixelLumCenter + pixelLumDownUp ) * 2.0 + abs(-2.0 * pixelLumRight + pixelLumRightCorners); + float edgeVertical = abs(-2.0 * pixelLumUp + pixelLumUpCorners) + + abs(-2.0 * pixelLumCenter + pixelLumLeftRight) * 2.0 + abs(-2.0 * pixelLumDown + pixelLumDownCorners); // ============================ // Choosing Edge Orientation: // ============================ - // Select the two neighboring texels lumas in the opposite direction to the local edge. - float luma1 = isHorizontal ? lumaDown : lumaLeft; - float luma2 = isHorizontal ? lumaUp : lumaRight; + bool isHorizontal = (edgeHorizontal >= edgeVertical); + float pixelLum1 = isHorizontal ? pixelLumDown : pixelLumLeft; + float pixelLum2 = isHorizontal ? pixelLumUp : pixelLumRight; - // Compute gradients in this direction. - float gradient1 = luma1 - lumaCenter; - float gradient2 = luma2 - lumaCenter; + // Gradients + float gradient1 = pixelLum1 - pixelLumCenter; + float gradient2 = pixelLum2 - pixelLumCenter; - // Which direction is the steepest ? bool is1Steepest = abs(gradient1) >= abs(gradient2); - - // Gradient in the corresponding direction, normalized. float gradientScaled = 0.25 * max(abs(gradient1), abs(gradient2)); - // Choose the step size (one pixel) according to the edge direction. + // Step size (one pixel) according to the edge direction. float stepLength = isHorizontal ? inverseScreenSize.y : inverseScreenSize.x; - // Average luma in the correct direction. - float lumaLocalAverage = 0.0; + float pixelLumLocalAverage = 0.0; if (is1Steepest) { - // Switch the direction stepLength = - stepLength; - lumaLocalAverage = 0.5 * (luma1 + lumaCenter); + pixelLumLocalAverage = 0.5 * (pixelLum1 + pixelLumCenter); } else { - lumaLocalAverage = 0.5 * (luma2 + lumaCenter); + pixelLumLocalAverage = 0.5 * (pixelLum2 + pixelLumCenter); } - // Shift UV in the correct direction by half a pixel. vec2 currentUv = texCoord; if (isHorizontal) { currentUv.y += stepLength * 0.5; @@ -147,28 +129,22 @@ void main() { // ============================ // Iterations: // ============================ - // Compute offset (for each iteration step) in the right direction. vec2 offset = isHorizontal ? vec2(inverseScreenSize.x, 0.0) : vec2(0.0, inverseScreenSize.y); - // Compute UVs to explore on each side of the edge, orthogonally. - // The QUALITY allows us to step faster. vec2 uv1 = currentUv - offset; vec2 uv2 = currentUv + offset; - // Read the lumas at both current extremities of the exploration segment, - // and compute the delta wrt to the local average luma. - float lumaEnd1 = getLum(texture(renderedTexture, uv1).rgb); - float lumaEnd2 = getLum(texture(renderedTexture, uv2).rgb); - lumaEnd1 -= lumaLocalAverage; - lumaEnd2 -= lumaLocalAverage; + // Read the pixelLums at both current extremities of the exploration segment, + // and compute the delta wrt to the local average pixelLum. + float pixelLumEnd1 = getLum(texture(renderedTexture, uv1).rgb); + float pixelLumEnd2 = getLum(texture(renderedTexture, uv2).rgb); + pixelLumEnd1 -= pixelLumLocalAverage; + pixelLumEnd2 -= pixelLumLocalAverage; - // If the luma deltas at the current extremities are larger than the local gradient, - // we have reached the side of the edge. - bool reached1 = abs(lumaEnd1) >= gradientScaled; - bool reached2 = abs(lumaEnd2) >= gradientScaled; + bool reached1 = abs(pixelLumEnd1) >= gradientScaled; + bool reached2 = abs(pixelLumEnd2) >= gradientScaled; bool reachedBoth = reached1 && reached2; - // If the side is not reached, we continue to explore in this direction. if (!reached1) { uv1 -= offset; } @@ -177,27 +153,24 @@ void main() { uv2 += offset; } - // If both sides have not been reached, continue to explore. + // Still exploring if (!reachedBoth) { for (int i = 2; i < ITERATIONS; i++) { - // If needed, read luma in 1st direction, compute delta. + // If needed, read pixelLum in 1st direction, compute delta. if (!reached1) { - lumaEnd1 = getLum(texture(renderedTexture, uv1).rgb); - lumaEnd1 = lumaEnd1 - lumaLocalAverage; + pixelLumEnd1 = getLum(texture(renderedTexture, uv1).rgb); + pixelLumEnd1 = pixelLumEnd1 - pixelLumLocalAverage; } - // If needed, read luma in opposite direction, compute delta. + // If needed, read pixelLum in opposite direction, compute delta. if (!reached2) { - lumaEnd2 = getLum(texture(renderedTexture, uv2).rgb); - lumaEnd2 = lumaEnd2 - lumaLocalAverage; + pixelLumEnd2 = getLum(texture(renderedTexture, uv2).rgb); + pixelLumEnd2 = pixelLumEnd2 - pixelLumLocalAverage; } - // If the luma deltas at the current extremities is larger than - // the local gradient, we have reached the side of the edge. - reached1 = abs(lumaEnd1) >= gradientScaled; - reached2 = abs(lumaEnd2) >= gradientScaled; + reached1 = abs(pixelLumEnd1) >= gradientScaled; + reached2 = abs(pixelLumEnd2) >= gradientScaled; reachedBoth = reached1 && reached2; - // If the side is not reached, we continue to explore in this direction, - // with a variable quality. + // If the side is not reached if (!reached1) { uv1 -= offset * QUALITY[i]; } @@ -206,7 +179,7 @@ void main() { uv2 += offset * QUALITY[i]; } - // If both sides have been reached, stop the exploration. + // If both sides have been reached if (reachedBoth) { break; } @@ -216,55 +189,45 @@ void main() { // ============================ // Estimating the offset: // ============================ - // Compute the distances to each extremity of the edge. float distance1 = isHorizontal ? (texCoord.x - uv1.x) : (texCoord.y - uv1.y); float distance2 = isHorizontal ? (uv2.x - texCoord.x) : (uv2.y - texCoord.y); - // In which direction is the extremity of the edge closer ? bool isDirection1 = distance1 < distance2; float distanceFinal = min(distance1, distance2); - // Length of the edge. float edgeThickness = (distance1 + distance2); - // UV offset: read in the direction of the closest side of the edge. + // Read in the direction of the closest side of the edge. float pixelOffset = - distanceFinal / edgeThickness + 0.5; - // Is the luma at center smaller than the local average ? - bool isLumaCenterSmaller = lumaCenter < lumaLocalAverage; + bool ispixelLumCenterSmaller = pixelLumCenter < pixelLumLocalAverage; - // If the luma at center is smaller than at its neighbour, the delta luma at + // If the pixelLum at center is smaller than at its neighbour, the delta pixelLum at // each end should be positive (same variation). - // (in the direction of the closer side of the edge.) - bool correctVariation = ((isDirection1 ? lumaEnd1 : lumaEnd2) < 0.0) != isLumaCenterSmaller; + bool correctVariation = ((isDirection1 ? pixelLumEnd1 : pixelLumEnd2) < 0.0) != ispixelLumCenterSmaller; - // If the luma variation is incorrect, do not offset. + // If the pixelLum variation is incorrect, do not offset. float finalOffset = correctVariation ? pixelOffset : 0.0; // ============================ // Subpixel antialiasing: // ============================ - // Sub-pixel shifting - // Full weighted average of the luma over the 3x3 neighborhood. - float lumaAverage = (1.0/12.0) * (2.0 * (lumaDownUp + lumaLeftRight) + - lumaLeftCorners + lumaRightCorners); - // Ratio of the delta between the global average and the center luma, over the luma range in the 3x3 neighborhood. - float subPixelOffset1 = clamp(abs(lumaAverage - lumaCenter) / lumaRange, 0.0, 1.0); - float subPixelOffset2 = (-2.0 * subPixelOffset1 + 3.0) * subPixelOffset1 * subPixelOffset1; - // Compute a sub-pixel offset based on this delta. + float pixelLumAverage = (1.0/12.0) * (2.0 * (pixelLumDownUp + pixelLumLeftRight) + + pixelLumLeftCorners + pixelLumRightCorners); + + float subPixelOffset1 = clamp(abs(pixelLumAverage - pixelLumCenter) / pixelLumRange, 0.0, 1.0); + float subPixelOffset2 = (-2.0 * subPixelOffset1 + 3.0) * subPixelOffset1 * subPixelOffset1; float subPixelOffsetFinal = subPixelOffset2 * subPixelOffset2 * SUBPIXEL_QUALITY; - // Pick the biggest of the two offsets. + // Biggest of the two offsets. finalOffset = max(finalOffset, subPixelOffsetFinal); - // Compute the final UV coordinates. - vec2 finalUv = texCoord; + vec2 finalUV = texCoord; if (isHorizontal) { - finalUv.y += finalOffset * stepLength; + finalUV.y += finalOffset * stepLength; } else { - finalUv.x += finalOffset * stepLength; + finalUV.x += finalOffset * stepLength; } - // Read the color at the new UV coordinates, and use it. - aaFinalColor = texture(renderedTexture, finalUv); + aaFinalColor = texture(renderedTexture, finalUV); } \ No newline at end of file From 2c5fab7120eed67f9c47383fa6306697ee9ee6d7 Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Thu, 22 Aug 2019 18:04:06 -0400 Subject: [PATCH 33/42] Removed unsused files and code. --- .../digitaluniverse/constellations.asset | 2 +- .../digitaluniverse/obassociations.asset | 2 +- data/assets/scene/digitaluniverse/stars.asset | 2 +- .../openspace/rendering/framebufferrenderer.h | 2 - shaders/framebuffer/hdrBackground.frag | 46 ------------------- shaders/framebuffer/hdrBackground.vert | 39 ---------------- shaders/framebuffer/pixelSizeMSAA.frag | 33 ------------- shaders/framebuffer/pixelSizeMSAA.vert | 34 -------------- shaders/framebuffer/resolveframebuffer.frag | 43 ----------------- shaders/framebuffer/resolveframebuffer.vert | 31 ------------- src/rendering/framebufferrenderer.cpp | 24 ---------- 11 files changed, 3 insertions(+), 255 deletions(-) delete mode 100644 shaders/framebuffer/hdrBackground.frag delete mode 100644 shaders/framebuffer/hdrBackground.vert delete mode 100644 shaders/framebuffer/pixelSizeMSAA.frag delete mode 100644 shaders/framebuffer/pixelSizeMSAA.vert delete mode 100644 shaders/framebuffer/resolveframebuffer.frag delete mode 100644 shaders/framebuffer/resolveframebuffer.vert diff --git a/data/assets/scene/digitaluniverse/constellations.asset b/data/assets/scene/digitaluniverse/constellations.asset index 18f1911df8..105c9fe001 100644 --- a/data/assets/scene/digitaluniverse/constellations.asset +++ b/data/assets/scene/digitaluniverse/constellations.asset @@ -6,7 +6,7 @@ local speck = asset.syncedResource({ Name = "Constellation Speck Files", Type = "HttpSynchronization", Identifier = "digitaluniverse_constellations_speck", - Version = 1 + Version = 2 }) local constellationsExtragalactic = { diff --git a/data/assets/scene/digitaluniverse/obassociations.asset b/data/assets/scene/digitaluniverse/obassociations.asset index c8411d45c0..3b5d9e2355 100644 --- a/data/assets/scene/digitaluniverse/obassociations.asset +++ b/data/assets/scene/digitaluniverse/obassociations.asset @@ -13,7 +13,7 @@ local speck = asset.syncedResource({ Name = "OB Associations Speck Files", Type = "HttpSynchronization", Identifier = "digitaluniverse_obassociations_speck", - Version = 1 + Version = 2 }) local object = { diff --git a/data/assets/scene/digitaluniverse/stars.asset b/data/assets/scene/digitaluniverse/stars.asset index 50dfc7b402..c33d89648d 100644 --- a/data/assets/scene/digitaluniverse/stars.asset +++ b/data/assets/scene/digitaluniverse/stars.asset @@ -13,7 +13,7 @@ local speck = asset.syncedResource({ Name = "Stars Speck Files", Type = "HttpSynchronization", Identifier = "stars_du", - Version = 1 + Version = 3 }) local colorLUT = asset.syncedResource({ diff --git a/include/openspace/rendering/framebufferrenderer.h b/include/openspace/rendering/framebufferrenderer.h index d116c54bce..a49568fe17 100644 --- a/include/openspace/rendering/framebufferrenderer.h +++ b/include/openspace/rendering/framebufferrenderer.h @@ -121,10 +121,8 @@ private: std::unique_ptr _hdrFilteringProgram; std::unique_ptr _tmoProgram; - std::unique_ptr _resolveProgram; std::unique_ptr _fxaaProgram; - UniformCache(mainColorTexture, blackoutFactor) _uniformCache; UniformCache(hdrFeedingTexture, blackoutFactor, hdrExposure, gamma, Hue, Saturation, Value) _hdrUniformCache; UniformCache(renderedTexture, inverseScreenSize) _fxaaUniformCache; diff --git a/shaders/framebuffer/hdrBackground.frag b/shaders/framebuffer/hdrBackground.frag deleted file mode 100644 index f3860b0e18..0000000000 --- a/shaders/framebuffer/hdrBackground.frag +++ /dev/null @@ -1,46 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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. * - ****************************************************************************************/ - -#version __CONTEXT__ - -#include "hdr.glsl" - -layout (location = 0) out vec4 finalColor; - -uniform int nAaSamples; -uniform float backgroundConstant; -uniform float backgroundExposure; -uniform sampler2DMS mainColorTexture; - -void main() { - vec4 color = vec4(0.0); - for (int i = 0; i < nAaSamples; i++) { - color += texelFetch(mainColorTexture, ivec2(gl_FragCoord), i); - } - - color /= nAaSamples; - // color.rgb *= blackoutFactor; - - finalColor = vec4(HDR(color.rgb * backgroundConstant, backgroundExposure), 1.0); -} diff --git a/shaders/framebuffer/hdrBackground.vert b/shaders/framebuffer/hdrBackground.vert deleted file mode 100644 index 46af90fe55..0000000000 --- a/shaders/framebuffer/hdrBackground.vert +++ /dev/null @@ -1,39 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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. * - ****************************************************************************************/ - -#version __CONTEXT__ - -in vec4 position; - -out vec2 texCoord; -out vec3 vPosition; -out vec4 worldPosition; - -void main() { - gl_Position = position; - texCoord = 0.5 + position.xy * 0.5; - - vPosition = position.xyz; - worldPosition = position; -} diff --git a/shaders/framebuffer/pixelSizeMSAA.frag b/shaders/framebuffer/pixelSizeMSAA.frag deleted file mode 100644 index a638403326..0000000000 --- a/shaders/framebuffer/pixelSizeMSAA.frag +++ /dev/null @@ -1,33 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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. * - ****************************************************************************************/ - -#version __CONTEXT__ - -layout (location = 0) out vec4 finalColor; - -flat in vec3 vPosition; - -void main() { - finalColor = vec4(0.5 * vPosition + 0.5, 1.0); -} diff --git a/shaders/framebuffer/pixelSizeMSAA.vert b/shaders/framebuffer/pixelSizeMSAA.vert deleted file mode 100644 index b0f01ca96b..0000000000 --- a/shaders/framebuffer/pixelSizeMSAA.vert +++ /dev/null @@ -1,34 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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. * - ****************************************************************************************/ - -#version __CONTEXT__ - -layout(location = 0) in vec4 position; - -flat out vec3 vPosition; - -void main() { - gl_Position = position; - vPosition = position.xyz; -} diff --git a/shaders/framebuffer/resolveframebuffer.frag b/shaders/framebuffer/resolveframebuffer.frag deleted file mode 100644 index 39f2946dec..0000000000 --- a/shaders/framebuffer/resolveframebuffer.frag +++ /dev/null @@ -1,43 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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. * - ****************************************************************************************/ - -#version __CONTEXT__ - -layout (location = 0) out vec4 finalColor; - -uniform float blackoutFactor; -uniform int nAaSamples; -uniform sampler2DMS mainColorTexture; - -void main() { - vec4 color = vec4(0.0); - for (int i = 0; i < nAaSamples; i++) { - color += texelFetch(mainColorTexture, ivec2(gl_FragCoord), i); - } - - color /= nAaSamples; - color.rgb *= blackoutFactor; - - finalColor = vec4(color.rgb, 1.0); -} diff --git a/shaders/framebuffer/resolveframebuffer.vert b/shaders/framebuffer/resolveframebuffer.vert deleted file mode 100644 index 9167d4c640..0000000000 --- a/shaders/framebuffer/resolveframebuffer.vert +++ /dev/null @@ -1,31 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2019 * - * * - * 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. * - ****************************************************************************************/ - -#version __CONTEXT__ - -in vec4 position; - -void main() { - gl_Position = position; -} diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 4908ef7836..6263f07328 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -50,10 +50,6 @@ namespace { constexpr const char* _loggerCat = "FramebufferRenderer"; - constexpr const std::array UniformNames = { - "mainColorTexture", "blackoutFactor" - }; - constexpr const std::array HDRUniformNames = { "hdrFeedingTexture", "blackoutFactor", "hdrExposure", "gamma", "Hue", "Saturation", "Value" @@ -320,17 +316,6 @@ void FramebufferRenderer::initialize() { // Sets back to default FBO glBindFramebuffer(GL_FRAMEBUFFER, _defaultFBO); - _resolveProgram = ghoul::opengl::ProgramObject::Build( - "Framebuffer Resolve", - absPath("${SHADERS}/framebuffer/resolveframebuffer.vert"), - absPath("${SHADERS}/framebuffer/resolveframebuffer.frag") - ); - - ghoul::opengl::updateUniformLocations( - *_resolveProgram, - _uniformCache, - UniformNames - ); ghoul::opengl::updateUniformLocations( *_hdrFilteringProgram, _hdrUniformCache, @@ -475,15 +460,6 @@ void FramebufferRenderer::update() { updateDeferredcastData(); } - if (_resolveProgram->isDirty()) { - _resolveProgram->rebuildFromFile(); - ghoul::opengl::updateUniformLocations( - *_resolveProgram, - _uniformCache, - UniformNames - ); - } - if (_hdrFilteringProgram->isDirty()) { _hdrFilteringProgram->rebuildFromFile(); From 0c48f5ef38ce23be1a4dff2782d01a599a5d1bff Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Thu, 22 Aug 2019 18:07:20 -0400 Subject: [PATCH 34/42] Added back resolveframebuffer.vert. It's used by volume rendering shaders. --- shaders/framebuffer/resolveframebuffer.vert | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 shaders/framebuffer/resolveframebuffer.vert diff --git a/shaders/framebuffer/resolveframebuffer.vert b/shaders/framebuffer/resolveframebuffer.vert new file mode 100644 index 0000000000..9167d4c640 --- /dev/null +++ b/shaders/framebuffer/resolveframebuffer.vert @@ -0,0 +1,31 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * 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. * + ****************************************************************************************/ + +#version __CONTEXT__ + +in vec4 position; + +void main() { + gl_Position = position; +} From cf3efb459196e01ef8f425dd8837685fc3567c5f Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Thu, 22 Aug 2019 18:36:27 -0400 Subject: [PATCH 35/42] Changed array type to old style in glsl. --- shaders/framebuffer/fxaa.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shaders/framebuffer/fxaa.frag b/shaders/framebuffer/fxaa.frag index 90c7674897..a9d30c4279 100644 --- a/shaders/framebuffer/fxaa.frag +++ b/shaders/framebuffer/fxaa.frag @@ -29,7 +29,7 @@ #define ITERATIONS 12 #define SUBPIXEL_QUALITY 0.75f -const float[12] QUALITY = {1.f, 1.f, 1.f, 1.f, 1.f, 1.5f, 2.f, 2.f, 2.f, 2.f, 4.f, 8.f}; +const float[12] QUALITY = float[](1.f, 1.f, 1.f, 1.f, 1.f, 1.5f, 2.f, 2.f, 2.f, 2.f, 4.f, 8.f); // const float[24] QUALITY = {2.f, 4.f, 6.f, 8.f, 10.f, 12.f, 12.f, 12.f, 12.f, 12.f, 14.f, 18.f, // 18.f, 18.f, 18.f, 18.f, 18.f, 18.f, 18.f, 18.f, 18.f, 18.f, // 18.f, 18.f}; From a25106886bd30bcce887df3a1e9eebcc52547550 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Fri, 23 Aug 2019 14:19:24 +0200 Subject: [PATCH 36/42] Cancel version check when application closes --- include/openspace/util/versionchecker.h | 1 + src/engine/openspaceengine.cpp | 1 + src/util/versionchecker.cpp | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/include/openspace/util/versionchecker.h b/include/openspace/util/versionchecker.h index c938dc281c..52092aad41 100644 --- a/include/openspace/util/versionchecker.h +++ b/include/openspace/util/versionchecker.h @@ -42,6 +42,7 @@ public: }; void requestLatestVersion(const std::string& url); + void cancel(); bool hasLatestVersionInfo(); SemanticVersion latestVersion(); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index a204b7e44c..d62d07937d 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -806,6 +806,7 @@ void OpenSpaceEngine::deinitialize() { ); } global::sessionRecording.deinitialize(); + global::versionChecker.cancel(); global::deinitialize(); diff --git a/src/util/versionchecker.cpp b/src/util/versionchecker.cpp index 223f2e695d..436b01fab1 100644 --- a/src/util/versionchecker.cpp +++ b/src/util/versionchecker.cpp @@ -53,6 +53,15 @@ void VersionChecker::requestLatestVersion(const std::string& url) { _request->start(opt); } +void VersionChecker::cancel() { + if (!_request) { + return; + } + _request->cancel(); + _request->wait(); + _request = nullptr; +} + bool VersionChecker::hasLatestVersionInfo() { if (_latestVersion.has_value()) { return true; From 4f319d06127c94075e31b22660eccbc117df973c Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Fri, 23 Aug 2019 14:25:52 +0200 Subject: [PATCH 37/42] Report unknown number of download bytes if nTotalDownloadBytes is 0 --- src/util/httprequest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/httprequest.cpp b/src/util/httprequest.cpp index dbc21a5c46..71b6877fbe 100644 --- a/src/util/httprequest.cpp +++ b/src/util/httprequest.cpp @@ -65,7 +65,7 @@ int progressCallback(void* userData, int64_t nTotalDownloadBytes, HttpRequest* r = reinterpret_cast(userData); return r->_onProgress( HttpRequest::Progress{ - true, + nTotalDownloadBytes > 0, static_cast(nTotalDownloadBytes), static_cast(nDownloadedBytes) } From a53581d6c6c6db1a55489cd6cdeb72cb43f44114 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Fri, 23 Aug 2019 14:32:11 +0200 Subject: [PATCH 38/42] Cancel request when the version checker is destructed --- include/openspace/util/versionchecker.h | 2 ++ src/util/versionchecker.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/include/openspace/util/versionchecker.h b/include/openspace/util/versionchecker.h index 52092aad41..4d3776dd46 100644 --- a/include/openspace/util/versionchecker.h +++ b/include/openspace/util/versionchecker.h @@ -41,6 +41,8 @@ public: int patch; }; + ~VersionChecker(); + void requestLatestVersion(const std::string& url); void cancel(); bool hasLatestVersionInfo(); diff --git a/src/util/versionchecker.cpp b/src/util/versionchecker.cpp index 436b01fab1..6ab9ffad73 100644 --- a/src/util/versionchecker.cpp +++ b/src/util/versionchecker.cpp @@ -35,6 +35,10 @@ namespace { namespace openspace { +VersionChecker::~VersionChecker() { + cancel(); +} + void VersionChecker::requestLatestVersion(const std::string& url) { HttpRequest::RequestOptions opt; opt.requestTimeoutSeconds = 0; From 157c653afc1029b0ec5c4a97afb1a141c8b4e308 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 23 Aug 2019 16:36:43 +0200 Subject: [PATCH 39/42] Moved the volume.asset from customization to scene/milkyway/milkyway/volume.asset Make the Galaxy volume a default Small changes here and there --- data/assets/base.asset | 2 +- .../milkyway/milkyway/volume.asset} | 28 +++--- modules/base/shaders/model_fs.glsl | 2 +- modules/galaxy/include.cmake | 2 + modules/galaxy/rendering/renderablegalaxy.cpp | 96 +++++++++++++------ 5 files changed, 87 insertions(+), 43 deletions(-) rename data/assets/{customization/volumes.asset => scene/milkyway/milkyway/volume.asset} (61%) diff --git a/data/assets/base.asset b/data/assets/base.asset index a758852399..3ab8f33d97 100644 --- a/data/assets/base.asset +++ b/data/assets/base.asset @@ -15,6 +15,7 @@ asset.require('scene/solarsystem/planets') asset.require('scene/solarsystem/planets/mars/moons/phobos') asset.require('scene/solarsystem/planets/mars/moons/deimos') asset.require('scene/solarsystem/dwarf_planets/pluto/system') +asset.request('scene/milkyway/milkyway/volume') assetHelper.requestAll(asset, 'scene/digitaluniverse') @@ -26,7 +27,6 @@ asset.require('util/default_joystick') -- Load web gui asset.require('util/webgui') -asset.request('customization/globebrowsing') asset.request('customization/volumes') -- Keybindings that are specific for this scene diff --git a/data/assets/customization/volumes.asset b/data/assets/scene/milkyway/milkyway/volume.asset similarity index 61% rename from data/assets/customization/volumes.asset rename to data/assets/scene/milkyway/milkyway/volume.asset index ad53d6ac6b..0f0fb1f399 100644 --- a/data/assets/customization/volumes.asset +++ b/data/assets/scene/milkyway/milkyway/volume.asset @@ -16,22 +16,22 @@ local MilkyWayVolumeGalaxy = { Renderable = { Type = "RenderableGalaxy", StepSize = 0.01, - AbsorptionMultiply = 75, - EmissionMultiply = 200, - Translation = {0.2, 0, 0}, + AbsorptionMultiply = 75, + EmissionMultiply = 200, + Translation = {0.2, 0, 0}, Rotation = {3.1415926, 3.1248, 4.45741}, Volume = { - Type = "Volume", - Filename = data .. "/MilkyWayRGBAVolume1024x1024x128.raw", - Dimensions = {1024, 1024, 128}, - Size = {1.2E21, 1.2E21, 0.15E21} - }, - Points = { - Type = "Points", - Filename = data .. "/MilkyWayPoints.off", - EnabledPointsRatio = 0.3, - Texture = data .. "/halo.png" - } + Type = "Volume", + Filename = data .. "/MilkyWayRGBAVolume1024x1024x128.raw", + Dimensions = {1024, 1024, 128}, + Size = {1.2E21, 1.2E21, 0.15E21} + }, + Points = { + Type = "Points", + Filename = data .. "/MilkyWayPoints.off", + EnabledPointsRatio = 0.3, + Texture = data .. "/halo.png" + } }, GUI = { Path = "/Milky Way" diff --git a/modules/base/shaders/model_fs.glsl b/modules/base/shaders/model_fs.glsl index db7eea1c32..b4bd1fd9ec 100644 --- a/modules/base/shaders/model_fs.glsl +++ b/modules/base/shaders/model_fs.glsl @@ -84,7 +84,7 @@ Fragment getFragment() { frag.color.rgb = diffuseAlbedo; } - frag.color.a = opacity; + frag.color.a = opacity; frag.depth = vs_screenSpaceDepth; frag.gPosition = vs_positionCameraSpace; frag.gNormal = vec4(vs_normalViewSpace, 0.0); diff --git a/modules/galaxy/include.cmake b/modules/galaxy/include.cmake index 8216f1c090..586a4f7717 100644 --- a/modules/galaxy/include.cmake +++ b/modules/galaxy/include.cmake @@ -1,3 +1,5 @@ +set(DEFAULT_MODULE ON) + set (OPENSPACE_DEPENDENCIES volume space diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index 40877451ef..14f87d7cc9 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -108,7 +108,8 @@ namespace { constexpr openspace::properties::Property::PropertyInfo StarRenderingMethodInfo = { "StarRenderingMethod", "Star Rendering Method", - "This value determines which rendering method is used for visualization of the stars." + "This value determines which rendering method is used for visualization of the " + "stars." }; constexpr openspace::properties::Property::PropertyInfo EnabledPointsRatioInfo = { @@ -127,7 +128,10 @@ namespace openspace { , _stepSize(StepSizeInfo, 0.01f, 0.0005f, 0.05f, 0.001f) , _absorptionMultiply(AbsorptionMultiplyInfo, 40.f, 0.0f, 100.0f) , _emissionMultiply(EmissionMultiplyInfo, 400.f, 0.0f, 1000.0f) - , _starRenderingMethod(StarRenderingMethodInfo, properties::OptionProperty::DisplayType::Dropdown) + , _starRenderingMethod( + StarRenderingMethodInfo, + properties::OptionProperty::DisplayType::Dropdown + ) , _enabledPointsRatio(EnabledPointsRatioInfo, 0.5f, 0.01f, 1.0f) , _translation(TranslationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(1.f)) , _rotation(RotationInfo, glm::vec3(0.f), glm::vec3(0.f), glm::vec3(6.28f)) @@ -143,7 +147,9 @@ namespace openspace { dictionary.getValue("Rotation", _rotation); if (dictionary.hasKeyAndValue(VolumeRenderingEnabledInfo.identifier)) { - _volumeRenderingEnabled = dictionary.value(VolumeRenderingEnabledInfo.identifier); + _volumeRenderingEnabled = dictionary.value( + VolumeRenderingEnabledInfo.identifier + ); } if (dictionary.hasKeyAndValue(StarRenderingEnabledInfo.identifier)) { @@ -155,21 +161,25 @@ namespace openspace { } if (dictionary.hasKeyAndValue(AbsorptionMultiplyInfo.identifier)) { - _absorptionMultiply = static_cast(dictionary.value(AbsorptionMultiplyInfo.identifier)); + _absorptionMultiply = static_cast( + dictionary.value(AbsorptionMultiplyInfo.identifier) + ); } if (dictionary.hasKeyAndValue(EmissionMultiplyInfo.identifier)) { - _emissionMultiply = static_cast(dictionary.value(EmissionMultiplyInfo.identifier)); + _emissionMultiply = static_cast( + dictionary.value(EmissionMultiplyInfo.identifier) + ); } _starRenderingMethod.addOptions({ - { 0, "Points" }, - { 1, "Billboards" } - }); + { 0, "Points" }, + { 1, "Billboards" } + }); if (dictionary.hasKey(StarRenderingMethodInfo.identifier)) { const std::string starRenderingMethod = dictionary.value( StarRenderingMethodInfo.identifier - ); + ); if (starRenderingMethod == "Points") { _starRenderingMethod = 0; } @@ -195,13 +205,15 @@ namespace openspace { std::string volumeFilename; if (volumeDictionary.getValue("Filename", volumeFilename)) { _volumeFilename = absPath(volumeFilename); - } else { + } + else { LERROR("No volume filename specified."); } glm::vec3 volumeDimensions; if (volumeDictionary.getValue("Dimensions", volumeDimensions)) { _volumeDimensions = static_cast(volumeDimensions); - } else { + } + else { LERROR("No volume dimensions specified."); } glm::vec3 volumeSize; @@ -220,18 +232,23 @@ namespace openspace { std::string pointsFilename; if (pointsDictionary.getValue("Filename", pointsFilename)) { _pointsFilename = absPath(pointsFilename); - } else { + } + else { LERROR("No points filename specified."); } if (pointsDictionary.hasKeyAndValue(EnabledPointsRatioInfo.identifier)) { - _enabledPointsRatio = static_cast(pointsDictionary.value(EnabledPointsRatioInfo.identifier)); + _enabledPointsRatio = static_cast( + pointsDictionary.value(EnabledPointsRatioInfo.identifier) + ); } std::string pointSpreadFunctionTexturePath; if (pointsDictionary.getValue("Texture", pointSpreadFunctionTexturePath)) { _pointSpreadFunctionTexturePath = absPath(pointSpreadFunctionTexturePath); - _pointSpreadFunctionFile = std::make_unique(_pointSpreadFunctionTexturePath); + _pointSpreadFunctionFile = std::make_unique( + _pointSpreadFunctionTexturePath + ); } else { LERROR("No points filename specified."); @@ -326,8 +343,16 @@ void RenderableGalaxy::initializeGL() { ); } - ghoul::opengl::updateUniformLocations(*_pointsProgram, _uniformCachePoints, UniformNamesPoints); - ghoul::opengl::updateUniformLocations(*_billboardsProgram, _uniformCacheBillboards, UniformNamesBillboards); + ghoul::opengl::updateUniformLocations( + *_pointsProgram, + _uniformCachePoints, + UniformNamesPoints + ); + ghoul::opengl::updateUniformLocations( + *_billboardsProgram, + _uniformCacheBillboards, + UniformNamesBillboards + ); _pointsProgram->setIgnoreUniformLocationError( ghoul::opengl::ProgramObject::IgnoreError::Yes @@ -357,7 +382,10 @@ void RenderableGalaxy::initializeGL() { // Read points float x, y, z, r, g, b, a; - for (size_t i = 0; i < static_cast(_nPoints * _enabledPointsRatio.maxValue()) + 1; ++i) { + for (size_t i = 0; + i < static_cast(_nPoints * _enabledPointsRatio.maxValue()) + 1; + ++i) + { std::getline(pointFile, line); std::istringstream issp(line); issp >> x >> y >> z >> r >> g >> b >> a; @@ -472,7 +500,8 @@ void RenderableGalaxy::render(const RenderData& data, RendererTasks& tasks) { if (length < lowerRampStart) { opacityCoefficient = 0.f; // camera really close } else if (length < lowerRampEnd) { - opacityCoefficient = (length - lowerRampStart) / (lowerRampEnd - lowerRampStart); + opacityCoefficient = (length - lowerRampStart) / + (lowerRampEnd - lowerRampStart); } else if (length < upperRampStart) { opacityCoefficient = 1.f; // sweet spot (max) } else if (length < upperRampEnd) { @@ -530,9 +559,13 @@ void RenderableGalaxy::renderPoints(const RenderData& data) { _pointsProgram->activate(); - glm::dmat4 rotMatrix = glm::rotate(glm::dmat4(1.0), 3.1415926, glm::dvec3(1.0, 0.0, 0.0)) * - glm::rotate(glm::dmat4(1.0), 3.1248, glm::dvec3(0.0, 1.0, 0.0)) * - glm::rotate(glm::dmat4(1.0), 4.45741, glm::dvec3(0.0, 0.0, 1.0)); + glm::dmat4 rotMatrix = glm::rotate( + glm::dmat4(1.0), + glm::pi(), + glm::dvec3(1.0, 0.0, 0.0)) * + glm::rotate(glm::dmat4(1.0), 3.1248, glm::dvec3(0.0, 1.0, 0.0)) * + glm::rotate(glm::dmat4(1.0), 4.45741, glm::dvec3(0.0, 0.0, 1.0) + ); glm::dmat4 modelMatrix = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * @@ -551,10 +584,14 @@ void RenderableGalaxy::renderPoints(const RenderData& data) { ); glm::dvec3 eyePosition = glm::dvec3( - glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0) + glm::inverse(data.camera.combinedViewMatrix()) * + glm::dvec4(0.0, 0.0, 0.0, 1.0) ); _pointsProgram->setUniform(_uniformCachePoints.eyePosition, eyePosition); - _pointsProgram->setUniform(_uniformCachePoints.opacityCoefficient, _opacityCoefficient); + _pointsProgram->setUniform( + _uniformCachePoints.opacityCoefficient, + _opacityCoefficient + ); glBindVertexArray(_pointsVao); glDrawArrays(GL_POINTS, 0, static_cast(_nPoints * _enabledPointsRatio)); @@ -600,9 +637,13 @@ void RenderableGalaxy::renderBillboards(const RenderData& data) { _billboardsProgram->activate(); - glm::dmat4 rotMatrix = glm::rotate(glm::dmat4(1.0), 3.1415926, glm::dvec3(1.0, 0.0, 0.0)) * - glm::rotate(glm::dmat4(1.0), 3.1248, glm::dvec3(0.0, 1.0, 0.0)) * - glm::rotate(glm::dmat4(1.0), 4.45741, glm::dvec3(0.0, 0.0, 1.0)); + glm::dmat4 rotMatrix = glm::rotate( + glm::dmat4(1.0), + glm::pi(), + glm::dvec3(1.0, 0.0, 0.0)) * + glm::rotate(glm::dmat4(1.0), 3.1248, glm::dvec3(0.0, 1.0, 0.0)) * + glm::rotate(glm::dmat4(1.0), 4.45741, glm::dvec3(0.0, 0.0, 1.0) + ); glm::dmat4 modelMatrix = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * @@ -621,7 +662,8 @@ void RenderableGalaxy::renderBillboards(const RenderData& data) { ); glm::dvec3 eyePosition = glm::dvec3( - glm::inverse(data.camera.combinedViewMatrix()) * glm::dvec4(0.0, 0.0, 0.0, 1.0) + glm::inverse(data.camera.combinedViewMatrix()) * + glm::dvec4(0.0, 0.0, 0.0, 1.0) ); _billboardsProgram->setUniform(_uniformCacheBillboards.eyePosition, eyePosition); From 2b91640344382da7680c53dccaf9c9b801674173 Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Fri, 23 Aug 2019 11:41:39 -0400 Subject: [PATCH 40/42] Disable Milky Way plane rendering now that we have the volumetric version. --- data/assets/scene/digitaluniverse/milkyway.asset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/assets/scene/digitaluniverse/milkyway.asset b/data/assets/scene/digitaluniverse/milkyway.asset index 83ee5c6f92..ad2453fd20 100644 --- a/data/assets/scene/digitaluniverse/milkyway.asset +++ b/data/assets/scene/digitaluniverse/milkyway.asset @@ -54,7 +54,7 @@ local plane = { Parent = "Root", Renderable = { Type = "RenderablePlanesCloud", - Enabled = true, + Enabled = false, Color = { 1.0, 1.0, 1.0 }, Transparency = 0.90, ScaleFactor = 2.8, From fbbcc6fc56df62e5576cf791a59cf1b0d79b74af Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Fri, 23 Aug 2019 13:18:06 -0400 Subject: [PATCH 41/42] Fixing shader on Mac. --- modules/galaxy/shaders/billboard_fs.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/galaxy/shaders/billboard_fs.glsl b/modules/galaxy/shaders/billboard_fs.glsl index 18fb39df76..cf758b3cab 100644 --- a/modules/galaxy/shaders/billboard_fs.glsl +++ b/modules/galaxy/shaders/billboard_fs.glsl @@ -29,8 +29,8 @@ uniform sampler2D psfTexture; in vec4 vs_position; in vec2 psfCoords; -in vec3 ge_color; -in float ge_screenSpaceDepth; +flat in vec3 ge_color; +flat in float ge_screenSpaceDepth; Fragment getFragment() { Fragment frag; From 6c84170a598bca71627b3f9abfc19db47fdc4064 Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Fri, 23 Aug 2019 13:47:27 -0400 Subject: [PATCH 42/42] readded globebrowsing cusomization asset;temp disabled fxaa on mac; temp not unsetting directories on deinit of webgui; added single_fisheye_gui.xml; --- config/single_fisheye_gui.xml | 54 ++++++++++++++++++++++++++++++++++ data/assets/base.asset | 2 +- data/assets/util/webgui.asset | 8 +++-- src/rendering/renderengine.cpp | 8 ++++- 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 config/single_fisheye_gui.xml diff --git a/config/single_fisheye_gui.xml b/config/single_fisheye_gui.xml new file mode 100644 index 0000000000..81019e8401 --- /dev/null +++ b/config/single_fisheye_gui.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/assets/base.asset b/data/assets/base.asset index 3ab8f33d97..791c43aa69 100644 --- a/data/assets/base.asset +++ b/data/assets/base.asset @@ -27,7 +27,7 @@ asset.require('util/default_joystick') -- Load web gui asset.require('util/webgui') -asset.request('customization/volumes') +asset.request('customization/globebrowsing') -- Keybindings that are specific for this scene local Keybindings = { diff --git a/data/assets/util/webgui.asset b/data/assets/util/webgui.asset index 9ecd45606a..25c60c242a 100644 --- a/data/assets/util/webgui.asset +++ b/data/assets/util/webgui.asset @@ -60,7 +60,8 @@ asset.onDeinitialize(function () local directories = openspace.getPropertyValue("Modules.WebGui.Directories") local newDirectories = {}; - openspace.setPropertyValueSingle("Modules.WebGui.DefaultEndpoint", "") + -- @TODO(maci, 2019-08-23) see message below + --openspace.setPropertyValueSingle("Modules.WebGui.DefaultEndpoint", "") for i = 0, #directories, 2 do -- @TODO(abock, 2019-08-20) The explicit check for directories[i] is a workaround @@ -70,5 +71,8 @@ asset.onDeinitialize(function () newDirectories[#newDirectories + 1] = directories[i + 1] end end - openspace.setPropertyValueSingle("Modules.WebGui.Directories", newDirectories) + -- @TODO(maci, 2019-08-23) setting this value on exit was causing the server to restart + -- on macos, which in turn, stopped the application from exiting. + -- need to address in webguimodule.cpp + --openspace.setPropertyValueSingle("Modules.WebGui.Directories", newDirectories) end) diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 49981a7a1a..ba0c38c71c 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -309,6 +309,12 @@ RenderEngine::RenderEngine() addProperty(_showVersionInfo); addProperty(_showCameraInfo); + // @TODO (maci 2019-08-23) disabling FXAA on + // MacOS for now until we have fix or MSAA option. +#ifdef __APPLE__ + _enableFXAA = false; +#endif + _enableFXAA.onChange([this]() { if (_renderer) { _renderer->enableFXAA(_enableFXAA); @@ -1083,7 +1089,7 @@ void RenderEngine::setRenderer(std::unique_ptr renderer) { _renderer = std::move(renderer); _renderer->setResolution(renderingResolution()); - _renderer->enableFXAA(true); + _renderer->enableFXAA(_enableFXAA); _renderer->setHDRExposure(_hdrExposure); _renderer->initialize(); }