From 839e280a382b6d9596bc3513021dea532b925487 Mon Sep 17 00:00:00 2001 From: ElonOlsson Date: Thu, 16 Sep 2021 16:29:42 -0400 Subject: [PATCH] flux nodes shaders and interaction clean up --- .../heliosphere/bastille_day/fluxnodes.asset | 7 +- .../bastille_day/magnetogram_textures.asset | 1 - .../space/rendering/renderablefluxnodes.cpp | 270 ++++-------------- modules/space/rendering/renderablefluxnodes.h | 62 +--- modules/space/shaders/fluxnodes_fs.glsl | 46 +-- modules/space/shaders/fluxnodes_vs.glsl | 154 +++------- 6 files changed, 127 insertions(+), 413 deletions(-) diff --git a/data/assets/scene/solarsystem/heliosphere/bastille_day/fluxnodes.asset b/data/assets/scene/solarsystem/heliosphere/bastille_day/fluxnodes.asset index 9bb359dcae..a2f7e178e3 100644 --- a/data/assets/scene/solarsystem/heliosphere/bastille_day/fluxnodes.asset +++ b/data/assets/scene/solarsystem/heliosphere/bastille_day/fluxnodes.asset @@ -32,12 +32,7 @@ local Fluxnodes = { Renderable = { Type = "RenderableFluxNodes", SourceFolder = fluxnodesBinaries, - ColorTablePaths = { - Standard = asset.localResource("transferfunctions/flux-nodes.txt"), - CMR = asset.localResource("transferfunctions/CMR.txt"), - Earth = asset.localResource("transferfunctions/flux-nodes-grey-scale.txt") - }, - + ColorTablePaths = asset.localResource("transferfunctions/CMR.txt"), LoadAtRuntime = true, --ScaleToMeters = 1.0, SecondsBefore = 24*60*60, diff --git a/data/assets/scene/solarsystem/heliosphere/bastille_day/magnetogram_textures.asset b/data/assets/scene/solarsystem/heliosphere/bastille_day/magnetogram_textures.asset index b9e7d9f817..7f673f1265 100644 --- a/data/assets/scene/solarsystem/heliosphere/bastille_day/magnetogram_textures.asset +++ b/data/assets/scene/solarsystem/heliosphere/bastille_day/magnetogram_textures.asset @@ -2,7 +2,6 @@ local assetHelper = asset.require('util/asset_helper') local sun = asset.require('scene/solarsystem/sun/sun') -- synced directories -local textureDirectory = asset.require('./bastille_day_sun_textures').TexturesPath; local magnetogramDirectory = asset.require('./magnetogram').TexturesPath; diff --git a/modules/space/rendering/renderablefluxnodes.cpp b/modules/space/rendering/renderablefluxnodes.cpp index 4c447ca19c..5b7872d6d8 100644 --- a/modules/space/rendering/renderablefluxnodes.cpp +++ b/modules/space/rendering/renderablefluxnodes.cpp @@ -50,23 +50,17 @@ namespace { // log category constexpr const char* _loggerCat = "RenderableFluxNodes"; - - constexpr int8_t CurrentCacheVersion = 2; //streamColor, nodeSize, nodeSizeLargerFlux, thresholdFlux, - constexpr const std::array UniformNames = { - "streamColor", "nodeSize", "nodeSizeLargerFlux", "thresholdFlux", "colorMode", - "filterLower", "filterUpper", "scalingMode", "colorTableRange", "domainLimZ", - "nodeSkip", "nodeSkipDefault", "nodeSkipEarth", "nodeSkipMethod", - "nodeSkipFluxThreshold", "nodeSkipRadiusThreshold", "fluxColorAlpha", - "fluxColorAlphaIlluminance", "earthPos", "distanceThreshold", - "enhanceMethod" - }; - constexpr const std::array UniformNames2 = { - "time", "maxNodeDistanceSize", "usingCameraPerspective", - "drawCircles", "drawHollow", "useGaussian", "usingRadiusPerspective", + constexpr const std::array UniformNames = { + "streamColor", "nodeSize", "proximityNodesSize", + "thresholdFlux", "colorMode", "filterLower", "filterUpper", "scalingMode", + "colorTableRange", "domainLimZ", "nodeSkip", "nodeSkipDefault", "nodeSkipEarth", + "nodeSkipMethod", "nodeSkipFluxThreshold", "nodeSkipRadiusThreshold", + "fluxColorAlpha", "earthPos", "distanceThreshold", "time", "maxNodeDistanceSize", + "usingCameraPerspective", "drawCircles", "drawHollow", "useGaussian", "perspectiveDistanceFactor", "minMaxNodeSize", "usingPulse", - "usingGaussianPulse", "pulsatingAlways" + "usingGaussianPulse" }; constexpr openspace::properties::Property::PropertyInfo GoesEnergyBinsInfo = { @@ -157,12 +151,6 @@ namespace { "Flux Color Alpha", "The value of alpha for the flux color mode." }; - constexpr openspace::properties::Property::PropertyInfo - FluxColorAlphaIlluminanceInfo = { - "FluxColorAlphaIlluminance", - "Flux Color Alpha for illuminance", - "The value of alpha for the flux color mode." - }; constexpr openspace::properties::Property::PropertyInfo FluxNodeskipThresholdInfo = { "SkippingNodesByFlux", "Skipping Nodes By Flux", @@ -174,11 +162,6 @@ namespace { "Skipping Nodes By Radius", "Select nodes to skip depending on Radius." }; - constexpr openspace::properties::Property::PropertyInfo EnhanceMethodInfo = { - "EnhanceMethod", - "Enhance Method", - "Deciding what method to use for nodes close to earth" - }; constexpr openspace::properties::Property::PropertyInfo DistanceplanetInfo = { "Distanceplanet", "Distance Planet", @@ -187,59 +170,23 @@ namespace { constexpr openspace::properties::Property::PropertyInfo DistanceThresholdInfo = { "DistancePlanetThreshold", "Threshold for distance between planet", - "Enhance the size of nodes dependent on distance to planet." + "Changes threshold distance for highlighting nodes close to earth." + }; + constexpr openspace::properties::Property::PropertyInfo ProximityNodesSizeInfo = { + "ProximityNodesSize", + "Earths Proximity Nodes Size", + "Changes size of nodes only close to earth." }; constexpr openspace::properties::Property::PropertyInfo MisalignedIndexInfo = { "MisalignedIndex", "Index to shift sequence number", "The misalignment number for sequence for fluxnodes vs Fieldlines" }; - constexpr openspace::properties::Property::PropertyInfo FlowColorInfo = { - "Flowcolor", - "Color of Flow", - "Color of Flow." - }; - constexpr openspace::properties::Property::PropertyInfo FlowEnabledInfo = { - "FlowEnabled", - "Flow Direction", - "Toggles the rendering of moving particles along the lines. Can, for example, " - "illustrate magnetic flow." - }; - constexpr openspace::properties::Property::PropertyInfo InterestingStreamsInfo = { - "InterestingStreamsEnabled", - "Interesting Streams Enabled", - "Toggles the rendering of selected streams." - }; - constexpr openspace::properties::Property::PropertyInfo FlowParticleSizeInfo = { - "ParticleSize", - "Particle Size", - "Size of the particles." - }; - constexpr openspace::properties::Property::PropertyInfo FlowParticleSpacingInfo = { - "ParticleSpacing", - "Particle Spacing", - "Spacing inbetween particles." - }; - constexpr openspace::properties::Property::PropertyInfo FlowSpeedInfo = { - "Speed", - "Speed", - "Speed of the flow." - }; - constexpr openspace::properties::Property::PropertyInfo UseFlowColorInfo = { - "Coloring", - "Color either by Flowcolor or Flow colortable", - "If set to true the flow will be colored by Flowcolor." - }; constexpr openspace::properties::Property::PropertyInfo MaxNodeDistanceSizeInfo = { "MaxNodeDistanceSize", "Max Node Distance Size", "The maximum size of the nodes at a certin distance." }; - constexpr openspace::properties::Property::PropertyInfo NodeDistanceThresholdInfo = { - "NodeDistanceThreshold", - "Node Distance Threshold", - "Threshold for where to interpolate between the max and min node distance." - }; constexpr openspace::properties::Property::PropertyInfo CameraPerspectiveEnabledInfo = { "CameraPerspectiveEnabled", @@ -263,13 +210,6 @@ namespace { "Using fragment shader to draw nodes with Gaussian filter for alpha value." }; - constexpr openspace::properties::Property::PropertyInfo - RadiusPerspectiveEnabledInfo = { - "RadiusPerspectiveEnabled", - "Include radius with cameraperspective", - "If false, then nodes closer to the sun will not be larger " - "regardless of distance to camera." - }; constexpr openspace::properties::Property::PropertyInfo PerspectiveDistanceFactorInfo = { "PerspectiveDistanceFactor", @@ -282,11 +222,6 @@ namespace { "Min & Max node size", "The minimum and maximum node size." }; - constexpr openspace::properties::Property::PropertyInfo AlwaysPulseInfo = { - "AlwaysPulsate", - "Pulsate regardless of camera position", - "Always have nodes close to earth pulsate regardless of position." - }; constexpr openspace::properties::Property::PropertyInfo pulseEnabledInfo = { "PulseEnabled", "Nodes close to Earth pulsate", @@ -315,14 +250,8 @@ namespace { struct [[codegen::Dictionary(RenderableFluxNodes)]] Parameters { // path to source folder with the 3 binary files in it std::filesystem::path sourceFolder [[codegen::directory()]]; - - struct TransferFunctions { - std::string standard; - std::string earth; - std::string cmr [[codegen::key("CMR")]]; - }; // [[codegen::verbatim(ColorTablePathInfo.description)]] - TransferFunctions colorTablePaths; + std::string colorTablePaths; // [[codegen::verbatim(GoesEnergyBinsInfo.description)]] std::optional energyBin; }; @@ -339,12 +268,10 @@ documentation::Documentation RenderableFluxNodes::Documentation() { RenderableFluxNodes::RenderableFluxNodes(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _goesEnergyBins(GoesEnergyBinsInfo, properties::OptionProperty::DisplayType::Radio) - , _colorGroup({ "Color" }) + , _styleGroup({ "Style" }) , _colorMode(ColorModeInfo, properties::OptionProperty::DisplayType::Radio) , _scalingMethod(ScalingmethodInfo, properties::OptionProperty::DisplayType::Radio) , _nodeskipMethod(NodeskipMethodInfo, properties::OptionProperty::DisplayType::Radio) - , _enhancemethod(EnhanceMethodInfo, properties::OptionProperty::DisplayType::Dropdown) - , _colorTablePath(ColorTablePathInfo) , _streamColor( StreamColorInfo, glm::vec4(0.96f, 0.88f, 0.8f, 1.f), @@ -353,11 +280,10 @@ RenderableFluxNodes::RenderableFluxNodes(const ghoul::Dictionary& dictionary) , _streamGroup({ "Streams" }) , _nodesAmountGroup({ "NodeGroup" }) , _nodeSize(NodeSizeInfo, 2.f, 1.f, 10.f) - , _nodeSizeLargerFlux(NodeSizeLargerFluxInfo, 2.f, 1.f, 10.f) + , _colorTablePath(ColorTablePathInfo) , _colorTableRange(colorTableRangeInfo, { -2.f, 4.f }, { -8.f, -8.f }, { 8.f, 8.f }) , _domainZ(DomainZInfo, { -2.5f, 2.5f }, { -2.5f, -2.5f }, { 2.5f, 2.5f}) - , _fluxColorAlpha(FluxColorAlphaInfo, 0.f, 0.f, 1.f) - , _fluxColorAlphaIlluminance(FluxColorAlphaIlluminanceInfo, 1.f, 0.f, 1.f) + , _fluxColorAlpha(FluxColorAlphaInfo, 1.f, 0.f, 1.f) , _thresholdFlux(ThresholdFluxInfo, -1.5f, -50.f, 10.f) , _filteringLower(FilteringInfo, 0.f, 0.f, 5.f) , _filteringUpper(FilteringUpperInfo, 5.f, 0.f, 5.f) @@ -367,42 +293,24 @@ RenderableFluxNodes::RenderableFluxNodes(const ghoul::Dictionary& dictionary) , _fluxNodeskipThreshold(FluxNodeskipThresholdInfo, 0, -20, 10) , _radiusNodeSkipThreshold(RadiusNodeSkipThresholdInfo, 0.f, 0.f, 5.f) , _earthdistGroup({ "Earthfocus" }) - , _distanceThreshold(DistanceThresholdInfo, 0.0f, 0.0f, 1.0f) - //, _flowColor( - // FlowColorInfo, - // glm::vec4(0.96f, 0.88f, 0.8f, 0.5f), - // glm::vec4(0.f), - // glm::vec4(1.f) - //) - //, _flowEnabled(FlowEnabledInfo, false) - , _interestingStreamsEnabled(InterestingStreamsInfo, false) - , _flowGroup({ "Flow" }) - //, _flowParticleSize(FlowParticleSizeInfo, 5, 0, 500) - //, _flowParticleSpacing(FlowParticleSpacingInfo, 60, 0, 500) - //, _flowSpeed(FlowSpeedInfo, 20, 0, 1000) - //, _useFlowColor(UseFlowColorInfo, false) + , _distanceThreshold(DistanceThresholdInfo, 0.f, 0.f, 1.f) + , _proximityNodesSize(ProximityNodesSizeInfo, 1.f, 0.f, 100.f) , _maxNodeDistanceSize(MaxNodeDistanceSizeInfo, 1.f, 1.f, 10.f) - , _nodeDistanceThreshold(NodeDistanceThresholdInfo, 0.f, 0.f, 40.f) , _cameraPerspectiveEnabled(CameraPerspectiveEnabledInfo, false) , _drawingCircles(DrawingCirclesInfo, false) , _cameraPerspectiveGroup({" CameraPerspective"}) , _drawingHollow(DrawingHollowInfo, false) , _gaussianAlphaFilter(GaussiandAlphaFilterInfo, false) - , _radiusPerspectiveEnabled(RadiusPerspectiveEnabledInfo, true) , _perspectiveDistanceFactor(PerspectiveDistanceFactorInfo, 2.67f, 1.f, 20.f) , _minMaxNodeSize(MinMaxNodeSizeInfo, {2.f, 30.f}, {1.f, 1.f}, {10.f, 200.f}) , _pulseEnabled(pulseEnabledInfo, false) , _gaussianPulseEnabled(gaussianPulseEnabledInfo, false) - , _pulseAlways(AlwaysPulseInfo, false) { const Parameters p = codegen::bake(dictionary); - _transferFunction = std::make_unique(p.colorTablePaths.standard); - _transferFunctionCMR = std::make_unique(p.colorTablePaths.cmr); - _transferFunctionEarth = std::make_unique(p.colorTablePaths.earth); + _colorTablePath = p.colorTablePaths; + _transferFunction = std::make_unique(_colorTablePath); - _colorTablePath = p.colorTablePaths.standard; - _binarySourceFolderPath = p.sourceFolder; if (std::filesystem::is_directory(_binarySourceFolderPath)) { // Extract all file paths from the provided folder @@ -443,16 +351,6 @@ RenderableFluxNodes::RenderableFluxNodes(const ghoul::Dictionary& dictionary) _nodeskipMethod.addOption(static_cast(NodeSkipMethod::Uniform), "Uniform"); _nodeskipMethod.addOption(static_cast(NodeSkipMethod::Flux), "Flux"); _nodeskipMethod.addOption(static_cast(NodeSkipMethod::Radius), "Radius"); - _nodeskipMethod.addOption( - static_cast(NodeSkipMethod::Streamnumber), "Streamnumber" - ); - - _enhancemethod.addOption(static_cast(EnhanceMethod::SizeScaling), "SizeScaling"); - _enhancemethod.addOption(static_cast(EnhanceMethod::ColorTables), "ColorTables"); - _enhancemethod.addOption( - static_cast(EnhanceMethod::SizeAndColor), "Sizescaling and colortables" - ); - _enhancemethod.addOption(static_cast(EnhanceMethod::Illuminance), "Illuminance"); if (p.energyBin.has_value()) { _goesEnergyBins.setValue(p.energyBin.value()); @@ -479,12 +377,9 @@ void RenderableFluxNodes::initializeGL() { _uniformCache.streamColor = _shaderProgram->uniformLocation("streamColor"); _uniformCache.nodeSize = _shaderProgram->uniformLocation("nodeSize"); - _uniformCache.nodeSizeLargerFlux = - _shaderProgram->uniformLocation("nodeSizeLargerFlux"); _uniformCache.thresholdFlux = _shaderProgram->uniformLocation("thresholdFlux"); ghoul::opengl::updateUniformLocations(*_shaderProgram, _uniformCache, UniformNames); - ghoul::opengl::updateUniformLocations(*_shaderProgram, _uniformCache2, UniformNames2); glGenVertexArrays(1, &_vertexArrayObject); glGenBuffers(1, &_vertexPositionBuffer); @@ -498,14 +393,12 @@ void RenderableFluxNodes::initializeGL() { void RenderableFluxNodes::definePropertyCallbackFunctions() { // Add Property Callback Functions - - _colorTablePath.onChange([this] { - _transferFunction->setPath(_colorTablePath); - }); - _goesEnergyBins.onChange([this] { loadNodeData(_goesEnergyBins.option().value); }); + _colorTablePath.onChange([this]() { + _transferFunction->setPath(_colorTablePath); + }); } void RenderableFluxNodes::loadNodeData(int energybinOption) { @@ -585,58 +478,45 @@ void RenderableFluxNodes::loadNodeData(int energybinOption) { void RenderableFluxNodes::setupProperties() { addProperty(_goesEnergyBins); - addPropertySubOwner(_colorGroup); + addPropertySubOwner(_styleGroup); addPropertySubOwner(_streamGroup); addPropertySubOwner(_nodesAmountGroup); addPropertySubOwner(_earthdistGroup); addPropertySubOwner(_cameraPerspectiveGroup); - _colorGroup.addProperty(_colorMode); - _colorGroup.addProperty(_scalingMethod); - _colorGroup.addProperty(_colorTableRange); - _colorGroup.addProperty(_colorTablePath); - _colorGroup.addProperty(_streamColor); - _colorGroup.addProperty(_fluxColorAlpha); - _colorGroup.addProperty(_fluxColorAlphaIlluminance); + _cameraPerspectiveGroup.addProperty(_cameraPerspectiveEnabled); + _cameraPerspectiveGroup.addProperty(_perspectiveDistanceFactor); + _minMaxNodeSize.setViewOption(properties::Property::ViewOptions::MinMaxRange); + _cameraPerspectiveGroup.addProperty(_minMaxNodeSize); - _streamGroup.addProperty(_thresholdFlux); - _streamGroup.addProperty(_filteringLower); - _streamGroup.addProperty(_filteringUpper); - _streamGroup.addProperty(_domainZ); + _earthdistGroup.addProperty(_distanceThreshold); + _earthdistGroup.addProperty(_proximityNodesSize); + _earthdistGroup.addProperty(_pulseEnabled); + _earthdistGroup.addProperty(_gaussianPulseEnabled); _nodesAmountGroup.addProperty(_nodeskipMethod); _nodesAmountGroup.addProperty(_amountofNodes); _nodesAmountGroup.addProperty(_defaultNodeSkip); _nodesAmountGroup.addProperty(_earthNodeSkip); _nodesAmountGroup.addProperty(_nodeSize); - _nodesAmountGroup.addProperty(_nodeSizeLargerFlux); _nodesAmountGroup.addProperty(_fluxNodeskipThreshold); _nodesAmountGroup.addProperty(_radiusNodeSkipThreshold); _nodesAmountGroup.addProperty(_maxNodeDistanceSize); - _nodesAmountGroup.addProperty(_nodeDistanceThreshold); - _earthdistGroup.addProperty(_distanceThreshold); - _earthdistGroup.addProperty(_enhancemethod); - _earthdistGroup.addProperty(_interestingStreamsEnabled); + _streamGroup.addProperty(_thresholdFlux); + _streamGroup.addProperty(_filteringLower); + _streamGroup.addProperty(_filteringUpper); + _streamGroup.addProperty(_domainZ); - //_flowGroup.addProperty(_flowEnabled); - //_flowGroup.addProperty(_flowColor); - //_flowGroup.addProperty(_flowParticleSize); - //_flowGroup.addProperty(_flowParticleSpacing); - //_flowGroup.addProperty(_flowSpeed); - //_flowGroup.addProperty(_useFlowColor); - - _cameraPerspectiveGroup.addProperty(_cameraPerspectiveEnabled); - _cameraPerspectiveGroup.addProperty(_perspectiveDistanceFactor); - _cameraPerspectiveGroup.addProperty(_drawingCircles); - _cameraPerspectiveGroup.addProperty(_drawingHollow); - _cameraPerspectiveGroup.addProperty(_gaussianAlphaFilter); - _cameraPerspectiveGroup.addProperty(_radiusPerspectiveEnabled); - _minMaxNodeSize.setViewOption(properties::Property::ViewOptions::MinMaxRange); - _cameraPerspectiveGroup.addProperty(_minMaxNodeSize); - _cameraPerspectiveGroup.addProperty(_pulseEnabled); - _cameraPerspectiveGroup.addProperty(_gaussianPulseEnabled); - _cameraPerspectiveGroup.addProperty(_pulseAlways); + _styleGroup.addProperty(_drawingCircles); + _styleGroup.addProperty(_drawingHollow); + _styleGroup.addProperty(_gaussianAlphaFilter); + _styleGroup.addProperty(_colorMode); + _styleGroup.addProperty(_scalingMethod); + _styleGroup.addProperty(_colorTableRange); + _styleGroup.addProperty(_colorTablePath); + _styleGroup.addProperty(_streamColor); + _styleGroup.addProperty(_fluxColorAlpha); definePropertyCallbackFunctions(); } @@ -796,10 +676,6 @@ void RenderableFluxNodes::render(const RenderData& data, RendererTasks&) { _shaderProgram->setUniform(_uniformCache.streamColor, _streamColor); _shaderProgram->setUniform(_uniformCache.nodeSize, _nodeSize); - _shaderProgram->setUniform( - _uniformCache.nodeSizeLargerFlux, - _nodeSizeLargerFlux - ); _shaderProgram->setUniform(_uniformCache.thresholdFlux, _thresholdFlux); _shaderProgram->setUniform(_uniformCache.colorMode, _colorMode); _shaderProgram->setUniform(_uniformCache.filterLower, _filteringLower); @@ -812,7 +688,7 @@ void RenderableFluxNodes::render(const RenderData& data, RendererTasks&) { _shaderProgram->setUniform(_uniformCache.nodeSkipEarth, _earthNodeSkip); _shaderProgram->setUniform(_uniformCache.nodeSkipMethod, _nodeskipMethod); _shaderProgram->setUniform( - _uniformCache.nodeSkipFluxThreshold, + _uniformCache.nodeSkipFluxThreshold, _fluxNodeskipThreshold ); _shaderProgram->setUniform( @@ -820,63 +696,46 @@ void RenderableFluxNodes::render(const RenderData& data, RendererTasks&) { _radiusNodeSkipThreshold ); _shaderProgram->setUniform(_uniformCache.fluxColorAlpha, _fluxColorAlpha); - _shaderProgram->setUniform( - _uniformCache.fluxColorAlphaIlluminance, - _fluxColorAlphaIlluminance - ); + _shaderProgram->setUniform(_uniformCache.earthPos, earthPos); _shaderProgram->setUniform(_uniformCache.distanceThreshold, _distanceThreshold); - _shaderProgram->setUniform(_uniformCache.enhanceMethod, _enhancemethod); + _shaderProgram->setUniform(_uniformCache.proximityNodesSize, _proximityNodesSize); _shaderProgram->setUniform( - _uniformCache2.time, + _uniformCache.time, global::windowDelegate->applicationTime() ); _shaderProgram->setUniform( - _uniformCache2.maxNodeDistanceSize, + _uniformCache.maxNodeDistanceSize, _maxNodeDistanceSize ); _shaderProgram->setUniform( - _uniformCache2.usingCameraPerspective, + _uniformCache.usingCameraPerspective, _cameraPerspectiveEnabled ); - _shaderProgram->setUniform(_uniformCache2.drawCircles, _drawingCircles); - _shaderProgram->setUniform(_uniformCache2.drawHollow, _drawingHollow); - _shaderProgram->setUniform(_uniformCache2.useGaussian, _gaussianAlphaFilter); + _shaderProgram->setUniform(_uniformCache.drawCircles, _drawingCircles); + _shaderProgram->setUniform(_uniformCache.drawHollow, _drawingHollow); + _shaderProgram->setUniform(_uniformCache.useGaussian, _gaussianAlphaFilter); + _shaderProgram->setUniform( - _uniformCache2.usingRadiusPerspective, - _radiusPerspectiveEnabled - ); - _shaderProgram->setUniform( - _uniformCache2.perspectiveDistanceFactor, + _uniformCache.perspectiveDistanceFactor, _perspectiveDistanceFactor ); - _shaderProgram->setUniform(_uniformCache2.minMaxNodeSize, _minMaxNodeSize); - _shaderProgram->setUniform(_uniformCache2.usingPulse, _pulseEnabled); + _shaderProgram->setUniform(_uniformCache.minMaxNodeSize, _minMaxNodeSize); + _shaderProgram->setUniform(_uniformCache.usingPulse, _pulseEnabled); _shaderProgram->setUniform( - _uniformCache2.usingGaussianPulse, + _uniformCache.usingGaussianPulse, _gaussianPulseEnabled ); - _shaderProgram->setUniform(_uniformCache2.pulsatingAlways, _pulseAlways); glm::vec3 cameraPos = data.camera.positionVec3() * data.modelTransform.rotation; _shaderProgram->setUniform("cameraPos", cameraPos); - ghoul::opengl::TextureUnit textureUnit; - ghoul::opengl::TextureUnit textureUnitCMR; - ghoul::opengl::TextureUnit textureUnitEarth; if (_colorMode == static_cast(ColorMethod::ByFluxValue)) { + ghoul::opengl::TextureUnit textureUnit; textureUnit.activate(); _transferFunction->bind(); // Calls update internally _shaderProgram->setUniform("colorTable", textureUnit); - - textureUnitCMR.activate(); - _transferFunctionCMR->bind(); // Calls update internally - _shaderProgram->setUniform("colorTableCMR", textureUnitCMR); - - textureUnitEarth.activate(); - _transferFunctionEarth->bind(); // Calls update internally - _shaderProgram->setUniform("colorTableEarth", textureUnitEarth); } glBindVertexArray(_vertexArrayObject); @@ -954,11 +813,6 @@ void RenderableFluxNodes::update(const UpdateData& data) { _uniformCache, UniformNames ); - ghoul::opengl::updateUniformLocations( - *_shaderProgram, - _uniformCache2, - UniformNames2 - ); } } diff --git a/modules/space/rendering/renderablefluxnodes.h b/modules/space/rendering/renderablefluxnodes.h index 3522a7f7c8..f388256d79 100644 --- a/modules/space/rendering/renderablefluxnodes.h +++ b/modules/space/rendering/renderablefluxnodes.h @@ -94,17 +94,14 @@ private: Illuminance = 3, }; - UniformCache(streamColor, nodeSize, nodeSizeLargerFlux, thresholdFlux, colorMode, - filterLower, filterUpper, scalingMode, colorTableRange, domainLimZ, nodeSkip, - nodeSkipDefault, nodeSkipEarth, nodeSkipMethod, nodeSkipFluxThreshold, - nodeSkipRadiusThreshold, fluxColorAlpha, fluxColorAlphaIlluminance, earthPos, - distanceThreshold, enhanceMethod) + UniformCache(streamColor, nodeSize, proximityNodesSize, + thresholdFlux, colorMode, filterLower, filterUpper, scalingMode, colorTableRange, + domainLimZ, nodeSkip, nodeSkipDefault, nodeSkipEarth, nodeSkipMethod, + nodeSkipFluxThreshold, nodeSkipRadiusThreshold, fluxColorAlpha, + earthPos, distanceThreshold, time, maxNodeDistanceSize, usingCameraPerspective, + drawCircles, drawHollow, useGaussian, perspectiveDistanceFactor, minMaxNodeSize, + usingPulse, usingGaussianPulse) _uniformCache; - UniformCache(time, maxNodeDistanceSize, usingCameraPerspective, - drawCircles, drawHollow, useGaussian, usingRadiusPerspective, - perspectiveDistanceFactor, minMaxNodeSize, usingPulse, - usingGaussianPulse, pulsatingAlways) - _uniformCache2; std::filesystem::path _binarySourceFolderPath; @@ -129,14 +126,8 @@ private: std::unique_ptr _shaderProgram; - // Transfer function used to color lines when _pColorMethod is set to BY_FLUX_VALUE + // Transfer function used to color lines when _colorMethod is set to by_flux_value std::unique_ptr _transferFunction; - // Transfer function used to color with the CMR map - std::unique_ptr _transferFunctionCMR; - // Transfer function used to color line near Earth - std::unique_ptr _transferFunctionEarth; - // Transfer function used to color line flow - std::unique_ptr _transferFunctionFlow; std::vector _binarySourceFiles; // Contains the _triggerTimes for all streams in the sequence @@ -160,21 +151,17 @@ private: // Property to show different energybins properties::OptionProperty _goesEnergyBins; // Group to hold the color properties - properties::PropertyOwner _colorGroup; + properties::PropertyOwner _styleGroup; // Uniform/transfer function properties::OptionProperty _colorMode; // Uniform stream Color properties::Vec4Property _streamColor; - // Choose different distant to earth enhanchement method. - properties::OptionProperty _enhancemethod; - // Color table/transfer function for "By Flux value" coloring + // Path to transferfunction properties::StringProperty _colorTablePath; // Valid range for the color table properties::Vec2Property _colorTableRange; // The value of alpha for the flux color mode properties::FloatProperty _fluxColorAlpha; - // The value of alpha for the flux illuminance color mode - properties::FloatProperty _fluxColorAlphaIlluminance; // Group to hold the particle properties properties::PropertyOwner _streamGroup; // Scaling options @@ -183,19 +170,13 @@ private: properties::PropertyOwner _nodesAmountGroup; // Size of simulated node particles properties::FloatProperty _nodeSize; - // Size of nodes for larger flux - properties::FloatProperty _nodeSizeLargerFlux; // Threshold from earth to decide the distance for which the nodeSize gets larger properties::FloatProperty _distanceThreshold; + // Change size of nodes close to earth + properties::FloatProperty _proximityNodesSize; // Maximum size of nodes at a certin distance properties::FloatProperty _maxNodeDistanceSize; - // Threshold for where to interpolate between the max and min node distance - properties::FloatProperty _nodeDistanceThreshold; - // Toggle selected streams [ON/OFF] - properties::BoolProperty _interestingStreamsEnabled; - //properties::FloatProperty _maxNodeSize; - //properties::FloatProperty _minNodeSize; properties::Vec2Property _minMaxNodeSize; // Valid range along the Z-axis @@ -221,32 +202,13 @@ private: //_pDefaultNodeSkip and _pAmountofNodes properties::FloatProperty _radiusNodeSkipThreshold; - // Flow Properties - // Simulated particles' color - //properties::Vec4Property _flowColor; - // Toggle flow [ON/OFF] - //properties::BoolProperty _flowEnabled; - // Group to hold the flow/particle properties - properties::PropertyOwner _flowGroup; - // Size of simulated flow particles - //properties::IntProperty _flowParticleSize; - // Size of simulated flow particles - //properties::IntProperty _flowParticleSpacing; - // Toggle flow direction [FORWARDS/BACKWARDS] - //properties::BoolProperty _pFlowReversed; - // Speed of simulated flow - //properties::IntProperty _flowSpeed; - //Either use flowcolortable or FlowColor. - //properties::BoolProperty _useFlowColor; properties::PropertyOwner _cameraPerspectiveGroup; properties::BoolProperty _cameraPerspectiveEnabled; properties::BoolProperty _drawingCircles; properties::BoolProperty _drawingHollow; properties::BoolProperty _gaussianAlphaFilter; - properties::BoolProperty _radiusPerspectiveEnabled; properties::FloatProperty _perspectiveDistanceFactor; properties::BoolProperty _pulseEnabled; properties::BoolProperty _gaussianPulseEnabled; - properties::BoolProperty _pulseAlways; }; } // namespace openspace diff --git a/modules/space/shaders/fluxnodes_fs.glsl b/modules/space/shaders/fluxnodes_fs.glsl index d0fdf0a85a..8f02e46812 100644 --- a/modules/space/shaders/fluxnodes_fs.glsl +++ b/modules/space/shaders/fluxnodes_fs.glsl @@ -28,26 +28,20 @@ in vec2 vs_st; in vec4 vs_color; in float vs_depth; in float vs_closeToEarth; -in flat double vs_time; -in float camera_IsCloseEnough; -uniform sampler2D texture1; uniform bool drawCircles; uniform bool drawHollow; uniform bool useGaussian; uniform bool usingCameraPerspective; -uniform bool pulsatingAlways; -uniform bool usingPulse; uniform bool usingGaussianPulse; uniform vec3 cameraPos; -uniform vec4 streamColor; Fragment getFragment() { vec4 fragColor = vs_color; if (vs_color.a == 0) { discard; } - + vec2 pos = vec2(0.5) - vs_st; float r = length(pos) * 2.0; @@ -66,18 +60,17 @@ Fragment getFragment() { discard; } - if (drawHollow && + if (drawHollow && length(coord) < 0.4 && - (vs_closeToEarth > 0.5 || distance(cameraPos, vec3(0.0)) < 500000000000.0)) + (vs_closeToEarth > 0.5 || distance(cameraPos, vec3(0.0)) < 500000000000.0)) { - if (usingGaussianPulse && + if (usingGaussianPulse && usingCameraPerspective && - vs_closeToEarth > 0.5) + vs_closeToEarth > 0.5) { - if (length(coord) < 0.3 && (pulsatingAlways || camera_IsCloseEnough > 0.5)) { - float e = 2.718055; - float y = 1.0 * - pow(e, - (pow(length(coord), 2.0)) /( 2.0 * pow(0.2, 2.0))); + if (length(coord) < 0.3) { + float e = 2.718055; + float y = pow(e, - (pow(length(coord), 2.0)) /( 2.0 * pow(0.2, 2.0))); if (y < 0.05) { discard; } @@ -89,34 +82,15 @@ Fragment getFragment() { } } - float e = 2.718055; - if (useGaussian) { - float y = 1.0 * pow(e, - (pow(length(coord), 2.0)) /( 2.0 * pow(0.2, 2.0))); + float e = 2.718055; + float y = pow(e, - (pow(length(coord), 2.0)) /( 2.0 * pow(0.2, 2.0))); if (y < 0.05) { discard; } frag.color.a = y; } - if (usingPulse && - usingCameraPerspective && - vs_closeToEarth > 0.5 && - (pulsatingAlways || camera_IsCloseEnough > 0.5) && - length(coord) > 0.46) - { - float speed = 60.0; - int modulusResult = int(double(speed) * vs_time) % 60; - if (modulusResult > 0 && modulusResult < 30) { - discard; - } - } - frag.gPosition = vec4(1e27, 1e27, 1e27, 1.0); - frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); - // There is no normal here - // TODO: Add the correct normal if necessary (JCC) - // frag.gNormal = vec4(0.0, 0.0, -1.0, 1.0); - return frag; } diff --git a/modules/space/shaders/fluxnodes_vs.glsl b/modules/space/shaders/fluxnodes_vs.glsl index 26267ee054..2a3728552e 100644 --- a/modules/space/shaders/fluxnodes_vs.glsl +++ b/modules/space/shaders/fluxnodes_vs.glsl @@ -26,18 +26,16 @@ #include "PowerScaling/powerScalingMath.hglsl" // Inputs -// Should be provided in meters VaPosition +// Should be provided in meters layout(location = 0) in vec3 in_position; -// The extra value used to color lines. Location must correspond to VaColor in -// renderablefluxnodes.h +// The extra value used to color lines layout(location = 1) in float fluxValue; -// The extra value used to mask out parts of lines. Location must correspond to -// VaFiltering in renderablefluxnodes.h +// The extra value used to mask out parts of lines layout(location = 2) in float rValue; -// These should correspond to the enum 'ColorMode' in renderablefluxnodes.cpp +// These should correspond to the enum 'ColorMode' const int colorByFluxValue = 0; const int uniformColor = 1; @@ -51,19 +49,11 @@ const int R2Flux = 2; const int log10RFlux = 3; const int lnRFlux = 4; -const int sizeScaling = 0; -const int colorTables = 1; -const int sizeAndColor = 2; -const int illuminance = 3; - const float AUtoMeter = 149597871000.0; out vec4 vs_color; out float vs_depth; out vec2 vs_st; -out float camera_IsCloseEnough; out float vs_closeToEarth; -out double vs_time; -out vec3 vs_camerapos; // General Uniforms that's always needed uniform mat4 modelViewProjection; @@ -71,24 +61,12 @@ uniform mat4 modelViewProjection; // Uniforms needed to color by quantity uniform int colorMode; uniform sampler1D colorTable; -uniform sampler1D colorTableCMR; -uniform sampler1D colorTableEarth; -//uniform sampler1D colorTableFlow; uniform vec2 colorTableRange; -// Masking Uniforms -uniform bool usingMasking; -uniform vec2 maskingRange; - -// Domain Uniforms -uniform vec2 domainLimX; -uniform vec2 domainLimY; uniform vec2 domainLimZ; -uniform vec2 domainLimR; // Fluxnodes specific uniforms uniform float nodeSize; -uniform float nodeSizeLargerFlux; uniform vec4 streamColor; uniform float thresholdFlux; uniform float filterLower; @@ -101,23 +79,20 @@ uniform int nodeSkipEarth; uniform float nodeSkipFluxThreshold; uniform float nodeSkipRadiusThreshold; uniform float fluxColorAlpha; -uniform float fluxColorAlphaIlluminance; uniform vec3 earthPos; uniform float distanceThreshold; -uniform int enhanceMethod; +uniform float proximityNodesSize; uniform double time; // Speicific uniforms for cameraperspective uniform float maxNodeDistanceSize; -uniform float nodeDistanceThreshold; uniform vec3 cameraPos; //uniform vec2 screenSize; uniform bool usingCameraPerspective; -uniform bool usingRadiusPerspective; uniform float perspectiveDistanceFactor; -uniform vec2 minMaxNodeSize; +uniform vec2 minMaxNodeSize; uniform bool usingPulse; vec4 getTransferFunctionColor(sampler1D inColorTable) { @@ -140,9 +115,9 @@ vec4 getTransferFunctionColor(sampler1D inColorTable) { else if (scalingMode == R2Flux) { scaleValue = rValue * rValue * fluxValue; } - float lookUpVal = (scaleValue - colorTableRange.x) / (colorTableRange.y - colorTableRange.x); + return texture(inColorTable, lookUpVal); } @@ -173,69 +148,35 @@ bool checkIfSkipVertex() { return false; } -//function for showing nodes different depending on distance to earth -void decideHowToShowCloseToEarth() { - // SizeScaling - if (enhanceMethod == sizeScaling || enhanceMethod == illuminance) { - vec4 fluxColor = getTransferFunctionColor(colorTableCMR); - vs_color = vec4(fluxColor.xyz, fluxColor.a); - } - // ColorTables - if (enhanceMethod == colorTables) { - vec4 fluxColor = getTransferFunctionColor(colorTable); - vs_color = vec4(fluxColor.xyz, fluxColor.a); - } - // SizeColor - if (enhanceMethod == sizeAndColor) { - vec4 fluxColor3 = getTransferFunctionColor(colorTable); - vs_color = vec4(fluxColor3.xyz, fluxColor3.a); - - float tempR2 = rValue + 0.4; - if (tempR2 > 1.5) { - tempR2 = 1.5; - } - gl_PointSize = tempR2 * tempR2 * tempR2 * gl_PointSize * 5; - } -} - -void checkdistanceMethod() { - //Enhance by distance to Earth +void whatToDoIfCloseToEarth() { float maxdist = 10000000000.0 * perspectiveDistanceFactor; float distancevec = distance(earthPos, in_position.xyz); - vs_closeToEarth = 0.0; - if (distancevec < AUtoMeter * distanceThreshold && usingPulse) { + if (distancevec < AUtoMeter * distanceThreshold) { + if (usingPulse) { + int speed = 2; + int modulusResult = int(speed * time) % 2; + if (fluxValue > thresholdFlux){ + if (modulusResult == 1) { + vs_color.a = 0.01; + } + else { + vs_color.a = 1.0; + } + } + else { + vs_color.a = 0.0; + } + } vs_closeToEarth = 1.0; - gl_PointSize = gl_PointSize * 5; - vec4 fluxColor = getTransferFunctionColor(colorTable); - vs_color = vec4(fluxColor.xyz, fluxColorAlpha); - } - if (enhanceMethod == colorTables || enhanceMethod == sizeAndColor) { - vec4 fluxColor = getTransferFunctionColor(colorTableEarth); - vs_color = vec4(fluxColor.xyz, fluxColorAlpha); - } - if (enhanceMethod == illuminance) { - vec4 fluxColor = getTransferFunctionColor(colorTableCMR); - vs_color = vec4(fluxColor.xyz, fluxColorAlpha); - } - if (distance(earthPos, in_position) < AUtoMeter * distanceThreshold) { if (mod(gl_VertexID, nodeSkipEarth) == 0) { - decideHowToShowCloseToEarth(); + gl_PointSize = proximityNodesSize; } else { vs_color = vec4(0.0); } } - else { - if (enhanceMethod == illuminance) { - vs_color.a = fluxColorAlphaIlluminance; - } - - if (fluxValue < thresholdFlux) { - vs_color.a = fluxColorAlpha; - } - } } void main() { @@ -244,30 +185,28 @@ void main() { // Checking if we should render the vertex dependent on the vertexindex, // by using modulus. - if (checkIfSkipVertex() || - distance(earthPos, in_position) < (distanceThreshold * AUtoMeter) && - rValue/AUtoMeter > filterLower && - rValue/AUtoMeter < filterUpper && + if ((checkIfSkipVertex() || + distance(earthPos, in_position) < (distanceThreshold * AUtoMeter)) && + filterLower < rValue / AUtoMeter && + filterUpper > rValue / AUtoMeter && in_position.z > (domainLimZ.x * AUtoMeter) && in_position.z < (domainLimZ.y * AUtoMeter)) { - // We should color it by flux - if (colorMode == 0) { - vec4 fluxColor = getTransferFunctionColor(colorTableCMR); + vs_color = getTransferFunctionColor(colorTable); + if (colorMode == colorByFluxValue) { if (fluxValue > thresholdFlux) { - vs_color = vec4(fluxColor.xyz, fluxColor.a); - gl_PointSize = nodeSizeLargerFlux; - } - else { - vs_color = vec4(fluxColor.xyz, fluxColorAlpha); + vs_color = getTransferFunctionColor(colorTable); + vs_color.a = fluxColorAlpha; gl_PointSize = nodeSize; } + else { + vs_color.a = 0.0; + } } - else { - //Uniform coloring + else if (colorMode == uniformColor){ vs_color = streamColor; } - checkdistanceMethod(); + whatToDoIfCloseToEarth(); } else { vs_color = vec4(0.0); @@ -279,23 +218,15 @@ void main() { float maxDistance = 100000000000.0 * perspectiveDistanceFactor; float distanceVec = distance(cameraPos, in_position.xyz); - if (distanceVec < maxDistance) { - camera_IsCloseEnough = 0.0; - } - else { - camera_IsCloseEnough = 1.0; - } - if (distanceVec < maxDistance) { float distScale = 1.0 - smoothstep(0.0, maxDistance, distanceVec); - float factorS = 1.0; - if (usingRadiusPerspective) { - factorS = pow(distScale, 9.0) * 500.0 * pow(rtemp, 2.0); + float factorS = pow(distScale, 9.0) * 500.0; + if (distance(earthPos, in_position.xyz) < (distanceThreshold * AUtoMeter)) { + gl_PointSize = proximityNodesSize; } else { - factorS = pow(distScale, 9.0) * 500.0; + gl_PointSize = factorS * maxNodeDistanceSize; } - gl_PointSize = factorS * maxNodeDistanceSize * 0.8; } if (gl_PointSize > minMaxNodeSize.y) { @@ -307,7 +238,6 @@ void main() { } } - vs_time = time; vec4 position_in_meters = vec4(in_position, 1.0); vec4 positionClipSpace = modelViewProjection * position_in_meters;