diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index 23b482c579..7cf1bc81c0 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit 23b482c57907972c966ee8f2ad92204179819525 +Subproject commit 7cf1bc81c05bf41db0a184ae31063a0ac368a932 diff --git a/data/assets/default.scene b/data/assets/default.scene index 2217ee6832..7dec0294f3 100644 --- a/data/assets/default.scene +++ b/data/assets/default.scene @@ -21,17 +21,6 @@ asset.request('customization/globebrowsing') -- Keybindings that are specific for this scene local Keybindings = { - { - Key = "s", - Command = propertyHelper.invert('Scene.Earth.Renderable.Layers.NightLayers.Earth at Night 2012.Enabled') .. - propertyHelper.invert('Scene.Earth.Renderable.PerformShading') .. - propertyHelper.invert('Scene.Earth.Renderable.Atmosphere') .. - propertyHelper.invert('Scene.Earth.Renderable.Layers.WaterMasks.MODIS_Water_Mask.Enabled'), - Name = "Night for earth", - Documentation = "Toggle night texture, shading, atmosphere, and water for Earth.", - GuiPath = "/Rendering", - Local = false - }, { Key = "b", Name = "Toggle background", diff --git a/data/assets/examples/basic.scene b/data/assets/examples/basic.scene new file mode 100644 index 0000000000..182c4776fe --- /dev/null +++ b/data/assets/examples/basic.scene @@ -0,0 +1,21 @@ +local assetHelper = asset.require('util/asset_helper') +local sceneHelper = asset.require('util/scene_helper') +local propertyHelper = asset.require('util/property_helper') + +-- At this point, a sceene needs basic spice data to load. +asset.require('spice/base') + +asset.require('util/default_keybindings') +asset.require('util/default_dashboard') +asset.require('util/default_joystick') + +asset.require('util/webgui') +local spheres = asset.require('examples/spheres') + +asset.onInitialize(function () + openspace.navigation.setCameraState({ + Anchor = spheres.ExampleSphere1.Identifier, + Position = { 20, 0, 0 }, + Rotation = { 0.758797, 0.221490, -0.605693, -0.091135 } + }) +end) diff --git a/data/assets/examples/spheres.asset b/data/assets/examples/spheres.asset new file mode 100644 index 0000000000..2510084d70 --- /dev/null +++ b/data/assets/examples/spheres.asset @@ -0,0 +1,34 @@ +local assetHelper = asset.require('util/asset_helper') + +local i = 1 +for z=1,3 do + for y=1,3 do + for x=1,3 do + local sphere = { + Identifier = "ExampleSphere" .. i, + Transform = { + Translation = { + Type = "StaticTranslation", + Position = {x, y, z} + } + }, + Renderable = { + Type = "RenderableSphere", + Enabled = true, + Size = 0.20 + i * 0.01, + Segments = 80, + Opacity = 1, + Texture = "${DATA}/test2.jpg", + Orientation = "Both", + }, + GUI = { + Name = "Test Sphere " .. i, + Path = "/Other/Spheres" + } + } + assetHelper.registerSceneGraphNodesAndExport(asset, { sphere }) + i = i + 1 + end + end +end + diff --git a/data/assets/newhorizons.scene b/data/assets/newhorizons.scene index 4821bcd3b7..6403b6d543 100644 --- a/data/assets/newhorizons.scene +++ b/data/assets/newhorizons.scene @@ -1,38 +1,29 @@ +asset.require('default'); + +asset.require('scene/solarsystem/missions/newhorizons/newhorizons') +local NewHorizonsAsset = asset.require('scene/solarsystem/missions/newhorizons/model') + local assetHelper = asset.require('util/asset_helper') -local sceneHelper = asset.require('util/scene_helper') local propertyHelper = asset.require('util/property_helper') +local sceneHelper = asset.require('util/scene_helper') local renderableHelper = asset.require('util/renderable_helper') --- Specifying which other assets should be loaded in this scene -asset.require('spice/base') -assetHelper.requestAll(asset, 'scene/solarsystem/sun') -asset.require('scene/solarsystem/planets') -asset.request('scene/digitaluniverse/stars') -asset.request('scene/digitaluniverse/milkyway') -asset.require('scene/solarsystem/missions/newhorizons/newhorizons') - --- Load default key bindings applicable to most scenes -asset.require('util/default_keybindings') -asset.require('util/default_dashboard') -asset.require('util/default_joystick') - -asset.require('util/webgui') - -asset.request('customization/globebrowsing') - --- Custom Keybindings local Keybindings = { { Key = "a", - Command = "openspace.setPropertyValue('NavigationHandler.Origin', 'NewHorizons')", + Command = "openspace.setPropertyValue('NavigationHandler.OrbitalNavigator.Anchor', 'NewHorizons');" .. + "openspace.setPropertyValue('NavigationHandler.OrbitalNavigator.Aim', 'Pluto');" .. + "openspace.setPropertyValue('NavigationHandler.OrbitalNavigator.RetargetAnchor', nil)", Documentation = "Sets the focus of the camera on 'NewHorizons'.", - Name = "Focus on New Horizons", + Name = "Anchor at New Horizons, Aim at Pluto", GuiPath = "/New Horizons", Local = false }, { Key = "s", - Command = "openspace.setPropertyValue('NavigationHandler.Origin', 'Pluto')", + Command = "openspace.setPropertyValue('NavigationHandler.OrbitalNavigator.Anchor', 'Pluto');".. + "openspace.setPropertyValue('NavigationHandler.OrbitalNavigator.Aim', '');" .. + "openspace.setPropertyValue('NavigationHandler.OrbitalNavigator.RetargetAnchor', nil)", Documentation = "Sets the focus of the camera on 'Pluto'", Name = "Focus on Pluto", GuiPath = "/New Horizons", @@ -40,7 +31,9 @@ local Keybindings = { }, { Key = "d", - Command = "openspace.setPropertyValue('NavigationHandler.Origin', 'Charon')", + Command = "openspace.setPropertyValue('NavigationHandler.OrbitalNavigator.Anchor', 'Charon');".. + "openspace.setPropertyValue('NavigationHandler.OrbitalNavigator.Aim', '');" .. + "openspace.setPropertyValue('NavigationHandler.OrbitalNavigator.RetargetAnchor', nil)", Documentation = "Sets the focus of the camera on 'Charon'.", Name = "Focus on New Charon", GuiPath = "/New Horizons", @@ -60,8 +53,8 @@ openspace.setPropertyValueSingle("Dashboard.NewHorizonsInstruments.Enabled", not }, { Key = "F8", - Command = "openspace.setPropertyValue('Scene.Pluto.Renderable.ProjectionComponent.ClearAllProjections', true);" .. - "openspace.setPropertyValue('Scene.Charon.Renderable.ProjectionComponent.ClearAllProjections', true);", + Command = "openspace.setPropertyValue('Scene.PlutoProjection.Renderable.ProjectionComponent.ClearAllProjections', true);" .. + "openspace.setPropertyValue('Scene.CharonProjection.Renderable.ProjectionComponent.ClearAllProjections', true);", Documentation = "Removes all image projections from Pluto and Charon.", Name = "Clear image projections", GuiPath = "/New Horizons", @@ -70,8 +63,8 @@ openspace.setPropertyValueSingle("Dashboard.NewHorizonsInstruments.Enabled", not { Key = "F9", Command = "openspace.time.setTime('2015-07-14T09:00:00.00');" .. - "openspace.setPropertyValue('Scene.Pluto.Renderable.ClearAllProjections', true);" .. - "openspace.setPropertyValue('Scene.Charon.Renderable.ClearAllProjections', true);", + "openspace.setPropertyValue('Scene.PlutoProjection.Renderable.ClearAllProjections', true);" .. + "openspace.setPropertyValue('Scene.CharonProjection.Renderable.ClearAllProjections', true);", Documentation = "Jumps to the 14th of July 2015 at 0900 UTC and clears all projections.", Name = "Reset time and projections", GuiPath = "/New Horizons", @@ -79,7 +72,7 @@ openspace.setPropertyValueSingle("Dashboard.NewHorizonsInstruments.Enabled", not }, { Key = "KP_8", - Command = propertyHelper.increment('Scene.Pluto.Renderable.HeightExaggeration', 5000), + Command = propertyHelper.increment('Scene.PlutoProjection.Renderable.HeightExaggeration', 5000), Documentation = "Increases the height map exaggeration on Pluto.", Name = "Pluto HeightExaggeration +", GuiPath = "/New Horizons", @@ -87,7 +80,7 @@ openspace.setPropertyValueSingle("Dashboard.NewHorizonsInstruments.Enabled", not }, { Key = "KP_2", - Command = propertyHelper.decrement('Scene.Pluto.Renderable.HeightExaggeration', 5000), + Command = propertyHelper.decrement('Scene.PlutoProjection.Renderable.HeightExaggeration', 5000), Documentation = "Decreases the height map exaggeration on Pluto.", Name = "Pluto HeightExaggeration -", GuiPath = "/New Horizons", @@ -95,7 +88,7 @@ openspace.setPropertyValueSingle("Dashboard.NewHorizonsInstruments.Enabled", not }, { Key = "KP_9", - Command = propertyHelper.increment('Scene.Charon.Renderable.HeightExaggeration', 5000), + Command = propertyHelper.increment('Scene.CharonProjection.Renderable.HeightExaggeration', 5000), Documentation = "Increases the height map exaggeration on Charon.", Name = "Charon HeightExaggeration +", GuiPath = "/New Horizons", @@ -103,7 +96,7 @@ openspace.setPropertyValueSingle("Dashboard.NewHorizonsInstruments.Enabled", not }, { Key = "KP_3", - Command = propertyHelper.decrement('Scene.Charon.Renderable.HeightExaggeration', 5000), + Command = propertyHelper.decrement('Scene.CharonProjection.Renderable.HeightExaggeration', 5000), Documentation = "Decreases the height map exaggeration on Charon.", Name = "Charon HeightExaggeration -", GuiPath = "/New Horizons", @@ -111,7 +104,7 @@ openspace.setPropertyValueSingle("Dashboard.NewHorizonsInstruments.Enabled", not }, { Key = "o", - Command = propertyHelper.invert('Scene.PlutoTrail.Renderable.Enabled'), + Command = propertyHelper.invert('Scene.PlutoBarycentricTrail.Renderable.Enabled'), Documentation = "Toggles the visibility of the trail behind Pluto.", Name = "Toggle Pluto Trail", GuiPath = "/New Horizons", @@ -169,10 +162,8 @@ openspace.setPropertyValueSingle("Dashboard.NewHorizonsInstruments.Enabled", not GuiPath = "/New Horizons", Local = false } - } -local NewHorizonsAsset = asset.require('scene/solarsystem/missions/newhorizons/model') assetHelper.registerDashboardItems(asset, { { @@ -188,7 +179,7 @@ assetHelper.registerDashboardItems(asset, { SourceType = "Node", SourceNodeName = "NewHorizons", DestinationType = "Node Surface", - DestinationNodeName = "Pluto" + DestinationNodeName = "PlutoProjection" }, { Type = "DashboardItemInstruments", @@ -213,6 +204,9 @@ asset.onInitialize(function () }) openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.FollowAnchorNodeRotationDistance', 20.000000); + openspace.setPropertyValueSingle('Scene.Pluto.Renderable.Enabled', false) + openspace.setPropertyValueSingle('Scene.Charon.Renderable.Enabled', false) + openspace.setPropertyValueSingle("Scene.PlutoBarycenterTrail.Renderable.Enabled", false) openspace.addVirtualProperty( "BoolProperty", @@ -233,6 +227,9 @@ end) asset.onDeinitialize(function () sceneHelper.unbindKeys(Keybindings) + openspace.setPropertyValueSingle('Scene.Pluto.Renderable.Enabled', true) + openspace.setPropertyValueSingle('Scene.Charon.Renderable.Enabled', true) + openspace.setPropertyValueSingle('Scene.PlutoBarycenterTrail.Renderable.Enabled', true) openspace.removeVirtualProperty("*Trail.Renderable.Enabled") end) diff --git a/data/assets/scene/digitaluniverse/backgroundradiation.asset b/data/assets/scene/digitaluniverse/backgroundradiation.asset index 5ca7b769ef..94b7b02e65 100644 --- a/data/assets/scene/digitaluniverse/backgroundradiation.asset +++ b/data/assets/scene/digitaluniverse/backgroundradiation.asset @@ -18,6 +18,12 @@ local speck = asset.syncedResource({ local wmap = { Identifier = "WMAP", + Transform = { + Rotation = { + Type = "StaticRotation", + Rotation = {0, 0, 3.14159265359} + } + }, Renderable = { Type = "RenderableSphere", Enabled = false, @@ -25,9 +31,10 @@ local wmap = { Segments = 80, Opacity = 0.5, Texture = textures .. "/wmap_ilc_7yr_v4_200uK_RGB_sos.png", - Orientation = "Inside/Outside", - FadeInThreshould = 8E26 - + Orientation = "Both", + MirrorTexture = true, + UseAdditiveBlending = true, + FadeInThreshold = 0.4 }, GUI = { Name = "Wilkinson Microwave Anisotropy Probe (WMAP)", @@ -37,6 +44,12 @@ local wmap = { local cbe = { Identifier = "CBE", + Transform = { + Rotation = { + Type = "StaticRotation", + Rotation = {0, 0, 3.14159265359} + } + }, Renderable = { Type = "RenderableSphere", Enabled = false, @@ -44,8 +57,10 @@ local cbe = { Segments = 80, Opacity = 0.5, Texture = textures .. "/COBErect.png", - Orientation = "Inside/Outside", - FadeInThreshould = 8E26 + Orientation = "Both", + MirrorTexture = true, + UseAdditiveBlending = true, + FadeInThreshold = 0.4 }, GUI = { Name = "Cosmic Background Explorer", @@ -55,15 +70,23 @@ local cbe = { local planck = { Identifier = "Planck", + Transform = { + Rotation = { + Type = "StaticRotation", + Rotation = {0, 0, 3.14159265359} + } + }, Renderable = { Type = "RenderableSphere", - Enabled = false, + Enabled = true, Size = 3975.41417036064E23, Segments = 80, Opacity = 0.3, Texture = textures .. "/cmb4k.jpg", - Orientation = "Inside/Outside", - FadeInThreshould = 8E26 + Orientation = "Both", + MirrorTexture = true, + UseAdditiveBlending = true, + FadeInThreshold = 0.4 }, GUI = { Path = "/Universe/Cosmic Microwave Background" diff --git a/data/assets/scene/digitaluniverse/milkyway.asset b/data/assets/scene/digitaluniverse/milkyway.asset index 82d0eb81da..5b6fc20343 100644 --- a/data/assets/scene/digitaluniverse/milkyway.asset +++ b/data/assets/scene/digitaluniverse/milkyway.asset @@ -25,14 +25,22 @@ local planeSpeck = asset.syncedResource({ local sphere = { Identifier = "MilkyWay", + Transform = { + Rotation = { + Type = "StaticRotation", + Rotation = {0, 0, 3.14159265359} + } + }, Renderable = { Type = "RenderableSphere", - Size = 9.2E20, + Size = 9.2E21, Segments = 40, Opacity = 0.4, Texture = sphereTextures .. "/DarkUniverse_mellinger_4k.jpg", - Orientation = "Inside/Outside", - FadeOutThreshould = 0.25 + Orientation = "Inside", + UseAdditiveBlending = true, + MirrorTexture = true, + FadeOutThreshold = 0.025 }, GUI = { Name = "Milky Way", @@ -54,8 +62,7 @@ local plane = { Luminosity = "size", ScaleLuminosity = 1.0, -- Fade in value in the same unit as "Unit" - FadeInThreshould = 119441, - FadeInDistances = { 1400.0, 119441.0 }, + FadeInDistances = { 1000.0, 100000.0 }, PlaneMinSize = 5.0, Unit = "pc" }, diff --git a/data/assets/scene/digitaluniverse/quasars.asset b/data/assets/scene/digitaluniverse/quasars.asset index 63020c882c..546fac9bd7 100644 --- a/data/assets/scene/digitaluniverse/quasars.asset +++ b/data/assets/scene/digitaluniverse/quasars.asset @@ -20,7 +20,7 @@ local object = { Identifier = "Quasars", Renderable = { Type = "RenderableBillboardsCloud", - Enabled = false, + Enabled = true, Color = { 1.0, 0.4, 0.2 }, Transparency = 1.0, File = speck .. "/quasars.speck", diff --git a/data/assets/scene/digitaluniverse/sdss.asset b/data/assets/scene/digitaluniverse/sdss.asset index 03829710cc..bdd2ae2d49 100644 --- a/data/assets/scene/digitaluniverse/sdss.asset +++ b/data/assets/scene/digitaluniverse/sdss.asset @@ -20,7 +20,7 @@ local object = { Identifier = "SloanDigitalSkySurvey", Renderable = { Type = "RenderableBillboardsCloud", - Enabled = false, + Enabled = true, Color = { 0.8, 0.8, 1.0 }, Transparency = 1.0, ScaleFactor = 507.88, diff --git a/data/assets/scene/digitaluniverse/tully.asset b/data/assets/scene/digitaluniverse/tully.asset index 5c3ee2ca20..a1d48b7c27 100644 --- a/data/assets/scene/digitaluniverse/tully.asset +++ b/data/assets/scene/digitaluniverse/tully.asset @@ -20,7 +20,7 @@ local tullyPoints = { Identifier = "TullyGalaxies", Renderable = { Type = "RenderableBillboardsCloud", - Enabled = false, + Enabled = true, Color = { 1.0, 0.4, 0.2 }, Transparency = 0.99, ScaleFactor = 502.77, @@ -45,8 +45,8 @@ local tullyPoints = { -- Max size in pixels BillboardMaxSize = 50.0, BillboardMinSize = 0.0, - CorrectionSizeEndDistance = 20.55, - CorrectionSizeFactor = 10.45, + CorrectionSizeEndDistance = 22.0, + CorrectionSizeFactor = 10.45 }, GUI = { Name = "Tully Galaxies", diff --git a/data/assets/scene/milkyway/milkyway/eso.asset b/data/assets/scene/milkyway/milkyway/eso.asset index dcfd30c43b..34cc9d79e9 100644 --- a/data/assets/scene/milkyway/milkyway/eso.asset +++ b/data/assets/scene/milkyway/milkyway/eso.asset @@ -11,14 +11,22 @@ local textures = asset.syncedResource({ local object = { Identifier = "MilkyWay-ESO", + Transform = { + Rotation = { + Type = "StaticRotation", + Rotation = {0, 0, 3.14159265359} + } + }, Renderable = { Type = "RenderableSphere", Size = 9.2E20, Segments = 40, Opacity = 0.4, Texture = textures .. "/eso0932a_blend.png", - Orientation = "Inside/Outside", - FadeOutThreshould = 0.01 + UseAdditiveBlending = true, + Orientation = "Inside", + MirrorTexture = true, + FadeOutThreshold = 0.01 }, GUI = { Name = "Milky Way (ESO)", diff --git a/data/assets/scene/solarsystem/dwarf_planets/pluto/charon_trail.asset b/data/assets/scene/solarsystem/dwarf_planets/pluto/charon_trail.asset index afc1190919..2d8e6dd1c0 100644 --- a/data/assets/scene/solarsystem/dwarf_planets/pluto/charon_trail.asset +++ b/data/assets/scene/solarsystem/dwarf_planets/pluto/charon_trail.asset @@ -18,7 +18,7 @@ local CharonTrailBarycentric = { Resolution = 1000 }, GUI = { - Name = "Pluto Barycenteric Trail", + Name = "Charon Barycenteric Trail", Path = "/Solar System/Dwarf Planets/Pluto" } } diff --git a/data/assets/scene/solarsystem/dwarf_planets/pluto/nix.asset b/data/assets/scene/solarsystem/dwarf_planets/pluto/nix.asset index 3ab7b01f12..225ba93e2d 100644 --- a/data/assets/scene/solarsystem/dwarf_planets/pluto/nix.asset +++ b/data/assets/scene/solarsystem/dwarf_planets/pluto/nix.asset @@ -41,7 +41,7 @@ local NixTrail = { Resolution = 1000 }, GUI = { - Name = "Hydra Trail", + Name = "Nix Trail", Path = "/Solar System/Dwarf Planets/Pluto" } } diff --git a/data/assets/scene/solarsystem/dwarf_planets/pluto/styx.asset b/data/assets/scene/solarsystem/dwarf_planets/pluto/styx.asset index 40c5b52b2c..b90db619e5 100644 --- a/data/assets/scene/solarsystem/dwarf_planets/pluto/styx.asset +++ b/data/assets/scene/solarsystem/dwarf_planets/pluto/styx.asset @@ -41,7 +41,7 @@ local StyxTrail = { Resolution = 1000 }, GUI = { - Name = "Hydra Trail", + Name = "Styx Trail", Path = "/Solar System/Dwarf Planets/Pluto" } } diff --git a/data/assets/scene/solarsystem/missions/newhorizons/charon.asset b/data/assets/scene/solarsystem/missions/newhorizons/charon.asset index b99860f62d..3929571670 100644 --- a/data/assets/scene/solarsystem/missions/newhorizons/charon.asset +++ b/data/assets/scene/solarsystem/missions/newhorizons/charon.asset @@ -13,9 +13,9 @@ local textures = asset.syncedResource({ local charonRadius = 6.035E5 -local Charon = { - Identifier = "Charon", - Parent = transforms.PlutoBarycenter.Identifier, +local CharonProjection = { + Identifier = "CharonProjection", + Parent = transforms.PlutoBarycenterAccurate.Identifier, Transform = { Translation = { Type = "SpiceTranslation", @@ -43,6 +43,7 @@ local Charon = { textures .. "/NH_Charon_DTM.png", textures .. "/NH_Charon_DTM_8192.png" }, + MeridianShift = true, Projection = { Observer = "NEW HORIZONS", Target = "CHARON", @@ -66,13 +67,14 @@ local Charon = { } }, GUI = { - Path = "/Solar System/Dwarf Planets/Pluto" + Path = "/Solar System/Dwarf Planets/Pluto", + Name = "Charon Projection" } } local CharonText = { Identifier = "CharonText", - Parent = Charon.Identifier, + Parent = CharonProjection.Identifier, Transform = { Translation = { Type = "StaticTranslation", @@ -95,7 +97,7 @@ local CharonText = { local CharonShadow = { Identifier = "CharonShadow", - Parent = Charon.Identifier, + Parent = CharonProjection .Identifier, Renderable = { Type = "RenderableShadowCylinder", TerminatorType = "PENUMBRAL", @@ -111,31 +113,8 @@ local CharonShadow = { } } -local CharonTrail = { - Identifier = "CharonTrail", - Parent = transforms.PlutoBarycenter.Identifier, - Renderable = { - Type = "RenderableTrailOrbit", - Translation = { - Type = "SpiceTranslation", - Target = "CHARON", - Observer = "PLUTO BARYCENTER" - }, - Color = { 0.00, 0.62, 1.00 }, - Period = 6.38725, - Resolution = 1000 - }, - GUI = { - Name = "Charon Trail", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - - - assetHelper.registerSceneGraphNodesAndExport(asset, { - Charon, + CharonProjection, CharonText, - CharonShadow, - CharonTrail + CharonShadow }) diff --git a/data/assets/scene/solarsystem/missions/newhorizons/fov.asset b/data/assets/scene/solarsystem/missions/newhorizons/fov.asset index 182639b9ad..45c7f7ba7e 100644 --- a/data/assets/scene/solarsystem/missions/newhorizons/fov.asset +++ b/data/assets/scene/solarsystem/missions/newhorizons/fov.asset @@ -355,11 +355,7 @@ local Rex = { Transform = { Rotation = { Type = "StaticRotation", - Rotation = { - 0.0, 1.0, 0.0, - 0.0, 0.0, 1.0, - 1.0, 0.0, 0.0 - } + Rotation = {-3.141502/2, 0, -3.141502/2} }, Translation = { Type = "StaticTranslation", diff --git a/data/assets/scene/solarsystem/missions/newhorizons/hydra.asset b/data/assets/scene/solarsystem/missions/newhorizons/hydra.asset deleted file mode 100644 index 153c653dd4..0000000000 --- a/data/assets/scene/solarsystem/missions/newhorizons/hydra.asset +++ /dev/null @@ -1,91 +0,0 @@ -local assetHelper = asset.require('util/asset_helper') -local transforms = asset.require('./transforms') -local kernels = asset.require('./kernels').Kernels - - - -local textures = asset.syncedResource({ - Name = "Hydra Textures", - Type = "HttpSynchronization", - Identifier = "hydra_textures", - Version = 1 -}) - -local Hydra = { - Identifier = "Hydra", - Parent = transforms.PlutoBarycenter.Identifier, - Transform = { - Translation = { - Type = "SpiceTranslation", - Target = "HYDRA", - Observer = "PLUTO BARYCENTER", - Kernels = kernels .. "/NavSE_plu047_od122.bsp" - } - }, - Renderable = { - Type = "RenderablePlanet", - Frame = "IAU_PLUTO", - Body = "HYDRA", - Radius = hydra_radius, - Geometry = { - Type = "SimpleSphere", - Radius = 0.53E5, - Segments = 100 - }, - ColorTexture = textures .. "/gray.jpg" - }, - GUI = { - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - -local HydraText = { - Identifier = "HydraText", - Parent = Hydra.Identifier, - Transform = { - Translation = { - Type = "StaticTranslation", - Position = { 1000000, 0, 1000000 }, - }, - }, - Renderable = { - Type = "RenderablePlaneImageLocal", - Size = 10.0^6.3, - Origin = "Center", - Billboard = true, - Texture = textures .. "/Hydra-Text.png", - BlendMode = "Additive" - }, - GUI = { - Name = "Hydra Text", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - -local HydraTrail = { - Identifier = "HydraTrail", - Parent = transforms.PlutoBarycenter.Identifier, - Renderable = { - Type = "RenderableTrailOrbit", - Translation = { - Type = "SpiceTranslation", - Target = "HYDRA", - Observer = "PLUTO BARYCENTER", - }, - Color = { 0.00, 0.62, 1.00 }, - Period = 38.20177, - Resolution = 1000 - }, - GUI = { - Name = "Hydra Trail", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - - - -assetHelper.registerSceneGraphNodesAndExport(asset, { - Hydra, - HydraText, - HydraTrail -}) diff --git a/data/assets/scene/solarsystem/missions/newhorizons/kerberos.asset b/data/assets/scene/solarsystem/missions/newhorizons/kerberos.asset deleted file mode 100644 index 87c156dd2c..0000000000 --- a/data/assets/scene/solarsystem/missions/newhorizons/kerberos.asset +++ /dev/null @@ -1,94 +0,0 @@ -local assetHelper = asset.require('util/asset_helper') -local transforms = asset.require('./transforms') -local kernels = asset.require('./kernels') - - - -local textures = asset.syncedResource({ - Name = "Kerberos Textures", - Type = "HttpSynchronization", - Identifier = "kerberos_textures", - Version = 1 -}) - -local Kerberos = { - Identifier = "Kerberos", - Parent = transforms.PlutoBarycenter.Identifier, - Transform = { - Translation = { - Type = "SpiceTranslation", - Target = "KERBEROS", - Observer = "PLUTO BARYCENTER", - Kernels = kernels.Kernels .. "/NavSE_plu047_od122.bsp" - }, - Rotation = { - Type = "SpiceRotation", - SourceFrame = "IAU_KERBEROS", - DestinationFrame = "GALACTIC" - } - }, - Renderable = { - Type = "RenderablePlanet", - Frame = "IAU_PLUTO", - Body = "KERBEROS", - Geometry = { - Type = "SimpleSphere", - Radius = 0.1E5, - Segments = 100 - }, - ColorTexture = textures .. "/gray.jpg" - }, - GUI = { - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - -local KerberosText = { - Identifier = "KerberosText", - Parent = Kerberos.Identifier, - Transform = { - Translation = { - Type = "StaticTranslation", - Position = { 1000000.0, 0, 1000000.0 } - }, - }, - Renderable = { - Type = "RenderablePlaneImageLocal", - Size = 10^6.3, - Origin = "Center", - Billboard = true, - Texture = textures .. "/Kerberos-Text.png" - }, - GUI = { - Name = "Kerberos Text", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - -local KerberosTrail = { - Identifier = "KerberosTrail", - Parent = transforms.PlutoBarycenter.Identifier, - Renderable = { - Type = "RenderableTrailOrbit", - Translation = { - Type = "SpiceTranslation", - Target = "KERBEROS", - Observer = "PLUTO BARYCENTER" - }, - Color = { 0.00, 0.62, 1.00 }, - Period = 32.16756, - Resolution = 1000 - }, - GUI = { - Name = "Kerberos Trail", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - - - -assetHelper.registerSceneGraphNodesAndExport(asset, { - Kerberos, - KerberosText, - KerberosTrail -}) diff --git a/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.asset b/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.asset index 82048c9b63..cf35bc01c1 100644 --- a/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.asset +++ b/data/assets/scene/solarsystem/missions/newhorizons/newhorizons.asset @@ -5,10 +5,8 @@ asset.require('./trail') asset.require('./pluto') asset.require('./charon') -asset.require('./hydra') -asset.require('./nix') -asset.require('./styx') +asset.require('./othermoons') local mission = asset.localResource("newhorizons.mission") local missionName diff --git a/data/assets/scene/solarsystem/missions/newhorizons/nix.asset b/data/assets/scene/solarsystem/missions/newhorizons/nix.asset deleted file mode 100644 index 86c04c376d..0000000000 --- a/data/assets/scene/solarsystem/missions/newhorizons/nix.asset +++ /dev/null @@ -1,83 +0,0 @@ -local assetHelper = asset.require('util/asset_helper') -local transforms = asset.require('./transforms') -local kernels = asset.require('./kernels') - - - -local textures = asset.syncedResource({ - Name = "Nix Textures", - Type = "HttpSynchronization", - Identifier = "nix_textures", - Version = 1 -}) - -local Nix = { - Identifier = "Nix", - Parent = transforms.PlutoBarycenter.Identifier, - Transform = { - Translation = { - Type = "SpiceTranslation", - Target = "NIX", - Observer = "PLUTO BARYCENTER", - Kernels = kernels.Kernels .. "/NavSE_plu047_od122.bsp" - } - }, - Renderable = { - Type = "RenderablePlanet", - Body = "NIX", - Geometry = { - Type = "SimpleSphere", - Radius = 0.45E5, - Segments = 100 - }, - ColorTexture = textures .. "/gray.jpg", - }, - GUI = { - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - -local NixText = { - Identifier = "NixText", - Parent = Nix.Identifier, - Renderable = { - Type = "RenderablePlaneImageLocal", - Size = 10^6.3, - Origin = "Center", - Billboard = true, - Texture = textures .. "/Nix-Text.png", - BlendMode = "Additive" - }, - GUI = { - Name = "Nix Text", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - -local NixTrail = { - Identifier = "NixTrail", - Parent = transforms.PlutoBarycenter.Identifier, - Renderable = { - Type = "RenderableTrailOrbit", - Translation = { - Type = "SpiceTranslation", - Target = "NIX", - Observer = "PLUTO BARYCENTER" - }, - Color = { 0.0, 0.62, 1.0 }, - Period = 24.85463, - Resolution = 1000 - }, - GUI = { - Name = "Nix Trail", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - - - -assetHelper.registerSceneGraphNodesAndExport(asset, { - Nix, - NixText, - NixTrail -}) diff --git a/data/assets/scene/solarsystem/missions/newhorizons/othermoons.asset b/data/assets/scene/solarsystem/missions/newhorizons/othermoons.asset new file mode 100644 index 0000000000..010e8bc9cf --- /dev/null +++ b/data/assets/scene/solarsystem/missions/newhorizons/othermoons.asset @@ -0,0 +1,126 @@ +local Hydra = asset.require('scene/solarsystem/dwarf_planets/pluto/hydra') +local Kerberos = asset.require('scene/solarsystem/dwarf_planets/pluto/kerberos') +local Nix = asset.require('scene/solarsystem/dwarf_planets/pluto/nix') +local Styx = asset.require('scene/solarsystem/dwarf_planets/pluto/styx') +local assetHelper = asset.require('util/asset_helper') + +local hydraTextures = asset.syncedResource({ + Name = "Hydra Textures", + Type = "HttpSynchronization", + Identifier = "hydra_textures", + Version = 1 +}) + +local HydraText = { + Identifier = "HydraText", + Parent = Hydra.Hydra.Identifier, + Transform = { + Translation = { + Type = "StaticTranslation", + Position = { 1000000, 0, 1000000 }, + }, + }, + Renderable = { + Type = "RenderablePlaneImageLocal", + Size = 10.0^6.3, + Origin = "Center", + Billboard = true, + Texture = hydraTextures .. "/Hydra-Text.png", + BlendMode = "Additive" + }, + GUI = { + Name = "Hydra Text", + Path = "/Solar System/Dwarf Planets/Pluto" + } +} + +local kerberosTextures = asset.syncedResource({ + Name = "Kerberos Textures", + Type = "HttpSynchronization", + Identifier = "kerberos_textures", + Version = 1 +}) + +local KerberosText = { + Identifier = "KerberosText", + Parent = Kerberos.Kerberos.Identifier, + Transform = { + Translation = { + Type = "StaticTranslation", + Position = { 1000000.0, 0, 1000000.0 } + }, + }, + Renderable = { + Type = "RenderablePlaneImageLocal", + Size = 10^6.3, + Origin = "Center", + Billboard = true, + Texture = kerberosTextures .. "/Kerberos-Text.png", + BlendMode = "Additive" + }, + GUI = { + Name = "Kerberos Text", + Path = "/Solar System/Dwarf Planets/Pluto" + } +} + +local nixTextures = asset.syncedResource({ + Name = "Nix Textures", + Type = "HttpSynchronization", + Identifier = "nix_textures", + Version = 1 +}) + +local NixText = { + Identifier = "NixText", + Parent = Nix.Nix.Identifier, + Renderable = { + Type = "RenderablePlaneImageLocal", + Size = 10^6.3, + Origin = "Center", + Billboard = true, + Texture = nixTextures .. "/Nix-Text.png", + BlendMode = "Additive" + }, + GUI = { + Name = "Nix Text", + Path = "/Solar System/Dwarf Planets/Pluto" + } +} + +local styxTextures = asset.syncedResource({ + Name = "Styx Textures", + Type = "HttpSynchronization", + Identifier = "styx_textures", + Version = 1 +}) + +local StyxText = { + Identifier = "StyxText", + Parent = Styx.Styx.Identifier, + Transform = { + Translation = { + Type = "StaticTranslation", + Position = { 1000000.0, 0, 1000000.0 } + }, + }, + Renderable = { + Type = "RenderablePlaneImageLocal", + Size = 10^6.3, + Origin = "Center", + Billboard = true, + Texture = styxTextures .. "/Styx-Text.png", + BlendMode = "Additive" + }, + GUI = { + Name = "Styx Text", + Path = "/Solar System/Dwarf Planets/Pluto" + } +} + +assetHelper.registerSceneGraphNodesAndExport(asset, { + HydraText, + KerberosText, + NixText, + StyxText +}) diff --git a/data/assets/scene/solarsystem/missions/newhorizons/pluto.asset b/data/assets/scene/solarsystem/missions/newhorizons/pluto.asset index 48dc6f7913..ec93de4ff5 100644 --- a/data/assets/scene/solarsystem/missions/newhorizons/pluto.asset +++ b/data/assets/scene/solarsystem/missions/newhorizons/pluto.asset @@ -2,8 +2,6 @@ local assetHelper = asset.require('util/asset_helper') local transforms = asset.require('./transforms') local sunTransforms = asset.require('scene/solarsystem/sun/transforms') - - local assets = asset.syncedResource({ Name = "Pluto Assets", Type = "HttpSynchronization", @@ -34,9 +32,9 @@ local images = asset.syncedResource({ local plutoRadius = 1.173E6 -local Pluto = { - Identifier = "Pluto", - Parent = transforms.PlutoBarycenter.Identifier, +local PlutoProjection = { + Identifier = "PlutoProjection", + Parent = transforms.PlutoBarycenterAccurate.Identifier, Transform = { Translation = { Type = "SpiceTranslation", @@ -73,7 +71,7 @@ local Pluto = { textures .. "/NH_Pluto_DTM_16384.png", textures .. "/NH_Pluto_DTM_8192.png" }, - MeridianShift = true, + MeridianShift = false, Projection = { Sequence = images, EventFile = assets .. "/core_v9h_obs_getmets_v8_time_fix_nofrcd_mld.txt", @@ -183,13 +181,14 @@ local Pluto = { } }, GUI = { + Name = "Pluto Projection", Path = "/Solar System/Dwarf Planets/Pluto" } } local PlutoBarycenterLabel = { Identifier = "PlutoBarycenterLabel", - Parent = transforms.PlutoBarycenter.Identifier, + Parent = transforms.PlutoBarycenterAccurate.Identifier, Renderable = { Type = "RenderablePlaneImageLocal", Billboard = true, @@ -205,7 +204,7 @@ local PlutoBarycenterLabel = { local PlutoText = { Identifier = "PlutoText", - Parent = Pluto.Identifier, + Parent = PlutoProjection.Identifier, Transform = { Translation = { Type = "StaticTranslation", @@ -228,7 +227,7 @@ local PlutoText = { local PlutoShadow = { Identifier = "PlutoShadow", - Parent = Pluto.Identifier, + Parent = PlutoProjection.Identifier, Renderable = { Type = "RenderableShadowCylinder", TerminatorType = "PENUMBRAL", @@ -244,56 +243,9 @@ local PlutoShadow = { } } -local PlutoTrailBarycentric = { - Identifier = "PlutoBarycentricTrail", - Parent = transforms.PlutoBarycenter.Identifier, - Renderable = { - Type = "RenderableTrailOrbit", - Translation = { - Type = "SpiceTranslation", - Target = "PLUTO", - Observer = "PLUTO BARYCENTER" - }, - Color = { 0.00, 0.62, 1.00 }, - Period = 6.38723, - Resolution = 1000 - }, - GUI = { - Name = "Pluto Barycenteric Trail", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - -local PlutoTrail = { - Identifier = "PlutoTrail", - Parent = sunTransforms.SolarSystemBarycenter.Identifier, - Renderable = { - Type = "RenderableTrailOrbit", - Enabled = false, - Translation = { - Type = "SpiceTranslation", - Target = "PLUTO BARYCENTER", - Observer = "SUN" - }, - Color = { 0.3, 0.7, 0.3 }, - -- Not the actual Period, but the SPICE kernels we have only - -- go back to 1850, about 150 yeays ago - Period = 160 * 365.242, - Resolution = 1000 - }, - GUI = { - Name = "Pluto Trail", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - - - assetHelper.registerSceneGraphNodesAndExport(asset, { - Pluto, + PlutoProjection, PlutoBarycenterLabel, PlutoText, - PlutoShadow, - PlutoTrailBarycentric, - PlutoTrail + PlutoShadow }) diff --git a/data/assets/scene/solarsystem/missions/newhorizons/styx.asset b/data/assets/scene/solarsystem/missions/newhorizons/styx.asset deleted file mode 100644 index 85459c5c66..0000000000 --- a/data/assets/scene/solarsystem/missions/newhorizons/styx.asset +++ /dev/null @@ -1,90 +0,0 @@ -local assetHelper = asset.require('util/asset_helper') -local transforms = asset.require('./transforms') -local kernels = asset.require('./kernels') - - - -local textures = asset.syncedResource({ - Name = "Styx Textures", - Type = "HttpSynchronization", - Identifier = "styx_textures", - Version = 1 -}) - -local Styx = { - Identifier = "Styx", - Parent = transforms.PlutoBarycenter.Identifier, - Transform = { - Translation = { - Type = "SpiceTranslation", - Target = "STYX", - Observer = "PLUTO BARYCENTER", - Kernels = kernels.Kernels .. "/NavSE_plu047_od122.bsp" - } - }, - Renderable = { - Type = "RenderablePlanet", - Frame = "IAU_PLUTO", - Body = "STYX", - Geometry = { - Type = "SimpleSphere", - Radius = 0.75E4, - Segments = 100 - }, - ColorTexture = textures .. "/gray.jpg" - }, - GUI = { - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - -local StyxText = { - Identifier = "StyxText", - Parent = Styx.Identifier, - Transform = { - Translation = { - Type = "StaticTranslation", - Position = { 1000000.0, 0, 1000000.0 } - }, - }, - Renderable = { - Type = "RenderablePlaneImageLocal", - Size = 10^6.3, - Origin = "Center", - Billboard = true, - Texture = textures .. "/Styx-Text.png", - BlendMode = "Additive" - }, - GUI = { - Name = "Styx Text", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - -local StyxTrail = { - Identifier = "StyxTrail", - Parent = transforms.PlutoBarycenter.Identifier, - Renderable = { - Type = "RenderableTrailOrbit", - Translation = { - Type = "SpiceTranslation", - Target = "STYX", - Observer = "PLUTO BARYCENTER" - }, - Color = { 0.00, 0.62, 1.00 }, - Period = 20.16155, - Resolution = 1000 - }, - GUI = { - Name = "Styx Trail", - Path = "/Solar System/Dwarf Planets/Pluto" - } -} - - - -assetHelper.registerSceneGraphNodesAndExport(asset, { - Styx, - StyxText, - StyxTrail -}) diff --git a/data/assets/scene/solarsystem/missions/newhorizons/trail.asset b/data/assets/scene/solarsystem/missions/newhorizons/trail.asset index a51e11f073..9ebb30c5d6 100644 --- a/data/assets/scene/solarsystem/missions/newhorizons/trail.asset +++ b/data/assets/scene/solarsystem/missions/newhorizons/trail.asset @@ -5,7 +5,7 @@ local transforms = asset.require('./transforms') local TrailAtPluto = { Identifier = "NewHorizonsTrailPluto", - Parent = transforms.PlutoBarycenter.Identifier, + Parent = transforms.PlutoBarycenterAccurate.Identifier, Renderable = { Type = "RenderableTrailTrajectory", Translation = { diff --git a/data/assets/scene/solarsystem/missions/newhorizons/transforms.asset b/data/assets/scene/solarsystem/missions/newhorizons/transforms.asset index 6efefa3590..2ce8b47f00 100644 --- a/data/assets/scene/solarsystem/missions/newhorizons/transforms.asset +++ b/data/assets/scene/solarsystem/missions/newhorizons/transforms.asset @@ -2,8 +2,8 @@ local assetHelper = asset.require('util/asset_helper') local sunTransforms = asset.require('scene/solarsystem/sun/transforms') local kernels = asset.require('./kernels') -local PlutoBarycenter = { - Identifier = "PlutoBarycenter", +local PlutoBarycenterAccurate = { + Identifier = "PlutoBarycenterAccurate", Parent = sunTransforms.SolarSystemBarycenter.Identifier, TimeFrame = { Type = "TimeFrameInterval", @@ -19,14 +19,14 @@ local PlutoBarycenter = { }, }, GUI = { - Name = "Pluto Barycenter", + Name = "Pluto Barycenter Accurate", Path = "/Solar System/Dwarf Planets/Pluto" } } local NewHorizonsPosition = { Identifier = "NewHorizonsPosition", - Parent = PlutoBarycenter.Identifier, + Parent = PlutoBarycenterAccurate.Identifier, Transform = { Translation = { Type = "SpiceTranslation", @@ -49,6 +49,6 @@ local NewHorizonsPosition = { assetHelper.registerSceneGraphNodesAndExport(asset, { - PlutoBarycenter, + PlutoBarycenterAccurate, NewHorizonsPosition }) diff --git a/data/assets/scene/solarsystem/sun/sun.asset b/data/assets/scene/solarsystem/sun/sun.asset index 3acbccb04a..cc887dc4d2 100644 --- a/data/assets/scene/solarsystem/sun/sun.asset +++ b/data/assets/scene/solarsystem/sun/sun.asset @@ -3,22 +3,23 @@ local transforms = asset.require("./transforms") local textures = asset.require('./sun_textures').TexturesPath asset.require("spice/base") - - local Sun = { Identifier = "Sun", Parent = transforms.SunIAU.Identifier, Renderable = { - Type = "RenderablePlanet", + Type = "RenderableGlobe", Enabled = false, - Frame = "IAU_SUN", - Body = "SUN", - Geometry = { - Type = "SimpleSphere", - Radius = 6.957E8, - Segments = 100 + Radii = { 6.957E8, 6.957E8, 6.957E8 }, + SegmentsPerPatch = 64, + Layers = { + ColorLayers = { + { + Identifier = "Texture", + FilePath = textures .. "/sun.jpg", + Enabled = true + } + } }, - ColorTexture = textures .. "/sun.jpg", PerformShading = false }, GUI = { @@ -26,6 +27,4 @@ local Sun = { } } - - assetHelper.registerSceneGraphNodesAndExport(asset, { Sun }) diff --git a/include/openspace/rendering/renderable.h b/include/openspace/rendering/renderable.h index 33e0282fce..390c3babb2 100644 --- a/include/openspace/rendering/renderable.h +++ b/include/openspace/rendering/renderable.h @@ -46,7 +46,6 @@ struct SurfacePositionHandle; namespace documentation { struct Documentation; } class Camera; -class PowerScaledCoordinate; class Renderable : public properties::PropertyOwner { public: @@ -60,7 +59,6 @@ public: static std::unique_ptr createFromDictionary( const ghoul::Dictionary& dictionary); - // constructors & destructor Renderable(const ghoul::Dictionary& dictionary); virtual ~Renderable() = default; @@ -88,9 +86,6 @@ public: void onEnabledChange(std::function callback); - static void setPscUniforms(ghoul::opengl::ProgramObject& program, - const Camera& camera, const PowerScaledCoordinate& position); - static documentation::Documentation Documentation(); protected: diff --git a/include/openspace/util/powerscaledcoordinate.h b/include/openspace/util/powerscaledcoordinate.h index 896097f52b..64f258940c 100644 --- a/include/openspace/util/powerscaledcoordinate.h +++ b/include/openspace/util/powerscaledcoordinate.h @@ -62,7 +62,7 @@ public: glm::dvec3 dvec3() const; // length of the vector as a pss - PowerScaledScalar length() const; + float length() const; glm::vec3 direction() const; // operator overloading @@ -80,8 +80,6 @@ public: // scalar operators PowerScaledCoordinate operator*(const double& rhs) const; PowerScaledCoordinate operator*(const float& rhs) const; - PowerScaledCoordinate& operator*=(const PowerScaledScalar& rhs); - PowerScaledCoordinate operator*(const PowerScaledScalar& rhs) const; PowerScaledCoordinate operator*(const glm::mat4& matrix) const; diff --git a/include/openspace/util/powerscaledscalar.h b/include/openspace/util/powerscaledscalar.h deleted file mode 100644 index 362e8dddc8..0000000000 --- a/include/openspace/util/powerscaledscalar.h +++ /dev/null @@ -1,88 +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. * - ****************************************************************************************/ - -#ifndef __OPENSPACE_CORE___POWERSCALEDSCALAR___H__ -#define __OPENSPACE_CORE___POWERSCALEDSCALAR___H__ - -#include - -namespace openspace { - -class PowerScaledScalar { -public: - PowerScaledScalar() = default; - PowerScaledScalar(const glm::vec2 &v); - PowerScaledScalar(float f1, float f2); - static PowerScaledScalar CreatePSS(double d1); - - const glm::vec2& vec2() const; - float lengthf() const; - double lengthd() const; - - - // operator overloading - PowerScaledScalar& operator=(const PowerScaledScalar& rhs); - PowerScaledScalar& operator+=(const PowerScaledScalar& rhs); - const PowerScaledScalar& operator+(const PowerScaledScalar& rhs) const; - PowerScaledScalar& operator-=(const PowerScaledScalar& rhs); - const PowerScaledScalar& operator-(const PowerScaledScalar& rhs) const; - PowerScaledScalar& operator*=(const PowerScaledScalar& rhs); - const PowerScaledScalar& operator*(const PowerScaledScalar& rhs) const; - PowerScaledScalar& operator*=(float rhs); - const PowerScaledScalar& operator*(float rhs) const; - float& operator[](unsigned int idx); - float operator[](unsigned int idx) const; - - // comparison - bool operator==(const PowerScaledScalar& other) const; - bool operator<(const PowerScaledScalar& other) const; - bool operator>(const PowerScaledScalar& other) const; - bool operator<=(const PowerScaledScalar& other) const; - bool operator>=(const PowerScaledScalar& other) const; - - bool operator==(double other) const; - bool operator<(double other) const; - bool operator>(double other) const; - bool operator<=(double other) const; - bool operator>=(double other) const; - - // glm integration - PowerScaledScalar& operator=(const glm::vec2& rhs); - PowerScaledScalar& operator=(float rhs); - - friend std::ostream& operator<<(std::ostream& os, const PowerScaledScalar& rhs); - - // allow the power scaled coordinates to access private members - friend class PowerScaledCoordinate; - -private: - // float vector used when returning float values - glm::vec2 _data = glm::vec2(0.f); -}; - -typedef PowerScaledScalar pss; - -} // namespace openspace - -#endif // __OPENSPACE_CORE___POWERSCALEDSCALAR___H__ diff --git a/include/openspace/util/powerscaledsphere.h b/include/openspace/util/powerscaledsphere.h index 44488c8c64..8be00b6f0b 100644 --- a/include/openspace/util/powerscaledsphere.h +++ b/include/openspace/util/powerscaledsphere.h @@ -30,12 +30,11 @@ namespace openspace { -class PowerScaledScalar; class PowerScaledSphere; class PowerScaledSphere { public: - PowerScaledSphere(const PowerScaledScalar& radius, int segments = 8); + PowerScaledSphere(float radius, int segments = 8); PowerScaledSphere(glm::vec3 radius, int segments); PowerScaledSphere(const PowerScaledSphere& cpy); ~PowerScaledSphere(); diff --git a/include/openspace/util/syncbuffer.h b/include/openspace/util/syncbuffer.h index bba450e870..8d8f5bb7e7 100644 --- a/include/openspace/util/syncbuffer.h +++ b/include/openspace/util/syncbuffer.h @@ -26,6 +26,7 @@ #define __OPENSPACE_CORE___SYNCBUFFER___H__ #include +#include #include namespace openspace { diff --git a/include/openspace/util/updatestructures.h b/include/openspace/util/updatestructures.h index 3f19c6959f..f6ecef64a4 100644 --- a/include/openspace/util/updatestructures.h +++ b/include/openspace/util/updatestructures.h @@ -51,9 +51,6 @@ struct UpdateData { struct RenderData { const Camera& camera; - // psc position to be removed in favor of the double precision position defined in - // the translation in transform. - psc position; const Time time; bool doPerformanceMeasurement; int renderBinMask; diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp index 5eaef72764..12252f2bc8 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp @@ -364,7 +364,8 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, // First we determine if the caster is shadowing the current planet // (all calculations in World Coordinates): - glm::dvec3 planetCasterVec = casterPos - renderData.position.dvec3(); + glm::dvec3 planetCasterVec = + casterPos - renderData.modelTransform.translation; glm::dvec3 sourceCasterVec = casterPos - sourcePos; double sc_length = glm::length(sourceCasterVec); glm::dvec3 planetCaster_proj = ( @@ -378,7 +379,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, double casterDistSun = glm::length(casterPos - sunPosWorld); double planetDistSun = glm::length( - renderData.position.dvec3() - sunPosWorld + renderData.modelTransform.translation - sunPosWorld ); ShadowRenderingStruct shadowData; diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index 5077999c20..749fdf6725 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -43,13 +42,15 @@ namespace { constexpr const char* ProgramName = "Sphere"; - constexpr const std::array UniformNames = { - "opacity", "ViewProjection", "ModelTransform", "texture1" + constexpr const std::array UniformNames = { + "opacity", "modelViewProjection", "modelViewRotation", "colorTexture", + "mirrorTexture" }; - enum Orientation { - Outside = 1, - Inside = 2 + enum class Orientation : int { + Outside = 0, + Inside, + Both }; constexpr openspace::properties::Property::PropertyInfo TextureInfo = { @@ -60,6 +61,12 @@ namespace { "projection." }; + constexpr openspace::properties::Property::PropertyInfo MirrorTextureInfo = { + "MirrorTexture", + "Mirror Texture", + "Mirror the texture along the x-axis." + }; + constexpr openspace::properties::Property::PropertyInfo OrientationInfo = { "Orientation", "Orientation", @@ -67,6 +74,12 @@ namespace { "outside of the sphere, or both." }; + constexpr openspace::properties::Property::PropertyInfo UseAdditiveBlendingInfo = { + "UseAdditiveBlending", + "Use Additive Blending", + "Render the object using additive blending." + }; + constexpr openspace::properties::Property::PropertyInfo SegmentsInfo = { "Segments", "Number of Segments", @@ -79,22 +92,22 @@ namespace { "This value specifies the radius of the sphere in meters." }; - constexpr openspace::properties::Property::PropertyInfo FadeOutThreshouldInfo = { - "FadeOutThreshould", - "Fade-Out Threshould", + constexpr openspace::properties::Property::PropertyInfo FadeOutThresholdInfo = { + "FadeOutThreshold", + "Fade-Out Threshold", "This value determines percentage of the sphere is visible before starting " "fading-out it." }; - constexpr openspace::properties::Property::PropertyInfo FadeInThreshouldInfo = { - "FadeInThreshould", - "Fade-In Threshould", + constexpr openspace::properties::Property::PropertyInfo FadeInThresholdInfo = { + "FadeInThreshold", + "Fade-In Threshold", "Distance from center of MilkyWay from where the astronomical object starts to " "fade in." }; - constexpr openspace::properties::Property::PropertyInfo DisableFadeInOuInfo = { - "DisableFadeInOu", + constexpr openspace::properties::Property::PropertyInfo DisableFadeInOutInfo = { + "DisableFadeInOut", "Disable Fade-In/Fade-Out effects", "Enables/Disables the Fade-In/Out effects." }; @@ -128,27 +141,39 @@ documentation::Documentation RenderableSphere::Documentation() { }, { OrientationInfo.identifier, - new StringInListVerifier({ "Inside", "Outside", "Inside/Outside" }), + new StringInListVerifier({ "Inside", "Outside", "Both" }), Optional::Yes, OrientationInfo.description }, { - FadeOutThreshouldInfo.identifier, - new DoubleInRangeVerifier(0.0, 1.0), - Optional::Yes, - FadeOutThreshouldInfo.description - }, - { - FadeInThreshouldInfo.identifier, - new DoubleVerifier, - Optional::Yes, - FadeInThreshouldInfo.description - }, - { - DisableFadeInOuInfo.identifier, + UseAdditiveBlendingInfo.identifier, new BoolVerifier, Optional::Yes, - DisableFadeInOuInfo.description + UseAdditiveBlendingInfo.description + }, + { + MirrorTextureInfo.identifier, + new BoolVerifier, + Optional::Yes, + MirrorTextureInfo.description + }, + { + FadeOutThresholdInfo.identifier, + new DoubleInRangeVerifier(0.0, 1.0), + Optional::Yes, + FadeOutThresholdInfo.description + }, + { + FadeInThresholdInfo.identifier, + new DoubleVerifier, + Optional::Yes, + FadeInThresholdInfo.description + }, + { + DisableFadeInOutInfo.identifier, + new BoolVerifier, + Optional::Yes, + DisableFadeInOutInfo.description }, } }; @@ -161,7 +186,11 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary) , _orientation(OrientationInfo, properties::OptionProperty::DisplayType::Dropdown) , _size(SizeInfo, 1.f, 0.f, 1e35f) , _segments(SegmentsInfo, 8, 4, 1000) - , _disableFadeInDistance(DisableFadeInOuInfo, true) + , _useAdditiveBlending(UseAdditiveBlendingInfo, false) + , _mirrorTexture(MirrorTextureInfo, false) + , _disableFadeInDistance(DisableFadeInOutInfo, true) + , _fadeInThreshold(FadeInThresholdInfo, -1.f, 0.f, 1.f) + , _fadeOutThreshold(FadeOutThresholdInfo, -1.f, 0.f, 1.f) { documentation::testSpecificationAndThrow( Documentation(), @@ -177,28 +206,28 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary) _texturePath = absPath(dictionary.value(TextureInfo.identifier)); _orientation.addOptions({ - { Outside, "Outside" }, - { Inside, "Inside" }, - { Outside | Inside, "Inside/Outside" } + { static_cast(Orientation::Outside), "Outside" }, + { static_cast(Orientation::Inside), "Inside" }, + { static_cast(Orientation::Both), "Both" } }); if (dictionary.hasKey(OrientationInfo.identifier)) { const std::string& v = dictionary.value(OrientationInfo.identifier); if (v == "Inside") { - _orientation = Inside; + _orientation = static_cast(Orientation::Inside); } else if (v == "Outside") { - _orientation = Outside; + _orientation = static_cast(Orientation::Outside); } - else if (v == "Inside/Outside") { - _orientation = Outside | Inside; + else if (v == "Both") { + _orientation = static_cast(Orientation::Both); } else { throw ghoul::MissingCaseException(); } } else { - _orientation = Outside; + _orientation = static_cast(Orientation::Outside); } addProperty(_orientation); @@ -211,20 +240,33 @@ RenderableSphere::RenderableSphere(const ghoul::Dictionary& dictionary) addProperty(_texturePath); _texturePath.onChange([this]() { loadTexture(); }); - if (dictionary.hasKey(FadeOutThreshouldInfo.identifier)) { + addProperty(_mirrorTexture); + addProperty(_useAdditiveBlending); + + + if (dictionary.hasKey(MirrorTextureInfo.identifier)) { + _mirrorTexture = dictionary.value(MirrorTextureInfo.identifier); + } + if (dictionary.hasKey(UseAdditiveBlendingInfo.identifier)) { + _useAdditiveBlending = dictionary.value(UseAdditiveBlendingInfo.identifier); + } + + if (dictionary.hasKey(FadeOutThresholdInfo.identifier)) { _fadeOutThreshold = static_cast( - dictionary.value(FadeOutThreshouldInfo.identifier) + dictionary.value(FadeOutThresholdInfo.identifier) ); + addProperty(_fadeOutThreshold); } - if (dictionary.hasKey(FadeInThreshouldInfo.identifier)) { + if (dictionary.hasKey(FadeInThresholdInfo.identifier)) { _fadeInThreshold = static_cast( - dictionary.value(FadeInThreshouldInfo.identifier) + dictionary.value(FadeInThresholdInfo.identifier) ); + addProperty(_fadeInThreshold); } - if (dictionary.hasKey(FadeOutThreshouldInfo.identifier) || - dictionary.hasKey(FadeInThreshouldInfo.identifier)) { + if (dictionary.hasKey(FadeOutThresholdInfo.identifier) || + dictionary.hasKey(FadeInThresholdInfo.identifier)) { _disableFadeInDistance.set(false); addProperty(_disableFadeInDistance); } @@ -235,10 +277,7 @@ bool RenderableSphere::isReady() const { } void RenderableSphere::initializeGL() { - _sphere = std::make_unique( - PowerScaledScalar::CreatePSS(_size), - _segments - ); + _sphere = std::make_unique(_size, _segments); _sphere->initialize(); _shader = BaseModule::ProgramObjectManager.request( @@ -270,41 +309,72 @@ void RenderableSphere::deinitializeGL() { } void RenderableSphere::render(const RenderData& data, RendererTasks&) { - glm::mat4 transform = glm::mat4(1.0); + Orientation orientation = static_cast(_orientation.value()); - transform = glm::rotate(transform, glm::half_pi(), glm::vec3(1, 0, 0)); + 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::dmat3 modelRotation = + glm::dmat3(data.modelTransform.rotation); // Activate shader using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; _shader->activate(); _shader->setIgnoreUniformLocationError(IgnoreError::Yes); - _shader->setUniform(_uniformCache.viewProjection, data.camera.viewProjectionMatrix()); - _shader->setUniform(_uniformCache.modelTransform, transform); + glm::mat4 modelViewProjection = data.camera.projectionMatrix() * + glm::mat4(data.camera.combinedViewMatrix() * modelTransform); + _shader->setUniform(_uniformCache.modelViewProjection, modelViewProjection); - setPscUniforms(*_shader, data.camera, data.position); + glm::mat4 modelViewRotation = glm::mat3( + glm::dmat3(data.camera.viewRotationMatrix()) * modelRotation + ); + _shader->setUniform(_uniformCache.modelViewRotation, modelViewRotation); float adjustedTransparency = _opacity; - if (_fadeInThreshold > 0.0) { - const double distCamera = glm::length(data.camera.positionVec3()); - const float funcValue = static_cast( - (1.0 / double(_fadeInThreshold / 1E24)) * (distCamera / 1E24) - ); + if (_fadeInThreshold > -1.0) { + const float logDistCamera = glm::log(static_cast( + glm::distance(data.camera.positionVec3(), data.modelTransform.translation) + )); + const float startLogFadeDistance = glm::log(_size * _fadeInThreshold); + const float stopLogFadeDistance = startLogFadeDistance + 1.f; - adjustedTransparency *= (funcValue > 1.f) ? 1.f : funcValue; + if (logDistCamera > startLogFadeDistance && logDistCamera < stopLogFadeDistance) { + const float fadeFactor = glm::clamp( + (logDistCamera - startLogFadeDistance) / + (stopLogFadeDistance - startLogFadeDistance), + 0.f, + 1.f + ); + adjustedTransparency *= fadeFactor; + } + else if (logDistCamera <= startLogFadeDistance) { + adjustedTransparency = 0.f; + } } if (_fadeOutThreshold > -1.0) { - const double distCamera = glm::distance( - data.camera.positionVec3(), - data.position.dvec3() - ); - const double term = std::exp( - (-distCamera + _size * _fadeOutThreshold) / (_size * _fadeOutThreshold) - ); + const float logDistCamera = glm::log(static_cast( + glm::distance(data.camera.positionVec3(), data.modelTransform.translation) + )); + const float startLogFadeDistance = glm::log(_size * _fadeOutThreshold); + const float stopLogFadeDistance = startLogFadeDistance + 1.f; - adjustedTransparency *= static_cast(term / (term + 1.0)); + if (logDistCamera > startLogFadeDistance && logDistCamera < stopLogFadeDistance) { + const float fadeFactor = glm::clamp( + (logDistCamera - startLogFadeDistance) / + (stopLogFadeDistance - startLogFadeDistance), + 0.f, + 1.f + ); + adjustedTransparency *= (1.f - fadeFactor); + } + else if (logDistCamera >= stopLogFadeDistance) { + adjustedTransparency = 0.f; + } } // Performance wise @@ -312,38 +382,55 @@ void RenderableSphere::render(const RenderData& data, RendererTasks&) { return; } - _shader->setUniform(_uniformCache.opacity, _opacity); + _shader->setUniform(_uniformCache.opacity, adjustedTransparency); + _shader->setUniform(_uniformCache._mirrorTexture, _mirrorTexture.value()); ghoul::opengl::TextureUnit unit; unit.activate(); _texture->bind(); - _shader->setUniform(_uniformCache.texture, unit); + _shader->setUniform(_uniformCache.colorTexture, unit); + // Setting these states should not be necessary, + // since they are the default state in OpenSpace. glEnable(GL_CULL_FACE); glCullFace(GL_BACK); + if (orientation == Orientation::Inside) { + glCullFace(GL_FRONT); + } else if (orientation == Orientation::Both) { + glDisable(GL_CULL_FACE); + } + bool usingFramebufferRenderer = global::renderEngine.rendererImplementation() == RenderEngine::RendererImplementation::Framebuffer; bool usingABufferRenderer = global::renderEngine.rendererImplementation() == RenderEngine::RendererImplementation::ABuffer; - if (usingABufferRenderer) { + if (usingABufferRenderer && _useAdditiveBlending) { _shader->setUniform("additiveBlending", true); } - if (usingFramebufferRenderer) { + if (usingFramebufferRenderer && _useAdditiveBlending) { glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glDepthMask(false); } _sphere->render(); - if (usingFramebufferRenderer) { + if (usingFramebufferRenderer && _useAdditiveBlending) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthMask(true); } _shader->setIgnoreUniformLocationError(IgnoreError::No); _shader->deactivate(); + + if (orientation == Orientation::Inside) { + glCullFace(GL_BACK); + } else if (orientation == Orientation::Both) { + glEnable(GL_CULL_FACE); + } } void RenderableSphere::update(const UpdateData&) { @@ -353,10 +440,7 @@ void RenderableSphere::update(const UpdateData&) { } if (_sphereIsDirty) { - _sphere = std::make_unique( - PowerScaledScalar::CreatePSS(_size), - _segments - ); + _sphere = std::make_unique(_size, _segments); _sphere->initialize(); _sphereIsDirty = false; } diff --git a/modules/base/rendering/renderablesphere.h b/modules/base/rendering/renderablesphere.h index 468fb5b7e8..ac77832699 100644 --- a/modules/base/rendering/renderablesphere.h +++ b/modules/base/rendering/renderablesphere.h @@ -69,17 +69,20 @@ private: properties::FloatProperty _size; properties::IntProperty _segments; + properties::BoolProperty _mirrorTexture; + properties::BoolProperty _useAdditiveBlending; properties::BoolProperty _disableFadeInDistance; - float _fadeOutThreshold = -1.0; - float _fadeInThreshold = 0.0; + properties::FloatProperty _fadeInThreshold; + properties::FloatProperty _fadeOutThreshold; ghoul::opengl::ProgramObject* _shader = nullptr; std::unique_ptr _texture; std::unique_ptr _sphere; - UniformCache(opacity, viewProjection, modelTransform, texture) _uniformCache; + UniformCache(opacity, modelViewProjection, modelViewRotation, colorTexture, + _mirrorTexture) _uniformCache; bool _sphereIsDirty = false; }; diff --git a/modules/base/rotation/staticrotation.cpp b/modules/base/rotation/staticrotation.cpp index 1b1c9c9a20..6b4dca540a 100644 --- a/modules/base/rotation/staticrotation.cpp +++ b/modules/base/rotation/staticrotation.cpp @@ -34,6 +34,27 @@ namespace { "This value is the used as a 3x3 rotation matrix that is applied to the scene " "graph node that this transformation is attached to relative to its parent." }; + + // Conversion from rotation matrix to euler angles, + // given that the rotation is a pure rotation matrix. + // Inspired by: + // https://www.learnopencv.com/rotation-matrix-to-euler-angles/ + glm::dvec3 rotationMatrixToEulerAngles(glm::dmat4 mat) { + double sy = glm::sqrt(mat[0][0] * mat[0][0] + mat[0][1] * mat[0][1]); + bool singular = sy < 1e-6; + + double x, y, z; + if (singular) { + x = glm::atan(-mat[2][1], mat[1][1]); + y = glm::atan(-mat[0][2], sy); + z = 0; + } else { + x = glm::atan(mat[1][2], mat[2][2]); + y = glm::atan(-mat[0][2], sy); + z = glm::atan(mat[0][1], mat[0][0]); + } + return glm::dvec3(x, y, z); + } } // namespace namespace openspace { @@ -53,21 +74,27 @@ documentation::Documentation StaticRotation::Documentation() { RotationInfo.identifier, new OrVerifier({ new DoubleVector3Verifier(), + new DoubleVector4Verifier(), new DoubleMatrix3Verifier() }), Optional::No, - "Stores the static rotation as either a vector containing Euler angles " - "or by specifiying the 3x3 rotation matrix directly" + "Stores the static rotation as a vector containing Euler angles, " + " a quaternion or a rotation matrix." } } }; } StaticRotation::StaticRotation() - : _rotationMatrix(RotationInfo, glm::dmat3(1.0), glm::dmat3(-1.0), glm::dmat3(1.0)) + : _eulerRotation( + RotationInfo, + glm::vec3(0.f), + glm::vec3(-glm::pi()), + glm::vec3(glm::pi()) + ) { - addProperty(_rotationMatrix); - _rotationMatrix.onChange([this]() { requireUpdate(); }); + addProperty(_eulerRotation); + _eulerRotation.onChange([this]() { requireUpdate(); }); } StaticRotation::StaticRotation(const ghoul::Dictionary& dictionary) : StaticRotation() { @@ -77,20 +104,35 @@ StaticRotation::StaticRotation(const ghoul::Dictionary& dictionary) : StaticRota "StaticRotation" ); - if (dictionary.hasKeyAndValue(RotationInfo.identifier)) { - _rotationMatrix = glm::mat3_cast( - glm::dquat(dictionary.value(RotationInfo.identifier)) + _eulerRotation = static_cast( + dictionary.value(RotationInfo.identifier) ); + _matrixIsDirty = true; + } else if (dictionary.hasKeyAndValue(RotationInfo.identifier)) { + glm::dvec4 data = dictionary.value(RotationInfo.identifier); + _eulerRotation = rotationMatrixToEulerAngles( + glm::mat3_cast(glm::dquat(data.w, data.x, data.y, data.z)) + ); + _matrixIsDirty = true; + } else if (dictionary.hasKeyAndValue(RotationInfo.identifier)) { + _eulerRotation = rotationMatrixToEulerAngles( + dictionary.value(RotationInfo.identifier) + ); + _matrixIsDirty = true; } - else { - // Must be glm::dmat3 due to specification restriction - _rotationMatrix = dictionary.value(RotationInfo.identifier); - } + + _eulerRotation.onChange([this]() { + _matrixIsDirty = true; + }); } glm::dmat3 StaticRotation::matrix(const UpdateData&) const { - return _rotationMatrix; + if (_matrixIsDirty) { + _cachedMatrix = glm::mat3_cast(glm::quat(_eulerRotation.value())); + _matrixIsDirty = false; + } + return _cachedMatrix; } } // namespace openspace diff --git a/modules/base/rotation/staticrotation.h b/modules/base/rotation/staticrotation.h index 9394631650..a4e43ecee9 100644 --- a/modules/base/rotation/staticrotation.h +++ b/modules/base/rotation/staticrotation.h @@ -27,7 +27,7 @@ #include -#include +#include namespace openspace { @@ -43,7 +43,9 @@ public: static documentation::Documentation Documentation(); private: - properties::DMat3Property _rotationMatrix; + properties::Vec3Property _eulerRotation; + mutable glm::dmat3 _cachedMatrix; + mutable bool _matrixIsDirty = true; }; } // namespace openspace diff --git a/modules/base/shaders/sphere_fs.glsl b/modules/base/shaders/sphere_fs.glsl index e41037caa6..5a82d91e6e 100644 --- a/modules/base/shaders/sphere_fs.glsl +++ b/modules/base/shaders/sphere_fs.glsl @@ -25,31 +25,30 @@ #include "fragment.glsl" #include "PowerScaling/powerScaling_fs.hglsl" -in vec2 vs_st; in vec4 vs_position; -in vec4 vs_gPosition; +in vec2 vs_textureCoords; +in vec3 vs_normal; uniform float time; -uniform sampler2D texture1; +uniform sampler2D colorTexture; uniform float opacity; - +uniform bool mirrorTexture; Fragment getFragment() { - vec4 position = vs_position; - vec2 texCoord = vs_st; - // Why is this here? ---abock - texCoord.s = 1 - texCoord.s; - texCoord.t = 1 - texCoord.y; + vec2 texCoord = vs_textureCoords; Fragment frag; - frag.color = texture(texture1, texCoord) * vec4(1.0, 1.0, 1.0, opacity); - frag.depth = pscDepth(position); + if (mirrorTexture) { + texCoord.x = 1.0 - texCoord.x; + } + + frag.color = texture(colorTexture, texCoord); + frag.color.a *= opacity; + frag.depth = vs_position.w; // G-Buffer - frag.gPosition = vs_gPosition; - // There is no normal here - // TODO: Add the correct normal (JCC) - frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0); + frag.gPosition = vs_position; + frag.gNormal = vec4(vs_normal, 1.0); return frag; - } +} diff --git a/modules/base/shaders/sphere_vs.glsl b/modules/base/shaders/sphere_vs.glsl index 718f1b5748..38b19f23f0 100644 --- a/modules/base/shaders/sphere_vs.glsl +++ b/modules/base/shaders/sphere_vs.glsl @@ -24,35 +24,23 @@ #version __CONTEXT__ -#include "PowerScaling/powerScaling_vs.hglsl" - layout(location = 0) in vec4 in_position; -layout(location = 1) in vec2 in_st; +layout(location = 1) in vec2 in_textureCoords; -out vec2 vs_st; +uniform mat4 modelViewProjection; +uniform mat3 modelViewRotation; + +out vec2 vs_textureCoords; out vec4 vs_position; -out float s; -out vec4 vs_gPosition; - -uniform mat4 ViewProjection; -uniform mat4 ModelTransform; - +out vec3 vs_normal; void main() { - vec4 tmp = in_position; + vs_normal = modelViewRotation * normalize(in_position.xyz); + vs_textureCoords = in_textureCoords; - mat4 mt = mat4(0.0, -1.0, 0.0, 0.0, - 1.0, 0.0, 0.0, 0.0, - 0.0, 0.0, -1.0, 0.0, - 0.0, 0.0, 0.0, 1.0) * ModelTransform; - - vec4 position = pscTransform(tmp, mt); - - vs_position = tmp; - vs_st = in_st; - vs_gPosition = position; - - position = ViewProjection * position; - gl_Position = z_normalization(position); + vec4 position = modelViewProjection * vec4(in_position.xyz, 1.0); + vs_position = position; + // Set z to 0 to disable near/far-plane clipping + gl_Position = vec4(position.xy, 0.0, position.w); } diff --git a/modules/debugging/rendering/renderabledebugplane.cpp b/modules/debugging/rendering/renderabledebugplane.cpp index b16860cef8..1ba47a690c 100644 --- a/modules/debugging/rendering/renderabledebugplane.cpp +++ b/modules/debugging/rendering/renderabledebugplane.cpp @@ -218,7 +218,11 @@ void RenderableDebugPlane::render(const RenderData& data, RendererTasks&) { _shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _shader->setUniform("ModelTransform", transform); - setPscUniforms(*_shader, data.camera, data.position); + + _shader->setUniform("campos", glm::vec4(data.camera.positionVec3(), 1.f)); + _shader->setUniform("objpos", glm::vec4(data.modelTransform.translation, 0.f)); + _shader->setUniform("camrot", glm::mat4(data.camera.viewRotationMatrix())); + _shader->setUniform("scaling", glm::vec2(1.f, 0.f)); ghoul::opengl::TextureUnit unit; unit.activate(); diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index 9e8c1ac6fb..efdafba2d7 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -427,16 +427,21 @@ RenderableBillboardsCloud::RenderableBillboardsCloud(const ghoul::Dictionary& di addProperty(_drawElements); } - // DEBUG: _renderOption.addOption(0, "Camera View Direction"); _renderOption.addOption(1, "Camera Position Normal"); + _renderOption.set(1); - if (global::windowDelegate.isFisheyeRendering()) { - _renderOption.set(1); - } - else { - _renderOption.set(0); + if (dictionary.hasKeyAndValue(RenderOptionInfo.identifier)) { + const std::string option = + dictionary.value(RenderOptionInfo.identifier); + + if (option == "Camera View Direction") { + _renderOption.set(0); + } else if (option == "Camera Position Normal") { + _renderOption.set(1); + } } + addProperty(_renderOption); if (dictionary.hasKey(keyUnit)) { diff --git a/modules/fieldlines/rendering/renderablefieldlines.cpp b/modules/fieldlines/rendering/renderablefieldlines.cpp index fec84ed88b..8caf8d0408 100644 --- a/modules/fieldlines/rendering/renderablefieldlines.cpp +++ b/modules/fieldlines/rendering/renderablefieldlines.cpp @@ -229,7 +229,10 @@ void RenderableFieldlines::render(const RenderData& data, RendererTasks&) { glm::vec3(data.camera.viewDirectionWorldSpace()) ); glDisable(GL_CULL_FACE); - setPscUniforms(*_program, data.camera, data.position); + _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)); _program->setUniform("classification", _classification); if (!_classification) { diff --git a/modules/galaxy/rendering/galaxyraycaster.cpp b/modules/galaxy/rendering/galaxyraycaster.cpp index cc218de91f..29450d7903 100644 --- a/modules/galaxy/rendering/galaxyraycaster.cpp +++ b/modules/galaxy/rendering/galaxyraycaster.cpp @@ -59,7 +59,10 @@ void GalaxyRaycaster::renderEntryPoints(const RenderData& data, program.setUniform("viewProjection", data.camera.viewProjectionMatrix()); program.setUniform("blendMode", static_cast(1)); - Renderable::setPscUniforms(program, data.camera, data.position); + 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,7 +79,11 @@ void GalaxyRaycaster::renderExitPoints(const RenderData& data, program.setUniform("modelTransform", _modelTransform); program.setUniform("viewProjection", data.camera.viewProjectionMatrix()); program.setUniform("blendMode", static_cast(1)); - Renderable::setPscUniforms(program, data.camera, data.position); + + 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); @@ -122,7 +129,7 @@ bool GalaxyRaycaster::isCameraInside(const RenderData& data, glm::vec3& localPos // Camera position in world coordinates. const glm::vec4 camWorldPos = rigWorldPos; - const glm::vec3 objPos = data.position.vec3(); + const glm::vec3 objPos = static_cast(data.modelTransform.translation); const glm::mat4 modelTransform = glm::translate(_modelTransform, objPos); diff --git a/modules/globebrowsing/src/renderableglobe.cpp b/modules/globebrowsing/src/renderableglobe.cpp index 17a2bab78e..f5907c331b 100644 --- a/modules/globebrowsing/src/renderableglobe.cpp +++ b/modules/globebrowsing/src/renderableglobe.cpp @@ -1677,7 +1677,7 @@ void RenderableGlobe::calculateEclipseShadows(ghoul::opengl::ProgramObject& prog // First we determine if the caster is shadowing the current planet (all // calculations in World Coordinates): - const glm::dvec3 planetCasterVec = casterPos - data.position.dvec3(); + const glm::dvec3 planetCasterVec = casterPos - data.modelTransform.translation; const glm::dvec3 sourceCasterVec = casterPos - sourcePos; const double sc_length = glm::length(sourceCasterVec); const glm::dvec3 planetCaster_proj = @@ -1698,7 +1698,8 @@ void RenderableGlobe::calculateEclipseShadows(ghoul::opengl::ProgramObject& prog lt ); const double casterDistSun = glm::length(casterPos - sunPos); - const double planetDistSun = glm::length(data.position.dvec3() - sunPos); + const double planetDistSun = + glm::length(data.modelTransform.translation - sunPos); ShadowRenderingStruct shadowData; shadowData.isShadowing = false; diff --git a/modules/iswa/rendering/datasphere.cpp b/modules/iswa/rendering/datasphere.cpp index 90f00aa37e..10cdc263a2 100644 --- a/modules/iswa/rendering/datasphere.cpp +++ b/modules/iswa/rendering/datasphere.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -87,7 +86,7 @@ void DataSphere::initializeGL() { } bool DataSphere::createGeometry() { - PowerScaledScalar radius = PowerScaledScalar(6.371f * _radius, 6.0); + const float radius = 6.371f * _radius * glm::pow(10.f, 6.f); int segments = 100; _sphere = std::make_unique(radius, segments); _sphere->initialize(); diff --git a/modules/iswa/rendering/iswacygnet.cpp b/modules/iswa/rendering/iswacygnet.cpp index d86b2f3930..663ba6dca4 100644 --- a/modules/iswa/rendering/iswacygnet.cpp +++ b/modules/iswa/rendering/iswacygnet.cpp @@ -157,10 +157,12 @@ void IswaCygnet::render(const RenderData& data, RendererTasks&) { } transform = transform * _rotation; - psc position = data.position + transform * glm::vec4( - _data.spatialScale.x * _data.offset, - _data.spatialScale.w - ); + psc position = + static_cast(glm::dvec4(data.modelTransform.translation, 0.0)) + + transform * glm::vec4( + _data.spatialScale.x * _data.offset, + _data.spatialScale.w + ); // Activate shader _shader->activate(); @@ -170,7 +172,11 @@ void IswaCygnet::render(const RenderData& data, RendererTasks&) { _shader->setUniform("ViewProjection", data.camera.viewProjectionMatrix()); _shader->setUniform("ModelTransform", transform); - setPscUniforms(*_shader.get(), data.camera, position); + _shader->setUniform("campos", glm::vec4(data.camera.positionVec3(), 1.f)); + _shader->setUniform("objpos", glm::vec4(position.vec3(), 0.f)); + _shader->setUniform("camrot", glm::mat4(data.camera.viewRotationMatrix())); + _shader->setUniform("scaling", glm::vec2(1.f, 0.f)); + setUniforms(); renderGeometry(); diff --git a/modules/multiresvolume/rendering/errorhistogrammanager.cpp b/modules/multiresvolume/rendering/errorhistogrammanager.cpp index e0482b5b02..f60a5f7806 100644 --- a/modules/multiresvolume/rendering/errorhistogrammanager.cpp +++ b/modules/multiresvolume/rendering/errorhistogrammanager.cpp @@ -364,8 +364,7 @@ unsigned int ErrorHistogramManager::brickToInnerNodeIndex(unsigned int brickInde unsigned int ErrorHistogramManager::innerNodeToBrickIndex( unsigned int innerNodeIndex) const { - // @TODO(abock): innerNodeIndex is an unsigned int, so it will never be < 0 - if (innerNodeIndex < 0 || innerNodeIndex >= _numInnerNodes) { + if (innerNodeIndex >= _numInnerNodes) { return std::numeric_limits::max(); // Not an inner node } diff --git a/modules/multiresvolume/rendering/multiresvolumeraycaster.cpp b/modules/multiresvolume/rendering/multiresvolumeraycaster.cpp index 41c27b8e7c..2c86df53e2 100644 --- a/modules/multiresvolume/rendering/multiresvolumeraycaster.cpp +++ b/modules/multiresvolume/rendering/multiresvolumeraycaster.cpp @@ -67,7 +67,10 @@ void MultiresVolumeRaycaster::renderEntryPoints(const RenderData& data, { program.setUniform("modelTransform", _modelTransform); program.setUniform("viewProjection", data.camera.viewProjectionMatrix()); - Renderable::setPscUniforms(program, data.camera, data.position); + 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)); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); @@ -80,7 +83,10 @@ void MultiresVolumeRaycaster::renderExitPoints(const RenderData& data, { program.setUniform("modelTransform", _modelTransform); program.setUniform("viewProjection", data.camera.viewProjectionMatrix()); - Renderable::setPscUniforms(program, data.camera, data.position); + 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)); glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); @@ -139,7 +145,7 @@ bool MultiresVolumeRaycaster::isCameraInside(const RenderData& data, // Camera position in world coordinates. glm::vec4 camWorldPos = rigWorldPos; - glm::vec3 objPos = data.position.vec3(); + glm::vec3 objPos = static_cast(data.modelTransform.translation); glm::mat4 modelTransform = glm::translate(_modelTransform, objPos); diff --git a/modules/space/CMakeLists.txt b/modules/space/CMakeLists.txt index 107c86614b..de5321435b 100644 --- a/modules/space/CMakeLists.txt +++ b/modules/space/CMakeLists.txt @@ -27,7 +27,6 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometry.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableconstellationbounds.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanet.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablerings.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.h @@ -42,7 +41,6 @@ source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/rendering/planetgeometry.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableconstellationbounds.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableplanet.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablerings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderablestars.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/simplespheregeometry.cpp @@ -57,16 +55,8 @@ source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/shaders/constellationbounds_fs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/constellationbounds_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/nighttexture_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/nighttexture_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableplanet_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/renderableplanet_vs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/rings_vs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/rings_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_vs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_nighttexture_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shadow_nighttexture_vs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_fs.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_ge.glsl ${CMAKE_CURRENT_SOURCE_DIR}/shaders/star_vs.glsl diff --git a/modules/space/rendering/renderableconstellationbounds.cpp b/modules/space/rendering/renderableconstellationbounds.cpp index e95b101ea8..95183268e7 100644 --- a/modules/space/rendering/renderableconstellationbounds.cpp +++ b/modules/space/rendering/renderableconstellationbounds.cpp @@ -229,7 +229,10 @@ bool RenderableConstellationBounds::isReady() const { void RenderableConstellationBounds::render(const RenderData& data, RendererTasks&) { _program->activate(); - setPscUniforms(*_program, data.camera, data.position); + _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)); glm::dmat4 modelTransform = glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * diff --git a/modules/space/rendering/renderableplanet.cpp b/modules/space/rendering/renderableplanet.cpp deleted file mode 100644 index affe22e95b..0000000000 --- a/modules/space/rendering/renderableplanet.cpp +++ /dev/null @@ -1,689 +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. * - ****************************************************************************************/ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace { - constexpr const char* PlainProgramName = "PlanetProgram"; - constexpr const char* ShadowNightProgramName = "ShadowNightPlanetProgram"; - constexpr const char* NightProgramName = "NightPlanetProgram"; - constexpr const char* ShadowProgramName = "ShadowPlanetProgram"; - - constexpr const char* KeyBody = "Body"; - constexpr const char* KeyGeometry = "Geometry"; - constexpr const char* KeyRadius = "Radius"; - constexpr const char* _loggerCat = "RenderablePlanet"; - - constexpr const char* KeyShadowGroup = "Shadow_Group"; - constexpr const char* KeyShadowSource = "Source"; - constexpr const char* KeyShadowCaster = "Caster"; - - constexpr openspace::properties::Property::PropertyInfo ColorTextureInfo = { - "ColorTexture", - "Color Base Texture", - "The path to the base color texture that is used on the planet prior to any " - "image projection." - }; - - constexpr openspace::properties::Property::PropertyInfo HeightTextureInfo = { - "HeightTexture", - "Heightmap Texture", - "The path to the height map texture that is used for the planet. If no height " - "map is specified the planet does not use a height field." - }; - - constexpr openspace::properties::Property::PropertyInfo NightTextureInfo = { - "NightTexture", - "Night Texture", - "The path to the night texture that is used for the part of the planet that is " - "facing away from the Sun. If no night texture is loaded, the night side of the " - "planet is rendered dark." - }; - - constexpr openspace::properties::Property::PropertyInfo HeightExaggerationInfo = { - "HeightExaggeration", - "Height Exaggeration", - "This value determines the level of height exaggeration that is applied to a " - "potential height field. A value of '0' inhibits the height field, whereas a " - "value of '1' uses the measured height field." - }; - - constexpr openspace::properties::Property::PropertyInfo PerformShadingInfo = { - "PerformShading", - "Perform Shading", - "If this value is enabled, the model will be shaded based on the relative " - "location to the Sun. If this value is disabled, shading is disabled and the " - "entire model is rendered brightly. If this value is 'false', any existing night " - "texture will not be used." - }; -} // namespace - -namespace openspace { - -documentation::Documentation RenderablePlanet::Documentation() { - using namespace documentation; - return { - "RenderablePlanet", - "space_renderable_planet", - { - { - KeyGeometry, - new ReferencingVerifier("space_geometry_planet"), - Optional::No, - "Specifies the planet geometry that is used for this RenderablePlanet." - }, - { - KeyRadius, - new DoubleVerifier, - Optional::Yes, - "Specifies the radius of the planet. If this value is not specified, it " - "will try to query the SPICE library for radius values using the body " - "key." - }, - { - KeyBody, - new StringVerifier, - Optional::Yes, - "If that radius is not specified, this name is used to query the SPICE " - "library for the radius values." - }, - { - ColorTextureInfo.identifier, - new StringVerifier, - Optional::Yes, - ColorTextureInfo.description - }, - { - HeightTextureInfo.identifier, - new StringVerifier, - Optional::Yes, - HeightTextureInfo.description - }, - { - NightTextureInfo.identifier, - new StringVerifier, - Optional::Yes, - NightTextureInfo.description - }, - { - PerformShadingInfo.identifier, - new BoolVerifier, - Optional::Yes, - PerformShadingInfo.description - }, - { - HeightExaggerationInfo.identifier, - new DoubleVerifier, - Optional::Yes, - HeightExaggerationInfo.description - }, - { - PerformShadingInfo.identifier, - new BoolVerifier, - Optional::Yes, - PerformShadingInfo.description - } - } - }; -} - -RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary) - : Renderable(dictionary) - , _colorTexturePath(ColorTextureInfo) - , _nightTexturePath(NightTextureInfo) - , _heightMapTexturePath(HeightTextureInfo) - , _heightExaggeration(HeightExaggerationInfo, 1.f, 0.f, 10.f) - , _performShading(PerformShadingInfo, true) -{ - documentation::testSpecificationAndThrow( - Documentation(), - dictionary, - "RenderablePlanet" - ); - - ghoul::Dictionary geomDict = dictionary.value(KeyGeometry); - - if (dictionary.hasKeyAndValue(KeyRadius)) { - // If the user specified a radius, we want to use this - _planetRadius = static_cast(dictionary.value(KeyRadius)); - } - else { - if (!dictionary.hasKey(KeyBody)) { - documentation::TestResult res; - res.success = false; - documentation::TestResult::Offense offense = { - fmt::format("{} or {}", KeyRadius, KeyBody), - documentation::TestResult::Offense::Reason::MissingKey - }; - res.offenses.push_back(std::move(offense)); - throw documentation::SpecificationError( - std::move(res), - std::move("RenderablePlanet") - ); - } - - const std::string& body = dictionary.value(KeyBody); - - // If the user didn't specfify a radius, but Spice has a radius, we can use this - glm::dvec3 radius; - SpiceManager::ref().getValue(body, "RADII", radius); - radius *= 1000.0; // Spice gives radii in KM. - std::swap(radius[1], radius[2]); // z is equivalent to y in our coordinate system - geomDict.setValue(KeyRadius, radius); - - _planetRadius = static_cast((radius.x + radius.y + radius.z) / 3.0); - } - - _geometry = planetgeometry::PlanetGeometry::createFromDictionary(geomDict); - - if (dictionary.hasKeyAndValue(ColorTextureInfo.identifier)) { - _colorTexturePath = absPath(dictionary.value( - ColorTextureInfo.identifier - )); - } - - if (dictionary.hasKeyAndValue(NightTextureInfo.identifier)) { - _hasNightTexture = true; - _nightTexturePath = absPath(dictionary.value( - NightTextureInfo.identifier - )); - } - - if (dictionary.hasKeyAndValue(HeightTextureInfo.identifier)) { - _hasHeightTexture = true; - _heightMapTexturePath = absPath(dictionary.value( - HeightTextureInfo.identifier - )); - } - - if (dictionary.hasKeyAndValue(PerformShadingInfo.identifier)) { - _performShading = dictionary.value(PerformShadingInfo.identifier); - } - addProperty(_performShading); - - addPropertySubOwner(_geometry.get()); - - auto loadTextureCallback = [this]() { loadTexture(); }; - addProperty(_colorTexturePath); - _colorTexturePath.onChange(loadTextureCallback); - - addProperty(_nightTexturePath); - _nightTexturePath.onChange(loadTextureCallback); - - addProperty(_heightMapTexturePath); - _heightMapTexturePath.onChange(loadTextureCallback); - - if (dictionary.hasKey(HeightExaggerationInfo.identifier)) { - _heightExaggeration = static_cast( - dictionary.value(HeightExaggerationInfo.identifier) - ); - } - addProperty(_heightExaggeration); - - //================================================================ - //======== Reads Shadow (Eclipses) Entries in mod file =========== - //================================================================ - ghoul::Dictionary shadowDictionary; - bool success = dictionary.getValue(KeyShadowGroup, shadowDictionary); - bool disableShadows = false; - if (success) { - std::vector> sourceArray; - unsigned int sourceCounter = 1; - while (success) { - std::string sourceName; - success = shadowDictionary.getValue( - KeyShadowSource + std::to_string(sourceCounter) + ".Name", - sourceName - ); - if (success) { - float sourceRadius; - success = shadowDictionary.getValue( - KeyShadowSource + std::to_string(sourceCounter) + ".Radius", - sourceRadius - ); - if (success) { - sourceArray.emplace_back(sourceName, sourceRadius); - } - else { - LWARNING(fmt::format( - "No Radius value specified for Shadow Source Name '{}' from " - "'{}' planet. Disabling shadows for this planet", - sourceName, identifier() - )); - disableShadows = true; - break; - } - } - sourceCounter++; - } - - if (!disableShadows && !sourceArray.empty()) { - success = true; - std::vector> casterArray; - unsigned int casterCounter = 1; - while (success) { - std::string casterName; - success = shadowDictionary.getValue( - KeyShadowCaster + std::to_string(casterCounter) + ".Name", - casterName - ); - if (success) { - float casterRadius; - success = shadowDictionary.getValue( - KeyShadowCaster + std::to_string(casterCounter) + ".Radius", - casterRadius - ); - if (success) { - casterArray.emplace_back(casterName, casterRadius); - } - else { - LWARNING(fmt::format( - "No Radius value expecified for Shadow Caster Name '{}' from " - "'{}' planet. Disabling shadows for this planet.", - casterName, identifier() - )); - disableShadows = true; - break; - } - } - - casterCounter++; - } - - if (!disableShadows && (!sourceArray.empty() && !casterArray.empty())) { - for (std::pair& source : sourceArray) { - for (std::pair& caster : casterArray) { - ShadowConfiguration sc; - sc.source = source; - sc.caster = caster; - _shadowConfArray.push_back({ source, caster }); - } - } - _shadowEnabled = true; - } - } - } -} - -void RenderablePlanet::initializeGL() { - // @FRAGILE: The shader deinitialization below relies on the name names for the - // request and the parameters to buildRenderProgram. That way, we can use - // the ProgramObject name in the releaseProgramObject method and release the - // correct one. - - if (!_programObject && _shadowEnabled && _hasNightTexture) { - _programObject = SpaceModule::ProgramObjectManager.request( - ShadowNightProgramName, - []() -> std::unique_ptr { - return global::renderEngine.buildRenderProgram( - ShadowNightProgramName, - absPath("${MODULE_SPACE}/shaders/shadow_nighttexture_vs.glsl"), - absPath("${MODULE_SPACE}/shaders/shadow_nighttexture_fs.glsl") - ); - } - ); - } - else if (!_programObject && _shadowEnabled) { - _programObject = SpaceModule::ProgramObjectManager.request( - ShadowProgramName, - []() -> std::unique_ptr { - return global::renderEngine.buildRenderProgram( - ShadowProgramName, - absPath("${MODULE_SPACE}/shaders/shadow_vs.glsl"), - absPath("${MODULE_SPACE}/shaders/shadow_fs.glsl") - ); - } - ); - } - else if (!_programObject && _hasNightTexture) { - _programObject = SpaceModule::ProgramObjectManager.request( - NightProgramName, - []() -> std::unique_ptr { - return global::renderEngine.buildRenderProgram( - NightProgramName, - absPath("${MODULE_SPACE}/shaders/nighttexture_vs.glsl"), - absPath("${MODULE_SPACE}/shaders/nighttexture_fs.glsl") - ); - } - ); - } - else if (!_programObject) { - _programObject = SpaceModule::ProgramObjectManager.request( - PlainProgramName, - []() -> std::unique_ptr { - return global::renderEngine.buildRenderProgram( - PlainProgramName, - absPath("${MODULE_SPACE}/shaders/renderableplanet_vs.glsl"), - absPath("${MODULE_SPACE}/shaders/renderableplanet_fs.glsl") - ); - } - ); - } - - using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError; - _programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes); - _programObject->setIgnoreUniformLocationError(IgnoreError::Yes); - - _geometry->initialize(); - setBoundingSphere(_geometry->boundingSphere()); - - // Deactivate any previously activated shader program. - _programObject->deactivate(); - - loadTexture(); -} - -void RenderablePlanet::deinitializeGL() { - if (_geometry) { - _geometry->deinitialize(); - _geometry = nullptr; - } - - SpaceModule::ProgramObjectManager.release( - _programObject->name(), - [](ghoul::opengl::ProgramObject* p) { - global::renderEngine.removeRenderProgram(p); - } - ); - - _texture = nullptr; - _nightTexture = nullptr; -} - -bool RenderablePlanet::isReady() const { - return _programObject && _texture && _geometry; -} - -glm::dmat4 RenderablePlanet::computeModelTransformMatrix( - const openspace::TransformData& transformData) -{ - // scale the planet to appropriate size since the planet is a unit sphere - glm::dmat4 modelTransform = - glm::translate(glm::dmat4(1.0), transformData.translation) * // Translation - glm::dmat4(transformData.rotation) * // Spice rotation - glm::scale(glm::dmat4(1.0), glm::dvec3(transformData.scale)); - - // scale the planet to appropriate size since the planet is a unit sphere - //glm::mat4 transform = glm::mat4(1); - - //earth needs to be rotated for that to work. - glm::dmat4 rot = glm::rotate( - glm::dmat4(1.0), - glm::half_pi(), - glm::dvec3(1.0, 0.0, 0.0) - ); - glm::dmat4 roty = glm::rotate( - glm::dmat4(1.0), - glm::half_pi(), - glm::dvec3(0.0, -1.0, 0.0) - ); - - return modelTransform = modelTransform * rot * roty /** rotProp*/; -} - -void RenderablePlanet::render(const RenderData& data, RendererTasks&) { - // activate shader - _programObject->activate(); - - glm::dmat4 modelTransform = computeModelTransformMatrix(data.modelTransform); - glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; - - _programObject->setUniform("transparency", _alpha); - _programObject->setUniform("modelViewTransform", modelViewTransform); - _programObject->setUniform( - "modelViewProjectionTransform", - data.camera.sgctInternal.projectionMatrix() * glm::mat4(modelViewTransform) - ); - _programObject->setUniform("ModelTransform", glm::mat4(modelTransform)); - - // Normal Transformation - //glm::mat4 translateObjTrans = glm::translate(glm::mat4(1.0), data.position.vec3()); - //glm::mat4 translateCamTrans = glm::translate( - // glm::mat4(1.0), - // -data.camera.position().vec3() - //); - //float scaleFactor = data.camera.scaling().x * powf(10.0, data.camera.scaling().y); - //glm::mat4 scaleCamTrans = glm::scale(glm::mat4(1.0), glm::vec3(scaleFactor)); - -// glm::mat4 ModelViewTrans = data.camera.viewMatrix() * scaleCamTrans * -// translateCamTrans * translateObjTrans * glm::mat4(modelTransform); - - setPscUniforms(*_programObject, data.camera, data.position); - - _programObject->setUniform("_performShading", _performShading); - _programObject->setUniform("_hasHeightMap", _hasHeightTexture); - _programObject->setUniform("_heightExaggeration", _heightExaggeration); - - // Bind texture - ghoul::opengl::TextureUnit dayUnit; - ghoul::opengl::TextureUnit nightUnit; - ghoul::opengl::TextureUnit heightUnit; - - dayUnit.activate(); - _texture->bind(); - _programObject->setUniform("texture1", dayUnit); - - // Bind possible night texture - if (_hasNightTexture && _nightTexture) { - nightUnit.activate(); - _nightTexture->bind(); - _programObject->setUniform("nightTex", nightUnit); - } - - if (_hasHeightTexture && _heightMapTexture) { - heightUnit.activate(); - _heightMapTexture->bind(); - _programObject->setUniform("heightTex", heightUnit); - } - - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - - //============================================================================= - //============= Eclipse Shadow Calculations and Uniforms Loading ============== - //============================================================================= - // TODO: Move Calculations to VIEW SPACE (let's avoid precision problems...) - double lt; - if (!_shadowConfArray.empty()) { - std::vector shadowDataArray; - shadowDataArray.reserve(_shadowConfArray.size()); - - for (const ShadowConfiguration& shadowConf : _shadowConfArray) { - // TO REMEMBER: all distances and lengths in world coordinates are in meters!! - // We need to move this to view space... - // Getting source and caster: - glm::dvec3 sourcePos = SpiceManager::ref().targetPosition( - shadowConf.source.first, - "SUN", - "GALACTIC", - {}, - _time, - lt - ); - sourcePos *= 1000.0; // converting to meters - glm::dvec3 casterPos = SpiceManager::ref().targetPosition( - shadowConf.caster.first, - "SUN", - "GALACTIC", - {}, - _time, - lt - ); - casterPos *= 1000.0; // converting to meters - psc caster_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate( - casterPos.x, - casterPos.y, - casterPos.z - ); - - // First we determine if the caster is shadowing the current planet (all - // calculations in World Coordinates): - const glm::vec3 planetCasterVec = (caster_pos - data.position).vec3(); - const glm::vec3 sourceCasterVec = glm::vec3(casterPos - sourcePos); - const float sc_length = glm::length(sourceCasterVec); - const glm::vec3 planetCaster_proj = - (glm::dot(planetCasterVec, sourceCasterVec) / (sc_length*sc_length)) * - sourceCasterVec; - const float d_test = glm::length(planetCasterVec - planetCaster_proj); - const float xp_test = shadowConf.caster.second * sc_length / - (shadowConf.source.second + shadowConf.caster.second); - const float rp_test = shadowConf.caster.second * - (glm::length(planetCaster_proj) + xp_test) / - xp_test; - - const double casterDistSun = glm::length(casterPos); - const float planetDistSun = glm::length(data.position.vec3()); - - ShadowRenderingStruct shadowData; - shadowData.isShadowing = false; - - if (((d_test - rp_test) < _planetRadius) && (casterDistSun < planetDistSun)) { - // The current caster is shadowing the current planet - shadowData.isShadowing = true; - shadowData.rs = shadowConf.source.second; - shadowData.rc = shadowConf.caster.second; - shadowData.sourceCasterVec = sourceCasterVec; - shadowData.xp = xp_test; - shadowData.xu = shadowData.rc * sc_length / - (shadowData.rs - shadowData.rc); - shadowData.casterPositionVec = glm::vec3(casterPos); - } - shadowDataArray.push_back(shadowData); - } - - constexpr const char* isShadowingTemplate = "shadowDataArray[{}].isShadowing"; - constexpr const char* xpTemplate = "shadowDataArray[{}].xp"; - constexpr const char* xuTemplate = "shadowDataArray[{}].xu"; - constexpr const char* rcTemplate = "shadowDataArray[{}].rc"; - constexpr const char* sourceTemplate = "shadowDataArray[{}].sourceCasterVec"; - constexpr const char* casterTemplate = "shadowDataArray[{}].casterPositionVec"; - - const std::string uniformVarName("shadowDataArray["); - unsigned int counter = 0; - for (const ShadowRenderingStruct& sd : shadowDataArray) { - _programObject->setUniform( - fmt::format(isShadowingTemplate, counter), - sd.isShadowing - ); - - if (sd.isShadowing) { - _programObject->setUniform(fmt::format(xpTemplate, counter), sd.xp); - _programObject->setUniform(fmt::format(xuTemplate, counter), sd.xu); - _programObject->setUniform(fmt::format(rcTemplate, counter), sd.rc); - _programObject->setUniform( - fmt::format(sourceTemplate, counter), - sd.sourceCasterVec - ); - _programObject->setUniform( - fmt::format(casterTemplate, counter), - sd.casterPositionVec - ); - } - counter++; - } - } - - // render - _geometry->render(); - - // disable shader - _programObject->deactivate(); -} - -void RenderablePlanet::update(const UpdateData& data) { - // set spice-orientation in accordance to timestamp - _stateMatrix = data.modelTransform.rotation; - _time = data.time.j2000Seconds(); - - if (_programObject && _programObject->isDirty()) { - _programObject->rebuildFromFile(); - } -} - -void RenderablePlanet::loadTexture() { - _texture = nullptr; - if (!_colorTexturePath.value().empty()) { - using namespace ghoul::io; - _texture = TextureReader::ref().loadTexture(absPath(_colorTexturePath)); - if (_texture) { - if (_texture->numberOfChannels() == 1) { - _texture->setSwizzleMask({ GL_RED, GL_RED, GL_RED, GL_RED }); - } - - LDEBUG(fmt::format("Loaded texture '{}'", _colorTexturePath.value())); - _texture->uploadTexture(); - _texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); - } - } - - if (_hasNightTexture) { - _nightTexture = nullptr; - if (!_nightTexturePath.value().empty()) { - using namespace ghoul::io; - _nightTexture = TextureReader::ref().loadTexture(absPath(_nightTexturePath)); - if (_nightTexture) { - LDEBUG(fmt::format("Loaded texture '{}'", _nightTexturePath.value())); - _nightTexture->uploadTexture(); - _nightTexture->setFilter( - ghoul::opengl::Texture::FilterMode::LinearMipMap - ); - } - } - } - - if (_hasHeightTexture) { - _heightMapTexture = nullptr; - if (!_heightMapTexturePath.value().empty()) { - _heightMapTexture = ghoul::io::TextureReader::ref().loadTexture( - absPath(_heightMapTexturePath) - ); - if (_heightMapTexture) { - LDEBUG(fmt::format( - "Loaded texture from '{}'", - _heightMapTexturePath.value() - )); - _heightMapTexture->uploadTexture(); - _heightMapTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); - } - } - } -} - -} // namespace openspace diff --git a/modules/space/rendering/renderableplanet.h b/modules/space/rendering/renderableplanet.h deleted file mode 100644 index ff40289dee..0000000000 --- a/modules/space/rendering/renderableplanet.h +++ /dev/null @@ -1,113 +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. * - ****************************************************************************************/ - -#ifndef __OPENSPACE_MODULE_SPACE___RENDERABLEPLANET___H__ -#define __OPENSPACE_MODULE_SPACE___RENDERABLEPLANET___H__ - -#include - -#include -#include -#include - -#include -#include - -namespace ghoul::opengl { - class ProgramObject; - class Texture; -} // namespace ghoul::opengl - -namespace openspace { - -struct TransformData; - -namespace documentation { struct Documentation; } -namespace planetgeometry { class PlanetGeometry; } - -class RenderablePlanet : public Renderable { -public: - // Shadow structure - struct ShadowConfiguration { - std::pair source; - std::pair caster; - }; - - struct ShadowRenderingStruct { - float xu; - float xp; - float rs; - float rc; - glm::vec3 sourceCasterVec; - glm::vec3 casterPositionVec; - bool isShadowing; - }; - - RenderablePlanet(const ghoul::Dictionary& dictionary); - - void initializeGL() override; - void deinitializeGL() override; - bool isReady() const override; - - void render(const RenderData& data, RendererTasks& rendererTask) override; - void update(const UpdateData& data) override; - - static documentation::Documentation Documentation(); - -protected: - void loadTexture(); - -private: - glm::dmat4 computeModelTransformMatrix(const openspace::TransformData& transformData); - - properties::StringProperty _colorTexturePath; - properties::StringProperty _nightTexturePath; - properties::StringProperty _heightMapTexturePath; - - ghoul::opengl::ProgramObject* _programObject = nullptr; - - std::unique_ptr _texture; - std::unique_ptr _nightTexture; - std::unique_ptr _heightMapTexture; - - properties::FloatProperty _heightExaggeration; - - std::unique_ptr _geometry; - properties::BoolProperty _performShading; - - float _alpha = 1.f; - float _planetRadius = 0.f; - bool _hasNightTexture = false; - bool _hasHeightTexture = false; - bool _shadowEnabled = false; - double _time = 0.f; - - glm::dmat3 _stateMatrix; - - std::vector _shadowConfArray; -}; - -} // namespace openspace - -#endif // __OPENSPACE_MODULE_SPACE___RENDERABLEPLANET___H__ diff --git a/modules/space/rendering/renderablestars.cpp b/modules/space/rendering/renderablestars.cpp index 7d18dd0b8f..bf874b6cd0 100644 --- a/modules/space/rendering/renderablestars.cpp +++ b/modules/space/rendering/renderablestars.cpp @@ -467,7 +467,10 @@ void RenderableStars::render(const RenderData& data, RendererTasks&) { glm::vec2(global::renderEngine.renderingResolution()) ); - setPscUniforms(*_program, data.camera, data.position); + _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)); _program->setUniform(_uniformCache.scaling, scaling); ghoul::opengl::TextureUnit psfUnit; diff --git a/modules/space/rendering/simplespheregeometry.cpp b/modules/space/rendering/simplespheregeometry.cpp index d02bd1c493..347752cc3c 100644 --- a/modules/space/rendering/simplespheregeometry.cpp +++ b/modules/space/rendering/simplespheregeometry.cpp @@ -124,7 +124,7 @@ void SimpleSphereGeometry::createSphere() { const glm::vec3 radius = _radius.value(); delete _sphere; - _sphere = new PowerScaledSphere(glm::vec4(radius, 0.0), _segments); + _sphere = new PowerScaledSphere(radius, _segments); _sphere->initialize(); } diff --git a/modules/space/shaders/nighttexture_fs.glsl b/modules/space/shaders/nighttexture_fs.glsl deleted file mode 100644 index dd926efba9..0000000000 --- a/modules/space/shaders/nighttexture_fs.glsl +++ /dev/null @@ -1,76 +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. * - ****************************************************************************************/ - -#include "PowerScaling/powerScaling_fs.hglsl" -#include "fragment.glsl" - -in vec2 vs_st; -in vec2 vs_nightTex; -in vec4 vs_normal; -in vec4 vs_position; -in vec4 vs_gPosition; -in vec3 vs_gNormal; - -uniform vec4 objpos; - -uniform vec3 sun_pos; - -uniform bool _performShading = true; -uniform float transparency; -uniform int shadows; - -uniform float time; -uniform sampler2D texture1; -uniform sampler2D nightTex; - -Fragment getFragment() { - vec4 diffuse = texture(texture1, vs_st); - vec4 diffuse2 = texture(nightTex, vs_st); - - Fragment frag; - if (_performShading) { - vec3 n = normalize(vs_normal.xyz); - vec3 l_pos = sun_pos; // sun - vec3 l_dir = normalize(l_pos - objpos.xyz); - float intensity = min(max(5 * dot(n, l_dir), 0.0), 1.0); - float darkSide = min(max(5 * dot(n, -l_dir), 0.0), 1.0); - - // float shine = 0.0001; - - vec4 ambient = vec4(0.0, 0.0, 0.0, transparency); - - vec4 daytex = max(intensity * diffuse, ambient); - vec4 mixtex = mix(diffuse, diffuse2, (1.0 + dot(n, -l_dir)) / 2.0); - - diffuse = (daytex * 2.0 + mixtex) / 3.0; - } - - frag.color = vec4(diffuse.rgb, transparency); - frag.depth = vs_position.w; - frag.gPosition = vs_gPosition; - frag.gNormal = vec4(vs_gNormal, 1.0); - - return frag; -} - diff --git a/modules/space/shaders/nighttexture_vs.glsl b/modules/space/shaders/nighttexture_vs.glsl deleted file mode 100644 index 3ea0d1e9d8..0000000000 --- a/modules/space/shaders/nighttexture_vs.glsl +++ /dev/null @@ -1,74 +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 "PowerScaling/powerScaling_vs.hglsl" - -layout(location = 0) in vec4 in_position; -layout(location = 1) in vec2 in_st; -layout(location = 2) in vec3 in_normal; - -out vec2 vs_st; -out vec4 vs_normal; -out vec4 vs_position; -out vec4 vs_gPosition; -out vec3 vs_gNormal; - -uniform mat4 ModelTransform; -uniform dmat4 modelViewTransform; -uniform mat4 modelViewProjectionTransform; - -uniform sampler2D heightTex; -uniform bool _hasHeightMap; -uniform float _heightExaggeration; - -void main() { - // set variables - vs_st = in_st; - - // this is wrong for the normal. The normal transform is the transposed inverse of the model transform - vs_normal = normalize(ModelTransform * vec4(in_normal,0)); - // vs_normal = vec4(in_normal, 0.0); - - // G-Buffer - vs_gNormal = in_normal; - - vec4 position = vec4(in_position.xyz * pow(10, in_position.w), 1.0); - - if (_hasHeightMap) { - float height = texture(heightTex, in_st).r; - vec3 displacementDirection = abs(normalize(in_normal.xyz)); - float displacementFactor = height * _heightExaggeration; - position.xyz = position.xyz + displacementDirection * displacementFactor; - } - - // G-Buffer - vs_gPosition = vec4(modelViewTransform * position); // Must be in SGCT eye space - - position = modelViewProjectionTransform * position; - vs_position = z_normalization(position); - - gl_Position = vs_position; -} diff --git a/modules/space/shaders/renderableplanet_fs.glsl b/modules/space/shaders/renderableplanet_fs.glsl deleted file mode 100644 index 0c2d70b3cc..0000000000 --- a/modules/space/shaders/renderableplanet_fs.glsl +++ /dev/null @@ -1,60 +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. * - ****************************************************************************************/ - -#include "fragment.glsl" -#include "PowerScaling/powerScaling_fs.hglsl" - -in vec2 vs_st; -in vec4 vs_normal; -in vec4 vs_position; -in vec4 vs_gPosition; -in vec3 vs_gNormal; - -uniform vec4 objpos; -uniform vec3 sun_pos; -uniform bool _performShading = true; -uniform float transparency; -uniform sampler2D texture1; - -Fragment getFragment() { - vec4 diffuse = texture(texture1, vs_st); - - Fragment frag; - if (_performShading) { - vec4 ambient = vec4(0.0,0.0,0.0,transparency); - vec3 n = normalize(vs_normal.xyz); - vec3 l_pos = vec3(sun_pos); // sun - vec3 l_dir = normalize(l_pos - objpos.xyz); - float intensity = min(max(5.0 * dot(n, l_dir), 0.0), 1.0); - diffuse = max(intensity * diffuse, ambient); - } - - frag.color = vec4(diffuse.rgb, transparency); - frag.depth = vs_position.w; - - frag.gPosition = vs_gPosition; - frag.gNormal = vec4(vs_gNormal, 1.0); - - return frag; -} diff --git a/modules/space/shaders/renderableplanet_vs.glsl b/modules/space/shaders/renderableplanet_vs.glsl deleted file mode 100644 index 2cf37c2eee..0000000000 --- a/modules/space/shaders/renderableplanet_vs.glsl +++ /dev/null @@ -1,74 +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 "PowerScaling/powerScaling_vs.hglsl" - -layout(location = 0) in vec4 in_position; -layout(location = 1) in vec2 in_st; -layout(location = 2) in vec3 in_normal; - -out vec2 vs_st; -out vec4 vs_normal; -out vec4 vs_position; -out vec4 vs_gPosition; -out vec3 vs_gNormal; - -uniform mat4 ModelTransform; -uniform dmat4 modelViewTransform; -uniform mat4 modelViewProjectionTransform; - -uniform sampler2D heightTex; -uniform bool _hasHeightMap; -uniform float _heightExaggeration; - -void main() { - vs_st = in_st; - - // G-Buffer - vs_gNormal = in_normal; - - // this is wrong for the normal. The normal transform is the transposed inverse of the model transform - vs_normal = normalize(ModelTransform * vec4(in_normal,0)); - // vs_normal = vec4(in_normal, 0.0); - - vec4 position = vec4(in_position.xyz * pow(10, in_position.w), 1.0); - - if (_hasHeightMap) { - float height = texture(heightTex, in_st).r; - vec3 displacementDirection = abs(normalize(in_normal.xyz)); - float displacementFactor = height * _heightExaggeration; - position.xyz = position.xyz + displacementDirection * displacementFactor; - } - - // G-Buffer - vs_gPosition = vec4(modelViewTransform * position); // Must be in SGCT eye space; - - position = modelViewProjectionTransform * position; - - vs_position = z_normalization(position); - - gl_Position = vs_position; -} diff --git a/modules/space/shaders/shadow_fs.glsl b/modules/space/shaders/shadow_fs.glsl deleted file mode 100644 index ffdc877ad7..0000000000 --- a/modules/space/shaders/shadow_fs.glsl +++ /dev/null @@ -1,118 +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. * - ****************************************************************************************/ - -#include "PowerScaling/powerScaling_fs.hglsl" -#include "fragment.glsl" - -in vec2 vs_st; -in vec4 vs_normal; -in vec4 vs_position; -in vec4 vs_posWorld; -in vec4 vs_gPosition; -in vec3 vs_gNormal; - -const uint numberOfShadows = 1; - -struct ShadowRenderingStruct { - float xu, xp; - float rs, rc; - vec3 sourceCasterVec; - vec3 casterPositionVec; - bool isShadowing; -}; - -uniform ShadowRenderingStruct shadowDataArray[numberOfShadows]; - -uniform vec4 objpos; - -uniform vec3 sun_pos; - -uniform bool _performShading = true; -uniform float transparency; - -uniform sampler2D texture1; - -vec4 butterworthFunc(const float d, const float r, const float n) { - return vec4(vec3(sqrt(r / (r + pow(d, 2 * n)))), 1.0); -} - -vec4 calcShadow(ShadowRenderingStruct shadowInfoArray[numberOfShadows], vec3 position) { - if (shadowInfoArray[0].isShadowing) { - vec3 pc = shadowInfoArray[0].casterPositionVec - position; - // we can pass this normalized to the shader - vec3 sc_norm = normalize(shadowInfoArray[0].sourceCasterVec); - vec3 pc_proj = dot(pc, sc_norm) * sc_norm; - vec3 d = pc - pc_proj; - - float length_d = length(d); - float length_pc_proj = length(pc_proj); - - float r_p_pi = shadowInfoArray[0].rc * (length_pc_proj + shadowInfoArray[0].xp) / shadowInfoArray[0].xp; - - //float r_u_pi = shadowInfoArray[0].rc * (length_pc_proj + shadowInfoArray[0].xu) / shadowInfoArray[0].xu; - float r_u_pi = shadowInfoArray[0].rc * (shadowInfoArray[0].xu - length_pc_proj) / shadowInfoArray[0].xu; - - if (length_d < r_u_pi) { // umbra - //return vec4(0.0, 0.0, 0.0, 1.0); - //return vec4(1.0, 0.0, 0.0, 1.0); - return butterworthFunc(length_d, r_u_pi, 4.0); - } - else if (length_d < r_p_pi) {// penumbra - //return vec4(0.5, 0.5, 0.5, 1.0); - //return vec4(0.0, 1.0, 0.0, 1.0); - return vec4(vec3(length_d/r_p_pi), 1.0); - } - } - - return vec4(1.0); -} - -Fragment getFragment() { - vec4 position = vs_position; - float depth = pscDepth(position); - vec4 diffuse = texture(texture1, vs_st); - - Fragment frag; - if (_performShading) { - // directional lighting - vec3 n = normalize(vs_normal.xyz); - vec3 l_pos = vec3(sun_pos); // sun - vec3 l_dir = normalize(l_pos - objpos.xyz); - float intensity = min(max(5.0 * dot(n, l_dir), 0.0), 1.0); - float darkSide = min(max(5.0 * dot(n, -l_dir), 0.0), 1.0); - - vec4 ambient = vec4(0.0, 0.0, 0.0, transparency); - vec4 daytex = max(intensity * diffuse, ambient); - - diffuse = daytex * calcShadow(shadowDataArray, vs_posWorld.xyz); - } - - frag.color = vec4(diffuse.rgb, transparency); - frag.depth = depth; - - frag.gPosition = vs_gPosition; - frag.gNormal = vec4(vs_gNormal, 1.0); - - return frag; -} diff --git a/modules/space/shaders/shadow_nighttexture_fs.glsl b/modules/space/shaders/shadow_nighttexture_fs.glsl deleted file mode 100644 index 8155c8c8d4..0000000000 --- a/modules/space/shaders/shadow_nighttexture_fs.glsl +++ /dev/null @@ -1,125 +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. * - ****************************************************************************************/ - -#include "PowerScaling/powerScaling_fs.hglsl" -#include "fragment.glsl" - -in vec2 vs_st; -in vec2 vs_nightTex; -in vec4 vs_normal; -in vec4 vs_position; -in vec4 vs_posWorld; -in vec4 vs_gPosition; -in vec3 vs_gNormal; - -const uint numberOfShadows = 1; - -struct ShadowRenderingStruct { - float xu, xp; - float rs, rc; - vec3 sourceCasterVec; - vec3 casterPositionVec; - bool isShadowing; -}; - -uniform ShadowRenderingStruct shadowDataArray[numberOfShadows]; - -uniform vec4 campos; -uniform vec4 objpos; - -uniform vec3 sun_pos; - -uniform bool _performShading = true; -uniform float transparency; -uniform int shadows; - -uniform float time; -uniform sampler2D texture1; -uniform sampler2D nightTex; - -vec4 butterworthFunc(const float d, const float r, const float n) { - return vec4(vec3(sqrt(r/(r + pow(d, 2*n)))), 1.0); -} - -vec4 calcShadow(ShadowRenderingStruct shadowInfoArray[numberOfShadows], vec3 position) { - if (shadowInfoArray[0].isShadowing) { - vec3 pc = shadowInfoArray[0].casterPositionVec - position; - // we can pass this normalized to the shader - vec3 sc_norm = normalize(shadowInfoArray[0].sourceCasterVec); - vec3 pc_proj = dot(pc, sc_norm) * sc_norm; - vec3 d = pc - pc_proj; - - float length_d = length(d); - float length_pc_proj = length(pc_proj); - - float r_p_pi = shadowInfoArray[0].rc * (length_pc_proj + shadowInfoArray[0].xp) / shadowInfoArray[0].xp; - - //float r_u_pi = shadowInfoArray[0].rc * (length_pc_proj + shadowInfoArray[0].xu) / shadowInfoArray[0].xu; - float r_u_pi = shadowInfoArray[0].rc * (shadowInfoArray[0].xu - length_pc_proj) / shadowInfoArray[0].xu; - - if ( length_d < r_u_pi ) { // umbra - //return vec4(0.0, 0.0, 0.0, 1.0); - //return vec4(1.0, 0.0, 0.0, 1.0); - return butterworthFunc(length_d, r_u_pi, 4.0); - } - else if ( length_d < r_p_pi ) {// penumbra - //return vec4(0.5, 0.5, 0.5, 1.0); - //return vec4(0.0, 1.0, 0.0, 1.0); - return vec4(vec3(length_d/r_p_pi), 1.0); - } - } - - return vec4(1.0); -} - -Fragment getFragment() { - vec4 position = vs_position; - float depth = pscDepth(position); - vec4 diffuse = texture(texture1, vs_st); - vec4 diffuse2 = texture(nightTex, vs_st); - - Fragment frag; - if (_performShading) { - vec3 n = normalize(vs_normal.xyz); - vec3 l_pos = vec3(sun_pos); // sun. - vec3 l_dir = normalize(l_pos - objpos.xyz); - float intensity = min(max(5.0 * dot(n, l_dir), 0.0), 1.0); - float darkSide = min(max(5.0 * dot(n, -l_dir), 0.0), 1.0); - - vec4 ambient = vec4(0.0, 0.0, 0.0, transparency); - - vec4 daytex = max(intensity * diffuse, ambient); - vec4 mixtex = mix(diffuse, diffuse2, (1.0 + dot(n, -l_dir)) / 2.0); - - diffuse = ((daytex*2 + mixtex) / 3) * calcShadow(shadowDataArray, vs_posWorld.xyz); - } - - frag.color = vec4(diffuse.rgb, transparency); - frag.depth = depth; - - frag.gPosition = vs_gPosition; - frag.gNormal = vec4(vs_gNormal, 1.0); - - return frag; -} diff --git a/modules/space/shaders/shadow_nighttexture_vs.glsl b/modules/space/shaders/shadow_nighttexture_vs.glsl deleted file mode 100644 index f191378e68..0000000000 --- a/modules/space/shaders/shadow_nighttexture_vs.glsl +++ /dev/null @@ -1,73 +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 "PowerScaling/powerScaling_vs.hglsl" - -layout(location = 0) in vec4 in_position; -layout(location = 1) in vec2 in_st; -layout(location = 2) in vec3 in_normal; - -out vec2 vs_st; -out vec4 vs_normal; -out vec4 vs_position; -out vec4 vs_posWorld; -out vec4 vs_gPosition; -out vec3 vs_gNormal; - -uniform mat4 ViewProjection; -uniform mat4 ModelTransform; - - -void main() { - vs_st = in_st; - vs_position = in_position; - vec4 tmp = in_position; - - // this is wrong for the normal. The normal transform is the transposed inverse of the model transform - vs_normal = normalize(ModelTransform * vec4(in_normal,0)); - - // G-Buffer - vs_gNormal = in_normal; - - // The tmp is now in the OS eye space (camera rig space) - // and wrtitten using PSC coords. - // position is in the same space, i.e., OS eye space but - // in meters (no PSC coords). - vec4 position = pscTransform(tmp, ModelTransform); - - // G-Buffer - vs_gPosition = position; - - vec3 local_vertex_pos = mat3(ModelTransform) * in_position.xyz; - vec4 vP = psc_addition(vec4(local_vertex_pos, in_position.w), objpos); - vs_posWorld = vec4(vP.xyz * pow(10, vP.w), 1.0); - - vs_position = tmp; - // Now is transforming from view position to SGCT projection - // coordinates. - position = ViewProjection * position; - gl_Position = z_normalization(position); -} diff --git a/modules/space/shaders/shadow_vs.glsl b/modules/space/shaders/shadow_vs.glsl deleted file mode 100644 index e26e9e3514..0000000000 --- a/modules/space/shaders/shadow_vs.glsl +++ /dev/null @@ -1,85 +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 "PowerScaling/powerScaling_vs.hglsl" - -layout(location = 0) in vec4 in_position; -layout(location = 1) in vec2 in_st; -layout(location = 2) in vec3 in_normal; - -uniform mat4 ViewProjection; -uniform mat4 ModelTransform; -uniform bool _hasHeightMap; -uniform float _heightExaggeration; -uniform sampler2D heightTex; - -out vec2 vs_st; -out vec4 vs_normal; -out vec4 vs_position; -out vec4 vs_posWorld; -out float s; -out vec4 vs_gPosition; -out vec3 vs_gNormal; - -void main() { - // set variables - vs_st = in_st; - vs_position = in_position; - vec4 tmp = in_position; - - // this is wrong for the normal. The normal transform is the transposed inverse of the model transform - vs_normal = normalize(ModelTransform * vec4(in_normal,0)); - - // We are using the normal in Object (model) space in G-Buffer (because of atm). - vs_gNormal = in_normal; - - // The tmp is now in the OS eye space (camera rig space) - // and wrtitten using PSC coords. - // position is in the same space, i.e., OS eye space but - // in meters (no PSC coords). - vec4 position = pscTransform(tmp, ModelTransform); - - // G-Buffer - vs_gPosition = position; - - vec3 local_vertex_pos = mat3(ModelTransform) * in_position.xyz; - vec4 vP = psc_addition(vec4(local_vertex_pos,in_position.w),objpos); - vs_posWorld = vec4(vP.xyz * pow(10,vP.w), 1.0); - - vs_position = tmp; - - if (_hasHeightMap) { - float height = texture(heightTex, in_st).r; - vec3 displacementDirection = abs(normalize(in_normal.xyz)); - float displacementFactor = height * _heightExaggeration; - position.xyz = position.xyz + displacementDirection * displacementFactor; - } - - // Now is transforming from view position to SGCT projection - // coordinates. - position = ViewProjection * position; - gl_Position = z_normalization(position); -} diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index bf95c08672..6152a79650 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include #include @@ -77,7 +76,7 @@ void SpaceModule::internalInitialize(const ghoul::Dictionary&) { fRenderable->registerClass( "RenderableConstellationBounds" ); - fRenderable->registerClass("RenderablePlanet"); + fRenderable->registerClass("RenderableRings"); fRenderable->registerClass("RenderableStars"); @@ -106,7 +105,6 @@ void SpaceModule::internalDeinitializeGL() { std::vector SpaceModule::documentations() const { return { RenderableConstellationBounds::Documentation(), - RenderablePlanet::Documentation(), RenderableRings::Documentation(), RenderableStars::Documentation(), SpiceRotation::Documentation(), diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index dc306d2a76..8dba28ee8d 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -377,8 +377,7 @@ void RenderableModelProjection::update(const UpdateData& data) { global::renderEngine.scene()->sceneGraphNode("Sun")->worldPosition() - data.modelTransform.translation; - _sunPosition = - PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z).vec3(); + _sunPosition = static_cast(p); } void RenderableModelProjection::imageProjectGPU( diff --git a/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp b/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp index a3c3b06053..f73ba033d8 100644 --- a/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp @@ -512,20 +512,7 @@ void RenderablePlanetProjection::attitudeParameters(double time) { _projectionComponent.instrumentId(), _mainFrame, time ); - _transform = glm::mat4(1); - //90 deg rotation w.r.t spice req. - glm::mat4 rot = glm::rotate( - _transform, - glm::half_pi(), - glm::vec3(1, 0, 0) - ); - glm::mat4 roty = glm::rotate( - _transform, - glm::half_pi(), - glm::vec3(0, -1, 0) - ); - - _transform = glm::mat4(_stateMatrix) * rot * roty; + _transform = glm::mat4(_stateMatrix); glm::dvec3 bs; try { @@ -547,19 +534,12 @@ void RenderablePlanetProjection::attitudeParameters(double time) { _projectionComponent.aberration(), time, lightTime - ); - psc position = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z); + ) * 1000.0; - //change to KM and add psc camera scaling. - position[3] += (3 + _camScaling[1]); - //position[3] += 3; - glm::vec3 cpos = position.vec3(); - - float distance = glm::length(cpos); + float distance = glm::length(p); float radius = boundingSphere(); - _projectorMatrix = _projectionComponent.computeProjectorMatrix( - cpos, + p, bs, _up, _instrumentMatrix, @@ -610,8 +590,8 @@ void RenderablePlanetProjection::render(const RenderData& data, RendererTasks&) } attitudeParameters(data.time.j2000Seconds()); - double lt; - glm::dvec3 p = SpiceManager::ref().targetPosition( + double lt; + glm::dvec3 sunPos = SpiceManager::ref().targetPosition( "SUN", _projectionComponent.projecteeId(), "GALACTIC", @@ -619,13 +599,10 @@ void RenderablePlanetProjection::render(const RenderData& data, RendererTasks&) data.time.j2000Seconds(), lt ); - psc sun_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z); // Main renderpass _programObject->activate(); - _programObject->setUniform(_mainUniformCache.sunPos, sun_pos.vec3()); - //_program->setUniform("ViewProjection" , data.camera.viewProjectionMatrix()); - //_program->setUniform("ModelTransform" , _transform); + _programObject->setUniform(_mainUniformCache.sunPos, static_cast(sunPos)); // Model transform and view transform needs to be in double precision glm::dmat4 modelTransform = @@ -633,24 +610,6 @@ void RenderablePlanetProjection::render(const RenderData& data, RendererTasks&) glm::dmat4(data.modelTransform.rotation) * // Spice rotation glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); - // This is apparently the transform needed to get the model in the coordinate system - // Used by SPICE. Don't ask me why, it was defined in the function attitudeParameters. - // SPICE needs a planet to be defined with z in the north pole, x in the prime - // meridian and y completes the right handed coordinate system. - // Doing this is part of changing from using the transforms defined by the - // scenegraph node (data.modelTransform) to achieve higher precision rendering. //KB - glm::dmat4 rot = glm::rotate( - glm::dmat4(1.0), - glm::half_pi(), - glm::dvec3(1.0, 0.0, 0.0) - ); - glm::dmat4 roty = glm::rotate( - glm::dmat4(1.0), - glm::half_pi(), - glm::dvec3(0.0, -1.0, 0.0) - ); - modelTransform = modelTransform * rot * roty; - glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; _programObject->setUniform( @@ -765,9 +724,7 @@ void RenderablePlanetProjection::clearProjectionBufferAfterTime(double time) { const auto& it = std::find_if( _imageTimes.begin(), _imageTimes.end(), - [time](const Image& image) { - return image.timeRange.end > time; - } + [time](const Image& image) { return image.timeRange.end > time; } ); if (it != _imageTimes.end()) { _imageTimes.erase(it, _imageTimes.end()); @@ -783,7 +740,6 @@ void RenderablePlanetProjection::insertImageProjections(const std::vector _projectionsInBuffer = static_cast(_imageTimes.size()); } - void RenderablePlanetProjection::loadColorTexture() { using ghoul::opengl::Texture; std::string selectedPath = _colorTexturePaths.option().description; diff --git a/modules/spacecraftinstruments/rendering/renderableshadowcylinder.cpp b/modules/spacecraftinstruments/rendering/renderableshadowcylinder.cpp index ad61c96356..d521c7bc5a 100644 --- a/modules/spacecraftinstruments/rendering/renderableshadowcylinder.cpp +++ b/modules/spacecraftinstruments/rendering/renderableshadowcylinder.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -106,19 +105,6 @@ namespace { "This value determines the aberration method that is used to compute the shadow " "cylinder." }; - - glm::vec4 psc_addition(glm::vec4 v1, glm::vec4 v2) { - const float k = 10.f; - const float ds = v2.w - v1.w; - if (ds >= 0) { - float p = pow(k, -ds); - return glm::vec4(v1.x*p + v2.x, v1.y*p + v2.y, v1.z*p + v2.z, v2.w); - } - else { - float p = pow(k, ds); - return glm::vec4(v1.x + v2.x*p, v1.y + v2.y*p, v1.z + v2.z*p, v1.w); - } - } } // namespace namespace openspace { @@ -374,15 +360,13 @@ void RenderableShadowCylinder::createCylinder(double time) { _numberOfPoints ); - std::vector terminatorPoints; + std::vector terminatorPoints; std::transform( res.terminatorPoints.begin(), res.terminatorPoints.end(), std::back_inserter(terminatorPoints), [](const glm::dvec3& p) { - psc coord = PowerScaledCoordinate::CreatePowerScaledCoordinate(p.x, p.y, p.z); - coord[3] += 3; - return coord; + return p * 1000.0; } ); @@ -404,15 +388,10 @@ void RenderableShadowCylinder::createCylinder(double time) { vecLightSource *= _shadowLength; _vertices.clear(); - const psc endpoint = psc::CreatePowerScaledCoordinate( - vecLightSource.x, - vecLightSource.y, - vecLightSource.z - ); - for (const psc& v : terminatorPoints) { - _vertices.push_back({ v[0], v[1], v[2], v[3] }); - glm::vec4 f = psc_addition(v.vec4(), endpoint.vec4()); - _vertices.push_back({ f[0], f[1], f[2], f[3] }); + for (const glm::vec3& v : terminatorPoints) { + _vertices.push_back({ v[0], v[1], v[2], 0.f }); + glm::vec3 f = v + glm::vec3(vecLightSource); + _vertices.push_back({ f[0], f[1], f[2], 0.f }); } _vertices.push_back(_vertices[0]); _vertices.push_back(_vertices[1]); diff --git a/modules/spacecraftinstruments/shaders/renderablePlanetProjection_fs.glsl b/modules/spacecraftinstruments/shaders/renderablePlanetProjection_fs.glsl index c3513ad40a..311e4f52c1 100644 --- a/modules/spacecraftinstruments/shaders/renderablePlanetProjection_fs.glsl +++ b/modules/spacecraftinstruments/shaders/renderablePlanetProjection_fs.glsl @@ -51,9 +51,9 @@ vec4 uvToModel(vec2 uv, vec3 radius, float segments){ float theta = fi * float(M_PI) / segments; // 0 -> PI float phi = fj * float(M_PI) * 2.0f / segments; - float x = radius[0] * sin(phi) * sin(theta); // - float y = radius[1] * cos(theta); // up - float z = radius[2] * cos(phi) * sin(theta); // + float x = radius[0] * sin(theta) * cos(phi); + float y = radius[1] * sin(theta) * sin(phi); + float z = radius[2] * cos(theta); return vec4(x, y, z, 0.0); } diff --git a/modules/spacecraftinstruments/shaders/renderablePlanet_fs.glsl b/modules/spacecraftinstruments/shaders/renderablePlanet_fs.glsl index e5e384d88b..fbfb89f52f 100644 --- a/modules/spacecraftinstruments/shaders/renderablePlanet_fs.glsl +++ b/modules/spacecraftinstruments/shaders/renderablePlanet_fs.glsl @@ -53,7 +53,6 @@ Fragment getFragment() { vec3 l_pos = sun_pos; // sun vec3 l_dir = normalize(l_pos - objpos.xyz); float intensity = min(max(5 * dot(n,l_dir), _ambientBrightness), 1); - // float shine = 0.0001; vec4 ambient = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/modules/spacecraftinstruments/shaders/renderablePlanet_vs.glsl b/modules/spacecraftinstruments/shaders/renderablePlanet_vs.glsl index 656a7c77c7..da05c6e9fa 100644 --- a/modules/spacecraftinstruments/shaders/renderablePlanet_vs.glsl +++ b/modules/spacecraftinstruments/shaders/renderablePlanet_vs.glsl @@ -52,7 +52,6 @@ void main() { // The normal transform is the transposed inverse of the model transform vs_normal = normalize(modelTransform * vec4(in_normal,0)); - if (_hasHeightMap) { vec2 st = vs_st; if (_meridianShift) { @@ -65,7 +64,7 @@ void main() { } // convert from psc to homogeneous coordinates - vec4 position = vec4(tmp.xyz * pow(10, tmp.w), 1); + vec4 position = vec4(tmp.xyz, 1); vec4 positionClipSpace = modelViewProjectionTransform * position; vs_positionScreenSpace = z_normalization(positionClipSpace); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7111bb5554..7f62468718 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -176,7 +176,6 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/util/keys.cpp ${OPENSPACE_BASE_DIR}/src/util/openspacemodule.cpp ${OPENSPACE_BASE_DIR}/src/util/powerscaledcoordinate.cpp - ${OPENSPACE_BASE_DIR}/src/util/powerscaledscalar.cpp ${OPENSPACE_BASE_DIR}/src/util/powerscaledsphere.cpp ${OPENSPACE_BASE_DIR}/src/util/progressbar.cpp ${OPENSPACE_BASE_DIR}/src/util/resourcesynchronization.cpp @@ -369,7 +368,6 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/util/mouse.h ${OPENSPACE_BASE_DIR}/include/openspace/util/openspacemodule.h ${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledcoordinate.h - ${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledscalar.h ${OPENSPACE_BASE_DIR}/include/openspace/util/powerscaledsphere.h ${OPENSPACE_BASE_DIR}/include/openspace/util/progressbar.h ${OPENSPACE_BASE_DIR}/include/openspace/util/resourcesynchronization.h diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index d3392bb292..669aa4f82d 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -950,7 +950,6 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac RenderData data = { *camera, - psc(), std::move(time), doPerformanceMeasurements, 0, diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index f9a67dbda3..cc1e12fac0 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -161,16 +161,6 @@ SurfacePositionHandle Renderable::calculateSurfacePositionHandle( }; } -void Renderable::setPscUniforms(ghoul::opengl::ProgramObject& program, - const Camera& camera, - const PowerScaledCoordinate& position) -{ - program.setUniform("campos", glm::vec4(camera.positionVec3(), 1.f)); - program.setUniform("objpos", position.vec4()); - program.setUniform("camrot", glm::mat4(camera.viewRotationMatrix())); - program.setUniform("scaling", glm::vec2(1.f, 0.f)); -} - Renderable::RenderBin Renderable::renderBin() const { return _renderBin; } diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index b4cfc710c7..8fce29ad62 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -421,15 +421,9 @@ void SceneGraphNode::render(const RenderData& data, RendererTasks& tasks) { if (_state != State::GLInitialized) { return; } - const psc thisPositionPSC = psc::CreatePowerScaledCoordinate( - _worldPositionCached.x, - _worldPositionCached.y, - _worldPositionCached.z - ); RenderData newData = { data.camera, - thisPositionPSC, data.time, data.doPerformanceMeasurement, data.renderBinMask, @@ -765,39 +759,6 @@ Renderable* SceneGraphNode::renderable() { return _renderable.get(); } -/* -bool SceneGraphNode::sphereInsideFrustum(const psc& s_pos, const PowerScaledScalar& s_rad, - const Camera* camera) -{ - // direction the camera is looking at in power scale - psc psc_camdir = psc(glm::vec3(camera->viewDirectionWorldSpace())); - - // the position of the camera, moved backwards in the view direction to encapsulate - // the sphere radius - psc U = camera->position() - psc_camdir * s_rad * (1.0 / camera->sinMaxFov()); - - // the vector to the object from the new position - psc D = s_pos - U; - - const double a = psc_camdir.angle(D); - if (a < camera->maxFov()) { - // center is inside K'' - D = s_pos - camera->position(); - if (D.length() * psc_camdir.length() * camera->sinMaxFov() - <= -psc_camdir.dot(D)) { - // center is inside K'' and inside K' - return D.length() <= s_rad; - } else { - // center is inside K'' and outside K' - return true; - } - } else { - // outside the maximum angle - return false; - } -} -*/ - SceneGraphNode* SceneGraphNode::childNode(const std::string& identifier) { if (this->identifier() == identifier) { return this; diff --git a/src/util/powerscaledcoordinate.cpp b/src/util/powerscaledcoordinate.cpp index 9c5ac81d0c..e5d1f5df75 100644 --- a/src/util/powerscaledcoordinate.cpp +++ b/src/util/powerscaledcoordinate.cpp @@ -24,7 +24,6 @@ #include -#include #include #include @@ -110,9 +109,9 @@ glm::dvec3 PowerScaledCoordinate::dvec3() const static_cast(_vec[2]) * p); } -PowerScaledScalar PowerScaledCoordinate::length() const +float PowerScaledCoordinate::length() const { - return PowerScaledScalar(glm::length(glm::vec3(_vec[0], _vec[1], _vec[2])), _vec[3]); + return glm::length(glm::vec3(_vec[0], _vec[1], _vec[2])) * std::pow(10, _vec[3]); } glm::vec3 PowerScaledCoordinate::direction() const @@ -212,30 +211,6 @@ PowerScaledCoordinate PowerScaledCoordinate::operator*(const float& rhs) const return PowerScaledCoordinate(_vec[0] * rhs, _vec[1] * rhs, _vec[2] * rhs, _vec[3]); } -PowerScaledCoordinate& PowerScaledCoordinate::operator*=(const PowerScaledScalar& rhs) -{ - double ds = this->_vec[3] - rhs._data[1]; - if (ds >= 0.0) { - double p = pow(k, -ds); - *this = PowerScaledCoordinate( - static_cast(rhs._data[0] * p * _vec[0]), - static_cast(rhs._data[0] * p * _vec[1]), - static_cast(rhs._data[0] * p * _vec[2]), this->_vec[3] + _vec[3]); - } else { - double p = pow(k, ds); - *this = PowerScaledCoordinate( - static_cast(rhs._data[0] * _vec[0] * p), - static_cast(rhs._data[0] * _vec[1] * p), - static_cast(rhs._data[0] * _vec[2] * p), rhs._data[1] + rhs._data[1]); - } - return *this; -} - -PowerScaledCoordinate PowerScaledCoordinate::operator*(const PowerScaledScalar& rhs) const -{ - return PowerScaledCoordinate(*this) *= rhs; -} - PowerScaledCoordinate PowerScaledCoordinate::operator*(const glm::mat4& matrix) const { return matrix * _vec; diff --git a/src/util/powerscaledscalar.cpp b/src/util/powerscaledscalar.cpp deleted file mode 100644 index 7aa766b485..0000000000 --- a/src/util/powerscaledscalar.cpp +++ /dev/null @@ -1,268 +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. * - ****************************************************************************************/ - -#include - -#include -#include - -namespace { - constexpr const double k = 10.0; -} // namespace - -namespace openspace { - -PowerScaledScalar::PowerScaledScalar(const glm::vec2& v) { - _data = std::move(v); -} - -PowerScaledScalar::PowerScaledScalar(float f1, float f2) { - _data = glm::vec2(f1, f2); -} - -PowerScaledScalar PowerScaledScalar::CreatePSS(double d1) { - char buff[30]; - - // find the number with maximum number of digits - double ad1 = std::abs(d1); - - // find out how many digits -#ifdef _MSC_VER - sprintf_s(buff, 30, "%.0f", ad1); -#else - sprintf(buff, "%.0f", ad1); -#endif - size_t digits = strlen(buff) - 1; - - // rescale and return - double tp = 1.0 / pow(k, digits); - return PowerScaledScalar(static_cast(d1 * tp), static_cast(digits)); -} - -const glm::vec2& PowerScaledScalar::vec2() const { - return _data; -} - -float PowerScaledScalar::lengthf() const { - return static_cast(_data.x * pow(k, _data.y)); -} - -double PowerScaledScalar::lengthd() const { - return _data.x * pow(k, _data.y); -} - -PowerScaledScalar& PowerScaledScalar::operator=(const PowerScaledScalar& rhs) { - if (this != &rhs) { - _data = rhs._data; - } - return *this; -} - -PowerScaledScalar& PowerScaledScalar::operator=(const glm::vec2& rhs) { - _data = rhs; - return *this; -} - -PowerScaledScalar& PowerScaledScalar::operator=(float rhs) { - _data = glm::vec2(rhs, 0.f); - return *this; // Return a reference to myself. -} - -PowerScaledScalar& PowerScaledScalar::operator+=(const PowerScaledScalar& rhs) { - const double ds = _data.y - rhs._data.y; - if (ds >= 0.0) { - *this = PowerScaledScalar( - static_cast(rhs._data.x * pow(k, -ds) + _data.x), - _data.y - ); - } else { - *this = PowerScaledScalar( - static_cast(rhs._data.x + _data.x * pow(k, ds)), - rhs._data.y - ); - } - - return *this; -} - -const PowerScaledScalar& PowerScaledScalar::operator+(const PowerScaledScalar& rhs) const -{ - return PowerScaledScalar(*this) += rhs; -} - -PowerScaledScalar& PowerScaledScalar::operator-=(const PowerScaledScalar& rhs) { - - const double ds = _data.y - rhs._data.y; - if (ds >= 0.0) { - *this = PowerScaledScalar( - static_cast(-rhs._data.x * pow(k, -ds) + _data.x), - this->_data.y - ); - } else { - *this = PowerScaledScalar( - static_cast(-rhs._data.x + _data.x * pow(k, ds)), - rhs._data.y - ); - } - - return *this; -} - -const PowerScaledScalar& PowerScaledScalar::operator-(const PowerScaledScalar& rhs) const -{ - return PowerScaledScalar(*this) -= rhs; -} - -PowerScaledScalar& PowerScaledScalar::operator*=(const PowerScaledScalar& rhs) { - const double ds = _data.y - rhs._data.y; - if (ds >= 0.0) { - *this = PowerScaledScalar( - static_cast(rhs._data.x * pow(k, -ds) * _data.x), - _data.y + _data.y - ); - } else { - *this = PowerScaledScalar( - static_cast(rhs._data.x * _data.x * pow(k, ds)), - rhs._data.y + rhs._data.y - ); - } - - return *this; -} - -const PowerScaledScalar& PowerScaledScalar::operator*(const PowerScaledScalar& rhs) const -{ - return PowerScaledScalar(*this) *= rhs; -} - -PowerScaledScalar & PowerScaledScalar::operator*=(float rhs) { - const double ds = _data.y; - if (ds >= 0.0) { - *this = PowerScaledScalar( - static_cast(rhs * pow(k, -ds) * _data.x), - _data.y + _data.y - ); - } else { - *this = PowerScaledScalar( - static_cast(rhs * _data.x * pow(k, ds)), - 0.f - ); - } - - return *this; -} - -const PowerScaledScalar& PowerScaledScalar::operator*(float rhs) const { - return PowerScaledScalar(*this) *= rhs; -} - -float& PowerScaledScalar::operator[](unsigned int idx) { - return _data[idx]; -} - -float PowerScaledScalar::operator[](unsigned int idx) const { - return _data[idx]; -} - -bool PowerScaledScalar::operator==(const PowerScaledScalar& other) const { - return _data == other._data; -} - -bool PowerScaledScalar::operator<(const PowerScaledScalar& other) const { - const double ds = _data.y - other._data.y; - if (ds >= 0.0) { - const double upscaled = other._data.x * pow(k, -ds); - return _data.x < upscaled; - } else { - const double upscaled = _data.x * pow(k, -ds); - return other._data.x > upscaled; - } -} - -bool PowerScaledScalar::operator>(const PowerScaledScalar& other) const { - const double ds = _data.y - other._data.y; - if (ds >= 0.0) { - const double upscaled = other._data.x * pow(k, -ds); - return _data.x > upscaled; - } else { - const double upscaled = _data.x * pow(k, -ds); - return other._data.x < upscaled; - } -} - -bool PowerScaledScalar::operator<=(const PowerScaledScalar& other) const { - return *this < other || *this == other; -} - -bool PowerScaledScalar::operator>=(const PowerScaledScalar& other) const { - return *this > other || *this == other; -} - -bool PowerScaledScalar::operator==(double other) const { - const double ds = _data.y; - if (ds >= 0.0) { - const double upscaled = other * pow(k, -ds); - return _data.x == upscaled; - } else { - const double upscaled = _data.x * pow(k, -ds); - return other == upscaled; - } -} - -bool PowerScaledScalar::operator<(double other) const { - const double ds = _data.y; - if (ds >= 0.0) { - const double upscaled = other * pow(k, -ds); - return _data.x < upscaled; - } else { - const double upscaled = _data.x * pow(k, -ds); - return other > upscaled; - } -} - -bool PowerScaledScalar::operator>(double other) const { - const double ds = _data.y; - if (ds >= 0.0) { - const double upscaled = other * pow(k, -ds); - return _data.x > upscaled; - } else { - const double upscaled = _data.x * pow(k, -ds); - return other < upscaled; - } -} - -bool PowerScaledScalar::operator<=(double other) const { - return *this < other || *this == other; -} - -bool PowerScaledScalar::operator>=(double other) const { - return *this > other || *this == other; -} - -std::ostream& operator<<(::std::ostream& os, const PowerScaledScalar& rhs) { - os << "(" << rhs[0] << ", " << rhs[1] << ")"; - return os; -} - -} // namespace openspace diff --git a/src/util/powerscaledsphere.cpp b/src/util/powerscaledsphere.cpp index 09ffc11f24..25319ddba1 100644 --- a/src/util/powerscaledsphere.cpp +++ b/src/util/powerscaledsphere.cpp @@ -25,7 +25,6 @@ #include #include -#include #include #include @@ -35,89 +34,9 @@ namespace { namespace openspace { -PowerScaledSphere::PowerScaledSphere(const PowerScaledScalar& radius, int segments) - : _isize(6 * segments * segments) - , _vsize((segments + 1) * (segments + 1)) - , _varray(new Vertex[_vsize]) - , _iarray(new int[_isize]) -{ - int nr = 0; - const float fsegments = static_cast(segments); - const float r = radius[0]; - - for (int i = 0; i <= segments; i++) { - // define an extra vertex around the y-axis due to texture mapping - for (int j = 0; j <= segments; j++) { - const float fi = static_cast(i); - const float fj = static_cast(j); - // inclination angle (north to south) - const float theta = fi * glm::pi() / fsegments; // 0 -> PI - - // azimuth angle (east to west) - const float phi = fj * glm::pi() * 2.f / fsegments; // 0 -> 2*PI - - const float x = r * sin(phi) * sin(theta); // - const float y = r * cos(theta); // up - const float z = r * cos(phi) * sin(theta); // - - glm::vec3 normal = glm::vec3(x, y, z); - if (!(x == 0.f && y == 0.f && z == 0.f)) { - normal = glm::normalize(normal); - } - - const float t1 = (fj / fsegments); - const float t2 = 1.f - (fi / fsegments); - - //double tp = 1.0 / pow(10, static_cast(radius[1])); - - _varray[nr].location[0] = x; - _varray[nr].location[1] = y; - _varray[nr].location[2] = z; - _varray[nr].location[3] = radius[1]; - _varray[nr].normal[0] = normal[0]; - _varray[nr].normal[1] = normal[1]; - _varray[nr].normal[2] = normal[2]; - - _varray[nr].tex[0] = t1; - _varray[nr].tex[1] = t2; - ++nr; - } - } - - nr = 0; - // define indices for all triangles - for (int i = 1; i <= segments; ++i) { - for (int j = 0; j < segments; ++j) { - const int t = segments + 1; - _iarray[nr] = t * (i - 1) + j + 0; //1 - ++nr; - _iarray[nr] = t * (i + 0) + j + 0; //2 - ++nr; - _iarray[nr] = t * (i + 0) + j + 1; //3 - ++nr; - - _iarray[nr] = t * (i - 1) + j + 0; //4 - ++nr; - _iarray[nr] = t * (i + 0) + j + 1; //5 - ++nr; - _iarray[nr] = t * (i - 1) + j + 1; //6 - ++nr; - - /* - _iarray[nr] = t * (i - 1) + j + 0; //1 - ++nr; - _iarray[nr] = t * (i + 0) + j + 0; //2 - ++nr; - _iarray[nr] = t * (i + 0) + j + 1; //3 - ++nr; - _iarray[nr] = t * (i - 1) + j + 1; //6 - ++nr; - _iarray[nr] = t * (i - 1) + j + 0; //4 - ++nr; - */ - } - } -} +PowerScaledSphere::PowerScaledSphere(float radius, int segments) + : PowerScaledSphere(glm::vec3(radius), segments) +{} // Alternative Constructor for using accurate triaxial ellipsoid PowerScaledSphere::PowerScaledSphere(glm::vec3 radius, int segments) @@ -139,9 +58,12 @@ PowerScaledSphere::PowerScaledSphere(glm::vec3 radius, int segments) // azimuth angle (east to west) const float phi = fj * glm::pi() * 2.f / fsegments; // 0 -> 2*PI - const float x = radius[0] * sin(phi) * sin(theta); // - const float y = radius[1] * cos(theta); // up - const float z = radius[2] * cos(phi) * sin(theta); // + // Spherical coordinates based on ISO standard. + // https://en.wikipedia.org/wiki/Spherical_coordinate_system + + const float x = radius[0] * sin(theta) * cos(phi); + const float y = radius[1] * sin(theta) * sin(phi); + const float z = radius[2] * cos(theta); // Z points towards pole (theta = 0) _varray[nr].location[0] = x; _varray[nr].location[1] = y; diff --git a/tests/test_powerscalecoordinates.inl b/tests/test_powerscalecoordinates.inl index fb8bf5074d..23b22a70a9 100644 --- a/tests/test_powerscalecoordinates.inl +++ b/tests/test_powerscalecoordinates.inl @@ -25,7 +25,6 @@ #include #include -#include class PowerscaleCoordinatesTest : public testing::Test { protected: @@ -60,23 +59,5 @@ TEST_F(PowerscaleCoordinatesTest, psc) { } -TEST_F(PowerscaleCoordinatesTest, pss) { - - openspace::pss first(1.f, 1.f); - openspace::pss second(1.f, -1.f); - EXPECT_EQ(openspace::pss(1.01f, 1.f), first + second); - EXPECT_EQ(openspace::pss(1.01f, 1.f), second + first); - /* - EXPECT_TRUE(first < (first + second)); - bool retu =(second < (first + second)); - - std::cout << "retu: " << retu << std::endl; - EXPECT_TRUE(retu); - - EXPECT_FALSE(first > (first + second)); - EXPECT_FALSE(second > (first + second)); - - */ -}