From 03543d8fe475942581e235eacb6b99cb1c4ef96c Mon Sep 17 00:00:00 2001 From: eriksunden Date: Fri, 16 Aug 2019 13:35:46 +0200 Subject: [PATCH] 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; }