Merge branch 'feature/globebrowsing' of github.com:OpenSpace/OpenSpace-Development into feature/globebrowsing

This commit is contained in:
Kalle Bladin
2016-06-02 11:53:25 -04:00
27 changed files with 306 additions and 1874 deletions

View File

@@ -58,6 +58,10 @@ class SyncBuffer;
class Time {
public:
Time();
Time(const Time& other);
/**
* Initializes the Time singleton.
* \return <code>true</code> if the initialization succeeded, <code>false</code>
@@ -123,6 +127,12 @@ public:
*/
std::string currentTimeUTC() const;
/**
* Returns the current time as a ISO 8601 formatted, i.e YYYY-MM-DDThh:mm:ssZ
* \return The current time as a ISO 8601 formatted string
*/
std::string ISO8601() const;
/**
* Sets the delta time value that is the number of seconds that should pass for each
* real-time second. This value is used in the advanceTime(double) method to easily

View File

@@ -28,8 +28,6 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/globes/renderableglobe.h
${CMAKE_CURRENT_SOURCE_DIR}/globes/globemesh.h
${CMAKE_CURRENT_SOURCE_DIR}/globes/clipmapglobe.h
${CMAKE_CURRENT_SOURCE_DIR}/globes/clipmappyramid.h
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkedlodglobe.h
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunknode.h
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkindex.h
@@ -39,7 +37,6 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/meshes/grid.h
${CMAKE_CURRENT_SOURCE_DIR}/meshes/basicgrid.h
${CMAKE_CURRENT_SOURCE_DIR}/meshes/skirtedgrid.h
${CMAKE_CURRENT_SOURCE_DIR}/meshes/clipmapgrid.h
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/geodetic2.h
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/angle.h
@@ -50,7 +47,6 @@ set(HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/aabb.h
${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.h
${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.h
${CMAKE_CURRENT_SOURCE_DIR}/other/temporaltileprovider.h
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.h
${CMAKE_CURRENT_SOURCE_DIR}/other/tiledataset.h
@@ -67,8 +63,6 @@ set(HEADER_FILES
set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/globes/renderableglobe.cpp
${CMAKE_CURRENT_SOURCE_DIR}/globes/globemesh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/globes/clipmapglobe.cpp
${CMAKE_CURRENT_SOURCE_DIR}/globes/clipmappyramid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkedlodglobe.cpp
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunknode.cpp
${CMAKE_CURRENT_SOURCE_DIR}/globes/chunkindex.cpp
@@ -78,7 +72,6 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/meshes/grid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/meshes/basicgrid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/meshes/skirtedgrid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/meshes/clipmapgrid.cpp
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/geodetic2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/geodetics/angle.inl
@@ -89,7 +82,6 @@ set(SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/rendering/aabb.cpp
${CMAKE_CURRENT_SOURCE_DIR}/other/distanceswitch.cpp
${CMAKE_CURRENT_SOURCE_DIR}/other/patchcoverageprovider.cpp
${CMAKE_CURRENT_SOURCE_DIR}/other/temporaltileprovider.cpp
${CMAKE_CURRENT_SOURCE_DIR}/other/tileprovider.cpp
${CMAKE_CURRENT_SOURCE_DIR}/other/tiledataset.cpp
@@ -109,11 +101,6 @@ set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalchunkedlodpatch_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalchunkedlodpatch_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalclipmappatch_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalclipmappatch_fs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/localclipmappatch_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/simple_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/simple_fs.glsl
)
source_group("Shader Files" FILES ${SHADER_FILES})

View File

@@ -1,142 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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 <modules/globebrowsing/globes/clipmapglobe.h>
#include <modules/globebrowsing/meshes/clipmapgrid.h>
// open space includes
#include <openspace/engine/openspaceengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/util/spicemanager.h>
#include <openspace/scene/scenegraphnode.h>
// ghoul includes
#include <ghoul/misc/assert.h>
#define _USE_MATH_DEFINES
#include <math.h>
namespace {
const std::string _loggerCat = "ClipMapGlobe";
}
namespace openspace {
ClipMapGlobe::ClipMapGlobe(
const Ellipsoid& ellipsoid,
std::shared_ptr<TileProviderManager> tileProviderManager)
: _clipMapPyramid(Geodetic2(M_PI / 2, M_PI / 2))
, _ellipsoid(ellipsoid)
{
// init Renderer
auto outerPatchRenderer = new ClipMapPatchRenderer(
shared_ptr<OuterClipMapGrid>(new OuterClipMapGrid(256)),
tileProviderManager);
_outerPatchRenderer.reset(outerPatchRenderer);
auto innerPatchRenderer = new ClipMapPatchRenderer(
shared_ptr<InnerClipMapGrid>(new InnerClipMapGrid(256)),
tileProviderManager);
_innerPatchRenderer.reset(innerPatchRenderer);
}
ClipMapGlobe::~ClipMapGlobe() {
}
const Ellipsoid& ClipMapGlobe::ellipsoid() const
{
return _ellipsoid;
}
bool ClipMapGlobe::initialize() {
return isReady();
}
bool ClipMapGlobe::deinitialize() {
return true;
}
bool ClipMapGlobe::isReady() const {
bool ready = true;
return ready;
}
void ClipMapGlobe::render(const RenderData& data)
{
int minDepth, maxDepth;
calculateDesiredMinAndMaxDepth(data, minDepth, maxDepth);
// render patches
for (size_t i = minDepth; i < maxDepth; i++)
{
Geodetic2 patchSize = _clipMapPyramid.getPatchSizeAtLevel(i);
_outerPatchRenderer->renderPatch(patchSize, data, _ellipsoid);
}
Geodetic2 patchSize = _clipMapPyramid.getPatchSizeAtLevel(maxDepth);
_innerPatchRenderer->renderPatch(patchSize, data, _ellipsoid);
}
void ClipMapGlobe::update(const UpdateData& data) {
_innerPatchRenderer->update();
_outerPatchRenderer->update();
}
void ClipMapGlobe::calculateDesiredMinAndMaxDepth(
const RenderData& data,
int& minDepth,
int& maxDepth)
{
Scalar minimumRadius = _ellipsoid.minimumRadius();
Vec3 cameraPosition = data.camera.position().dvec3();
Vec3 cameraPositionOnSurface = _ellipsoid.geodeticSurfaceProjection(cameraPosition);
Scalar h = glm::length(cameraPosition - cameraPositionOnSurface);
Scalar cosAngleToHorizon = minimumRadius / (minimumRadius + h);
Scalar angleToHorizon = glm::acos(cosAngleToHorizon);
Scalar minimumPatchSize = glm::min(
_clipMapPyramid.getPatchSizeAtLevel0().lat,
_clipMapPyramid.getPatchSizeAtLevel0().lon);
minDepth = log2(minimumPatchSize / 2 / angleToHorizon);
// Calculate desired level based on distance
Scalar scaleFactor = 1 * minimumRadius;
Scalar projectedScaleFactor = scaleFactor / h;
maxDepth = glm::max(static_cast<int>(log2(projectedScaleFactor)), 0);
// Test smaller and smaller patches until one is outside of frustum
int i;
for (i = minDepth; i < maxDepth; i++)
{
Geodetic2 center = _ellipsoid.cartesianToGeodetic2(cameraPosition);
Geodetic2 halfSize = _clipMapPyramid.getPatchSizeAtLevel(i) / 2;
GeodeticPatch testPatch(center, halfSize);
// Do frustrum culling
if (FrustumCuller::isVisible(data, testPatch, _ellipsoid)) {
break;
}
}
maxDepth = i;
}
} // namespace openspace

View File

@@ -1,81 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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 __CLIPMAPGLOBE_H__
#define __CLIPMAPGLOBE_H__
// open space includes
#include <openspace/rendering/renderable.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/util/updatestructures.h>
#include <modules/globebrowsing/meshes/trianglesoup.h>
#include <modules/globebrowsing/meshes/grid.h>
#include <modules/globebrowsing/other/distanceswitch.h>
#include <modules/globebrowsing/rendering/patchrenderer.h>
#include <modules/globebrowsing/rendering/culling.h>
#include <modules/globebrowsing/globes/clipmappyramid.h>
#include <modules/globebrowsing/other/TileProviderManager.h>
namespace ghoul {
namespace opengl {
class ProgramObject;
}
}
namespace openspace {
class ClipMapGlobe : public Renderable {
public:
ClipMapGlobe(
const Ellipsoid& ellipsoid,
std::shared_ptr<TileProviderManager> tileProviderManager);
~ClipMapGlobe();
bool initialize() override;
bool deinitialize() override;
bool isReady() const override;
void render(const RenderData& data) override;
void update(const UpdateData& data) override;
const Ellipsoid& ellipsoid() const;
private:
void calculateDesiredMinAndMaxDepth(
const RenderData& data,
int& minDepth,
int& maxDepth);
//shared_ptr<TileProvider> _tileProvider;
std::unique_ptr<ClipMapPatchRenderer> _outerPatchRenderer;
std::unique_ptr<ClipMapPatchRenderer> _innerPatchRenderer;
ClipMapPyramid _clipMapPyramid;
const Ellipsoid& _ellipsoid;
};
} // namespace openspace
#endif // __CLIPMAPGLOBE_H__

View File

@@ -1,59 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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 <modules/globebrowsing/globes/clipmappyramid.h>
#define _USE_MATH_DEFINES
#include <math.h>
// ghoul includes
#include <ghoul/misc/assert.h>
namespace {
const std::string _loggerCat = "ClipMapPyramid";
}
namespace openspace {
ClipMapPyramid::ClipMapPyramid(Geodetic2 sizeLevel0)
: _sizeLevel0(sizeLevel0)
{
}
ClipMapPyramid::~ClipMapPyramid()
{}
Geodetic2 ClipMapPyramid::getPatchSizeAtLevel(int level)
{
return Geodetic2(_sizeLevel0.lat / pow(2, level), _sizeLevel0.lon / pow(2, level));
}
Geodetic2 ClipMapPyramid::getPatchSizeAtLevel0()
{
return _sizeLevel0;
}
} // namespace openspace

View File

@@ -1,52 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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 __CLIPMAPPYRAMID_H__
#define __CLIPMAPPYRAMID_H__
// open space includes
#include <modules/globebrowsing/geodetics/geodetic2.h>
namespace openspace {
class ClipMapPyramid {
public:
/**
\Param sizeLevel0 is the size of the biggest patch in the pyramid.
The parameter needs to be M_PI / pow(2, i) where i is a positive or zero
valued integer.
*/
ClipMapPyramid(Geodetic2 sizeLevel0);
~ClipMapPyramid();
Geodetic2 getPatchSizeAtLevel(int level);
Geodetic2 getPatchSizeAtLevel0();
private:
const Geodetic2 _sizeLevel0;
};
} // namespace openspace
#endif // __CLIPMAPPYRAMID_H__

View File

@@ -25,7 +25,6 @@
#include <modules/globebrowsing/globes/renderableglobe.h>
#include <modules/globebrowsing/globes/globemesh.h>
#include <modules/globebrowsing/globes/clipmapglobe.h>
#include <modules/globebrowsing/other/threadpool.h>

View File

@@ -1,182 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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 <modules/globebrowsing/other/patchcoverageprovider.h>
#include <ghoul/logging/logmanager.h>
#include <glm/glm.hpp>
namespace {
const std::string _loggerCat = "PatchCoverageProvider";
}
namespace openspace {
PatchCoverageProvider::PatchCoverageProvider(
Geodetic2 sizeLevel0,
Geodetic2 offsetLevel0,
int depth)
: _sizeLevel0(sizeLevel0)
, _offsetLevel0(offsetLevel0)
, _depth(depth)
{
}
PatchCoverageProvider::~PatchCoverageProvider(){
}
ChunkIndex PatchCoverageProvider::getChunkIndex(const GeodeticPatch& patch) {
// Calculate the level of the index depending on the size of the incoming patch.
// The level is as big as possible (as far down as possible) but it can't be
// too big since at maximum four tiles should be used to cover a patch
int level = log2(static_cast<int>(glm::max(
_sizeLevel0.lat / (patch.size().lat),
_sizeLevel0.lon / (patch.size().lon))));
// If the depth is not big enough, the level must be clamped.
level = glm::min(level, _depth);
// Calculate the index in x y where the tile should be positioned
int nIndices = pow(2, level);
Geodetic2 tileSize = _sizeLevel0 / nIndices;
Geodetic2 nw = patch.northWestCorner();
glm::ivec2 chunkIndexXY =
glm::floor((nw.toLonLatVec2() - _offsetLevel0.toLonLatVec2()) / tileSize.toLonLatVec2());
// Flip y since indices increase from top to bottom
chunkIndexXY.y = nIndices - 1 - chunkIndexXY.y;
// Create the tileindex
ChunkIndex chunkIndex = { chunkIndexXY.x, chunkIndexXY.y, level };
return chunkIndex;
}
glm::mat3 PatchCoverageProvider::getUvTransformationPatchToTile(
GeodeticPatch patch,
const ChunkIndex& chunkIndex)
{
GeodeticPatch otherPatch(chunkIndex);
return getUvTransformationPatchToTile(patch, otherPatch);
}
glm::mat3 PatchCoverageProvider::getUvTransformationPatchToTile(
GeodeticPatch patch,
GeodeticPatch tile)
{
Vec2 posDiff =
patch.southWestCorner().toLonLatVec2() -
tile.southWestCorner().toLonLatVec2();
glm::mat3 invTileScale = glm::mat3(
{ 1 / (tile.size().lon), 0, 0,
0, 1 / (tile.size().lat), 0,
0, 0, 1 });
glm::mat3 globalTranslation = glm::mat3(
{ 1, 0, 0,
0, 1, 0,
posDiff.x, posDiff.y, 1 });
glm::mat3 patchScale = glm::mat3(
{ (patch.halfSize().lon * 2), 0, 0,
0, (patch.halfSize().lat * 2), 0,
0, 0, 1 });
return invTileScale * globalTranslation * patchScale;
}
PatchCoverage PatchCoverageProvider::getCoverage(
GeodeticPatch patch,
std::shared_ptr<TileProvider> tileProvider)
{
static const int numTilesInCoverageX = 2;
static const int numTilesInCoverageY = 2;
PatchCoverage patchCoverageToReturn;
Geodetic2 startPoint = patch.northWestCorner();
int level = (int) patch.minimumTileLevel();
ChunkIndex startIndex = ChunkIndex(startPoint, level);
for (int y = 0; y < numTilesInCoverageY; y++)
{
for (int x = 0; x < numTilesInCoverageX; x++)
{
int linearIdx = x + y * numTilesInCoverageX;
// May return negative indices
ChunkIndex chunkIndex = getChunkIndex(patch);
// Offset chunkIndex
chunkIndex.x += x;
chunkIndex.y += y;
// If the tile index is negative or too big it needs to wrap around
int nIndices = pow(2, chunkIndex.level);
ChunkIndex positiveChunkIndex = ChunkIndex(chunkIndex);
positiveChunkIndex.x += (chunkIndex.x < 0) ? nIndices : ((chunkIndex.x > nIndices - 1) ? -nIndices : 0);
positiveChunkIndex.y += (chunkIndex.y < 0) ? nIndices : ((chunkIndex.y > nIndices - 1) ? -nIndices : 0);
int numLevelsToLoop = chunkIndex.level;
// Start at the highest level and go down if the texture don't exist
for (int j = numLevelsToLoop; j >= 0; j--)
{
// Try if the texture exists
std::shared_ptr<Texture> tile = tileProvider->getOrStartFetchingTile(positiveChunkIndex);
if (tile == nullptr)
{ // If it doesn't exist, go down a level
chunkIndex.x /= 2;
chunkIndex.y /= 2;
chunkIndex.level -= 1;
}
else
{ // A texture was found, put it in the data structure to return
patchCoverageToReturn.textureTransformPairs[linearIdx].first =
tile;
patchCoverageToReturn.textureTransformPairs[linearIdx].second =
getUvTransformationPatchToTile(patch, chunkIndex);
}
}
// If the texture still doesn't exist put a temporary texture
if (patchCoverageToReturn.textureTransformPairs[linearIdx].first == nullptr)
{
patchCoverageToReturn.textureTransformPairs[linearIdx].first =
tileProvider->getDefaultTexture();
patchCoverageToReturn.textureTransformPairs[linearIdx].second =
getUvTransformationPatchToTile(patch, chunkIndex);
}
}
}
return patchCoverageToReturn;
}
} // namespace openspace

View File

@@ -1,94 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2016 *
* *
* 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 __PATCHCOVERAGEPROVIDER_H__
#define __PATCHCOVERAGEPROVIDER_H__
#include <ghoul/logging/logmanager.h>
#include <modules/globebrowsing/globes/chunkindex.h>
#include <modules/globebrowsing/geodetics/geodetic2.h>
#include <modules/globebrowsing/other/tileprovider.h>
#include <ghoul/opengl/texture.h>
//////////////////////////////////////////////////////////////////////////////////////////
// PATCH COVERAGE PROVIDER //
//////////////////////////////////////////////////////////////////////////////////////////
namespace openspace {
using namespace ghoul::opengl;
struct PatchCoverage
{
using TextureTransformPair = std::pair<std::shared_ptr<Texture>, glm::mat3>;
TextureTransformPair textureTransformPairs[4];
};
class PatchCoverageProvider
{
public:
PatchCoverageProvider(
Geodetic2 sizeLevel0,
Geodetic2 offsetLevel0,
int depth);
~PatchCoverageProvider();
/**
Returns the index of the tile at an appropriate level.
Appropriate meaning that the tile should be at as high level as possible
Without the tile being smaller than the patch in lat-lon space.
The tile is at least as big as the patch.
*/
ChunkIndex getChunkIndex(const GeodeticPatch& patch);
/**
A transformation (translation and scaling) from the texture space of a patch
to the texture space of a tile.
*/
glm::mat3 getUvTransformationPatchToTile(
GeodeticPatch patch,
const ChunkIndex& chunkIndex);
/**
Overloaded function
*/
glm::mat3 getUvTransformationPatchToTile(
GeodeticPatch patch,
GeodeticPatch tile);
PatchCoverage getCoverage(
GeodeticPatch patch,
std::shared_ptr<TileProvider> tileProvider);
private:
Geodetic2 _sizeLevel0;
Geodetic2 _offsetLevel0;
int _depth;
};
} // namespace openspace
#endif // __PATCHCOVERAGEPROVIDER_H__

View File

@@ -31,8 +31,12 @@
#include <ghoul/logging/logmanager.h>
#include <openspace/util/time.h>
#include <string>
#include <fstream>
#include <streambuf>
@@ -43,6 +47,73 @@ namespace {
namespace openspace {
const std::string TemporalTileProvider::TIME_PLACEHOLDER("${t}");
TemporalTileProvider::TemporalTileProvider(const std::string& datasetFile,
const TileProviderInitData& tileProviderInitData)
: _datasetFile(datasetFile)
, _tileProviderInitData(tileProviderInitData)
{
std::ifstream in(datasetFile.c_str());
ghoul_assert(errno == 0, strerror(errno) << std::endl << datasetFile);
// read file
std::string str( (std::istreambuf_iterator<char>(in)), (std::istreambuf_iterator<char>()));
_dataSourceXmlTemplate = std::string(str);
}
std::shared_ptr<TileProvider> TemporalTileProvider::getTileProvider(Time t) {
TimeKey timekey = getTimeKey(t);
auto it = _tileProviderMap.find(timekey);
if (it != _tileProviderMap.end()) {
return it->second;
}
else {
auto tileProvider = initTileProvider(timekey);
_tileProviderMap[timekey] = tileProvider;
return tileProvider;
}
}
std::shared_ptr<TileProvider> TemporalTileProvider::initTileProvider(TimeKey timekey) {
std::string gdalDatasetXml = getGdalDatasetXML(timekey);
std::shared_ptr<TileDataset> tileDataset = std::shared_ptr<TileDataset>(
new TileDataset(gdalDatasetXml, _tileProviderInitData.minimumPixelSize));
std::shared_ptr<ThreadPool> threadPool = std::shared_ptr<ThreadPool>(
new ThreadPool(_tileProviderInitData.threads));
std::shared_ptr<AsyncTileDataProvider> tileReader = std::shared_ptr<AsyncTileDataProvider>(
new AsyncTileDataProvider(tileDataset, threadPool));
std::shared_ptr<TileProvider> tileProvider= std::shared_ptr<TileProvider>(
new TileProvider(tileReader,
_tileProviderInitData.cacheSize,
_tileProviderInitData.framesUntilRequestQueueFlush));
return tileProvider;
}
TemporalTileProvider::TimeKey TemporalTileProvider::getTimeKey(const Time& t) {
std::string datestring = t.ISO8601();
datestring = datestring.substr(0, 10);
return datestring;
}
std::string TemporalTileProvider::getGdalDatasetXML(Time t) {
return getGdalDatasetXML(getTimeKey(t));
}
std::string TemporalTileProvider::getGdalDatasetXML(TimeKey timeKey) {
std::string xmlTemplate(_dataSourceXmlTemplate);
size_t pos = xmlTemplate.find(TIME_PLACEHOLDER);
size_t numChars = TIME_PLACEHOLDER.length();
ghoul_assert(pos != std::string::npos, "Invalid dataset file");
std::string timeSpecifiedXml = xmlTemplate.replace(pos, numChars, timeKey);
return timeSpecifiedXml;
}
} // namespace openspace

View File

@@ -30,6 +30,15 @@
#include <modules/globebrowsing/geodetics/geodetic2.h>
#include <modules/globebrowsing/other/tileprovider.h>
#include <openspace/util/time.h>
#include <unordered_map>
#include "gdal_priv.h"
#include "vrtdataset.h"
//////////////////////////////////////////////////////////////////////////////////////////
// TILE PROVIDER //
@@ -37,11 +46,50 @@
namespace openspace {
struct TileProviderInitData {
int minimumPixelSize;
int threads;
int cacheSize;
int framesUntilRequestQueueFlush;
};
class TemporalTileProvider {
public:
TemporalTileProvider(const std::string& datasetFile, const TileProviderInitData& tileProviderInitData);
std::shared_ptr<TileProvider> getTileProvider(Time t = Time::ref());
private:
typedef std::string TimeKey;
std::string getGdalDatasetXML(Time t);
std::string getGdalDatasetXML(TimeKey key);
static const std::string TIME_PLACEHOLDER;
TimeKey getTimeKey(const Time& t);
std::shared_ptr<TileProvider> initTileProvider(TimeKey timekey);
//////////////////////////////////////////////////////////////////////////////////
// Members variables //
//////////////////////////////////////////////////////////////////////////////////
const std::string _datasetFile;
std::string _dataSourceXmlTemplate;
std::unordered_map<TimeKey, std::shared_ptr<TileProvider> > _tileProviderMap;
TileProviderInitData _tileProviderInitData;
};
} // namespace openspace

View File

@@ -31,6 +31,8 @@
#include <modules/globebrowsing/other/tileprovider.h>
#include <modules/globebrowsing/geodetics/angle.h>
namespace {
const std::string _loggerCat = "TileDataset";
}
@@ -42,17 +44,16 @@ namespace openspace {
// INIT THIS TO FALSE AFTER REMOVED FROM TILEPROVIDER
bool TileDataset::GdalHasBeenInitialized = false;
TileDataset::TileDataset(const std::string& fileName, int minimumPixelSize, GLuint dataType)
TileDataset::TileDataset(const std::string& gdalDatasetDesc, int minimumPixelSize, GLuint dataType)
: _minimumPixelSize(minimumPixelSize)
{
if (!GdalHasBeenInitialized) {
GDALAllRegister();
GdalHasBeenInitialized = true;
}
_dataset = (GDALDataset *)GDALOpen(absPath(fileName).c_str(), GA_ReadOnly);
ghoul_assert(_dataset != nullptr, "Failed to load dataset: " << fileName);
_dataset = (GDALDataset *)GDALOpen(gdalDatasetDesc.c_str(), GA_ReadOnly);
ghoul_assert(_dataset != nullptr, "Failed to load dataset:\n" << gdalDatasetDesc);
_dataLayout = DataLayout(_dataset, dataType);
_depthTransform = calculateTileDepthTransform();

View File

@@ -34,6 +34,7 @@
#include "gdal_priv.h"
#include <memory>
#include <set>
#include <queue>
@@ -88,12 +89,22 @@ namespace openspace {
class TileDataset {
public:
// Default dataType = 0 means GDAL will use the same data type as the data
// is originally in
TileDataset(const std::string& fileName, int minimumPixelSize, GLuint dataType = 0);
/**
* Opens a GDALDataset in readonly mode and calculates meta data required for
* reading tile using a ChunkIndex.
*
* \param gdalDatasetDesc - A path to a specific file or raw XML describing the dataset
* \param minimumPixelSize - minimum number of pixels per side per tile requested
* \param datatype - datatype for storing pixel data in requested tile
*/
TileDataset(const std::string& gdalDatasetDesc, int minimumPixelSize, GLuint dataType = 0);
~TileDataset();
std::shared_ptr<TileIOResult> readTileData(ChunkIndex chunkIndex);
@@ -105,6 +116,7 @@ namespace openspace {
private:
//////////////////////////////////////////////////////////////////////////////////
// HELPER STRUCTS //
//////////////////////////////////////////////////////////////////////////////////

View File

@@ -52,7 +52,7 @@ namespace openspace {
, _tileCache(tileCacheSize)
, _framesSinceLastRequestFlush(0)
{
initDefaultTexture();
}
@@ -60,23 +60,6 @@ namespace openspace {
clearRequestQueue();
}
void TileProvider::initDefaultTexture() {
// Set a temporary texture
std::string fileName = "textures/earth_bluemarble.jpg";
_defaultTexture = std::move(ghoul::io::TextureReader::ref().loadTexture(absPath(fileName)));
if (_defaultTexture) {
LDEBUG("Loaded texture from '" << fileName << "'");
_defaultTexture->uploadTexture();
// Textures of planets looks much smoother with AnisotropicMipMap rather than linear
// TODO: AnisotropicMipMap crashes on ATI cards ---abock
//_testTexture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_defaultTexture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
_defaultTexture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
}
}
void TileProvider::prerender() {
initTexturesFromLoadedData();
@@ -98,44 +81,33 @@ namespace openspace {
}
Tile TileProvider::getHighestResolutionTile(
ChunkIndex chunkIndex,
TileUvTransform uvTransform) {
Tile TileProvider::getHighestResolutionTile(ChunkIndex chunkIndex, int parents, TileUvTransform uvTransform) {
int maximumLevel = _asyncTextureDataProvider->getTextureDataProvider()->getMaximumLevel();
while(chunkIndex.level > maximumLevel){
transformFromParent(chunkIndex, uvTransform);
chunkIndex = chunkIndex.parent();
}
for (int i = 0; i < parents && chunkIndex.level > 1; i++) {
transformFromParent(chunkIndex, uvTransform);
chunkIndex = chunkIndex.parent();
}
return getOrEnqueueHighestResolutionTile(chunkIndex, uvTransform);
}
Tile TileProvider::getHighestResolutionParentTile(ChunkIndex chunkIndex, int levelOffset) {
TileUvTransform uvTransform;
uvTransform.uvOffset = glm::vec2(0, 0);
uvTransform.uvScale = glm::vec2(1, 1);
for (int i = 0; i < levelOffset && chunkIndex.level > 2; i++) {
transformFromParent(chunkIndex, uvTransform);
chunkIndex = chunkIndex.parent();
}
Tile toReturn = getHighestResolutionTile(chunkIndex, uvTransform);
return toReturn;
}
Tile TileProvider::getOrEnqueueHighestResolutionTile(const ChunkIndex& chunkIndex,
TileUvTransform& uvTransform)
{
HashKey key = chunkIndex.hashKey();
if (_tileCache.exist(key) && _tileCache.get(key).ioError == CPLErr::CE_None) {
std::shared_ptr<Texture> texture = _tileCache.get(key).texture;
return { texture, uvTransform };
return { _tileCache.get(key).texture, uvTransform };
}
else if (chunkIndex.level <= 1) {
return { getDefaultTexture(), uvTransform };
else if (chunkIndex.level < 1) {
return { nullptr, uvTransform };
}
else {
// We don't have the tile for the requested level
@@ -179,11 +151,6 @@ namespace openspace {
}
}
std::shared_ptr<Texture> TileProvider::getDefaultTexture() {
return _defaultTexture;
}
TileDepthTransform TileProvider::depthTransform() {
return _asyncTextureDataProvider->getTextureDataProvider()->getDepthTransform();
}

View File

@@ -46,28 +46,27 @@
namespace openspace {
using namespace ghoul::opengl;
struct TileUvTransform
{
glm::vec2 uvOffset;
glm::vec2 uvScale;
};
struct Tile {
std::shared_ptr<Texture> texture;
TileUvTransform uvTransform;
};
struct MetaTexture {
std::shared_ptr<Texture> texture;
CPLErr ioError;
};
/**
Provides tiles through GDAL datasets which can be defined with xml files
for example for wms.
@@ -78,38 +77,27 @@ namespace openspace {
TileProvider(std::shared_ptr<AsyncTileDataProvider> tileReader, int tileCacheSize,
int framesUntilFlushRequestQueue);
~TileProvider();
Tile getHighestResolutionTile(
ChunkIndex chunkIndex,
TileUvTransform uvTransform = {glm::vec2(0.0f,0.0f), glm::vec2(1.0f,1.0f)});
/**
\param levelOffset gives a tile from a parent chunk with that particular
offset. For example levelOffset = 1 gives the first parent and levelOffset = 2
gives the grand parent.
*/
Tile getHighestResolutionParentTile(ChunkIndex chunkIndex, int levelOffset = 1);
Tile getHighestResolutionTile(ChunkIndex chunkIndex, int parents = 0,
TileUvTransform uvTransform = { glm::vec2(0, 0), glm::vec2(1, 1)});
std::shared_ptr<Texture> getOrStartFetchingTile(ChunkIndex chunkIndex);
std::shared_ptr<Texture> getDefaultTexture();
TileDepthTransform depthTransform();
void prerender();
static ThreadPool threadPool;
private:
friend class TileLoadJob;
//////////////////////////////////////////////////////////////////////////////////
// Helper functions //
//////////////////////////////////////////////////////////////////////////////////
Tile getOrEnqueueHighestResolutionTile(const ChunkIndex& ci, TileUvTransform& uvTransform);
Tile getOrEnqueueHighestResolutionTile(const ChunkIndex& ci,
TileUvTransform& uvTransform);
std::shared_ptr<Texture> getOrStartFetchingTile(ChunkIndex chunkIndex);
void transformFromParent(const ChunkIndex& ci, TileUvTransform& uv) const;
@@ -119,17 +107,12 @@ namespace openspace {
/**
Creates an OpenGL texture and pushes the data to the GPU.
*/
void initializeAndAddToCache(
std::shared_ptr<TileIOResult> uninitedTexture);
void initializeAndAddToCache(std::shared_ptr<TileIOResult> uninitedTexture);
void clearRequestQueue();
void initTexturesFromLoadedData();
void initDefaultTexture();
//////////////////////////////////////////////////////////////////////////////////
@@ -143,9 +126,6 @@ namespace openspace {
std::shared_ptr<AsyncTileDataProvider> _asyncTextureDataProvider;
std::shared_ptr<Texture> _defaultTexture;
};

View File

@@ -25,7 +25,6 @@
#include <modules/globebrowsing/rendering/patchrenderer.h>
#include <modules/globebrowsing/globes/chunkedlodglobe.h>
#include <modules/globebrowsing/meshes/clipmapgrid.h>
// open space includes
#include <openspace/engine/wrapper/windowwrapper.h>
@@ -167,8 +166,23 @@ namespace openspace {
auto tileProvider = it->get();
// Get the texture that should be used for rendering
Tile tile = tileProvider->getHighestResolutionTile(chunk.index());
Tile tileParent1 = tileProvider->getHighestResolutionParentTile(chunk.index(), 1);
Tile tileParent2 = tileProvider->getHighestResolutionParentTile(chunk.index(), 2);
Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1);
Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2);
if (tile.texture == nullptr) {
// don't render if no tile was available
programObject->deactivate();
return;
}
if (tileParent1.texture == nullptr) {
tileParent1 = tile;
}
if (tileParent2.texture == nullptr) {
tileParent2 = tileParent1;
}
TileDepthTransform depthTransform = tileProvider->depthTransform();
// The texture needs a unit to sample from
@@ -238,8 +252,22 @@ namespace openspace {
auto tileProvider = it->get();
// Get the texture that should be used for rendering
Tile tile = tileProvider->getHighestResolutionTile(chunk.index());
Tile tileParent1 = tileProvider->getHighestResolutionParentTile(chunk.index(), 1);
Tile tileParent2 = tileProvider->getHighestResolutionParentTile(chunk.index(), 2);
Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1);
Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2);
if (tile.texture == nullptr) {
// don't render if no tile was available
programObject->deactivate();
return;
}
if (tileParent1.texture == nullptr) {
tileParent1 = tile;
}
if (tileParent2.texture == nullptr) {
tileParent2 = tileParent1;
}
// The texture needs a unit to sample from
texUnitColor[i].activate();
@@ -314,6 +342,7 @@ namespace openspace {
programObject->setUniform("lonLatScalingFactor", vec2(patchSize.toLonLatVec2()));
programObject->setUniform("radiiSquared", vec3(ellipsoid.radiiSquared()));
programObject->setUniform("xSegments", _grid->xSegments());
// The length of the skirts is proportional to its size
programObject->setUniform("skirtLength", static_cast<float>(chunk.surfacePatch().halfSize().lat * 1000000));
@@ -390,8 +419,22 @@ namespace openspace {
auto tileProvider = it->get();
// Get the texture that should be used for rendering
Tile tile = tileProvider->getHighestResolutionTile(chunk.index());
Tile tileParent1 = tileProvider->getHighestResolutionParentTile(chunk.index(), 1);
Tile tileParent2 = tileProvider->getHighestResolutionParentTile(chunk.index(), 2);
Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1);
Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2);
if (tile.texture == nullptr) {
// don't render if no tile was available
programObject->deactivate();
return;
}
if (tileParent1.texture == nullptr) {
tileParent1 = tile;
}
if (tileParent2.texture == nullptr) {
tileParent2 = tileParent1;
}
TileDepthTransform depthTransform = tileProvider->depthTransform();
// The texture needs a unit to sample from
@@ -460,8 +503,22 @@ namespace openspace {
auto tileProvider = it->get();
// Get the texture that should be used for rendering
Tile tile = tileProvider->getHighestResolutionTile(chunk.index());
Tile tileParent1 = tileProvider->getHighestResolutionParentTile(chunk.index(), 1);
Tile tileParent2 = tileProvider->getHighestResolutionParentTile(chunk.index(), 2);
Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1);
Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2);
if (tile.texture == nullptr) {
// don't render if no tile was available
programObject->deactivate();
return;
}
if (tileParent1.texture == nullptr) {
tileParent1 = tile;
}
if (tileParent2.texture == nullptr) {
tileParent2 = tileParent1;
}
// The texture needs a unit to sample from
texUnitColor[i].activate();
@@ -513,7 +570,6 @@ namespace openspace {
i++;
}
// Calculate other uniform variables needed for rendering
// TODO : Model transform should be fetched as a matrix directly.
@@ -577,408 +633,4 @@ namespace openspace {
// disable shader
programObject->deactivate();
}
//////////////////////////////////////////////////////////////////////////////////////
// CLIPMAP PATCH RENDERER //
//////////////////////////////////////////////////////////////////////////////////////
ClipMapPatchRenderer::ClipMapPatchRenderer(
shared_ptr<ClipMapGrid> grid,
shared_ptr<TileProviderManager> tileProviderManager)
: PatchRenderer(tileProviderManager)
, _grid(grid)
, _patchCoverageProvider(
Geodetic2(M_PI * 2, M_PI * 2),
Geodetic2(-M_PI -M_PI/2, -M_PI),
10)
{
_programObjectGlobalRendering = OsEng.renderEngine().buildRenderProgram(
"GlobalClipMapPatch",
"${MODULE_GLOBEBROWSING}/shaders/globalclipmappatch_vs.glsl",
"${MODULE_GLOBEBROWSING}/shaders/globalclipmappatch_fs.glsl");
ghoul_assert(_programObjectGlobalRendering != nullptr, "Failed to initialize programObject!");
_programObjectLocalRendering = OsEng.renderEngine().buildRenderProgram(
"LocalClipMapPatch",
"${MODULE_GLOBEBROWSING}/shaders/localclipmappatch_vs.glsl",
"${MODULE_GLOBEBROWSING}/shaders/localclipmappatch_fs.glsl");
ghoul_assert(_programObjectLocalRendering != nullptr, "Failed to initialize programObject!");
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
_programObjectGlobalRendering->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
_programObjectLocalRendering->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
}
ClipMapPatchRenderer::~ClipMapPatchRenderer()
{
if (_programObjectGlobalRendering) {
RenderEngine& renderEngine = OsEng.renderEngine();
renderEngine.removeRenderProgram(_programObjectGlobalRendering);
_programObjectGlobalRendering = nullptr;
}
}
void ClipMapPatchRenderer::renderPatch(
const Geodetic2& patchSize,
const RenderData& data,
const Ellipsoid& ellipsoid)
{
if (glm::max(patchSize.lat, patchSize.lon) > M_PI / 200) {
renderPatchGlobally(patchSize, data, ellipsoid);
}
else {
renderPatchLocally(patchSize, data, ellipsoid);
}
}
void ClipMapPatchRenderer::renderPatchGlobally(
const Geodetic2& patchSize,
const RenderData& data,
const Ellipsoid& ellipsoid)
{
// activate shader
_programObjectGlobalRendering->activate();
using namespace glm;
mat4 viewTransform = data.camera.combinedViewMatrix();
// TODO : Model transform should be fetched as a matrix directly.
mat4 modelTransform = translate(mat4(1), data.position.vec3());
// Snap patch position
int segmentsPerPatch = _grid->segments();
Geodetic2 stepSize = Geodetic2(
patchSize.lat / segmentsPerPatch,
patchSize.lon / segmentsPerPatch);
ivec2 patchesToCoverGlobe = ivec2(
M_PI / patchSize.lat + 0.5,
M_PI * 2 / patchSize.lon + 0.5);
Geodetic2 cameraPosLatLon = ellipsoid.cartesianToGeodetic2(data.camera.position().dvec3());
ivec2 intSnapCoord = ivec2(
cameraPosLatLon.lat / (M_PI * 2) * segmentsPerPatch * patchesToCoverGlobe.y,
cameraPosLatLon.lon / (M_PI)* segmentsPerPatch * patchesToCoverGlobe.x);
Geodetic2 newPatchCenter = Geodetic2(
stepSize.lat * intSnapCoord.x,
stepSize.lon * intSnapCoord.y);
GeodeticPatch newPatch(
newPatchCenter,
Geodetic2(patchSize.lat / 2, patchSize.lon / 2));
ivec2 contraction = ivec2(intSnapCoord.y % 2, intSnapCoord.x % 2);
// For now just pick the first one from height maps
auto heightMapProviders = _tileProviderManager->getActiveHeightMapProviders();
auto tileProviderHeight = heightMapProviders[0];
PatchCoverage patchCoverageHeight = _patchCoverageProvider.getCoverage(newPatch, tileProviderHeight);
// Bind and use the texture
ghoul::opengl::TextureUnit texUnitHeight00;
texUnitHeight00.activate();
patchCoverageHeight.textureTransformPairs[0].first->bind(); // tile00
_programObjectGlobalRendering->setUniform("textureSamplerHeight00", texUnitHeight00);
ghoul::opengl::TextureUnit texUnitHeight10;
texUnitHeight10.activate();
patchCoverageHeight.textureTransformPairs[1].first->bind(); // tile10
_programObjectGlobalRendering->setUniform("textureSamplerHeight10", texUnitHeight10);
ghoul::opengl::TextureUnit texUnitHeight01;
texUnitHeight01.activate();
patchCoverageHeight.textureTransformPairs[2].first->bind(); // tile01
_programObjectGlobalRendering->setUniform("textureSamplerHeight01", texUnitHeight01);
ghoul::opengl::TextureUnit texUnitHeight11;
texUnitHeight11.activate();
patchCoverageHeight.textureTransformPairs[3].first->bind(); // tile11
_programObjectGlobalRendering->setUniform("textureSamplerHeight11", texUnitHeight11);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileHeight00",
patchCoverageHeight.textureTransformPairs[0].second);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileHeight10",
patchCoverageHeight.textureTransformPairs[1].second);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileHeight01",
patchCoverageHeight.textureTransformPairs[2].second);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileHeight11",
patchCoverageHeight.textureTransformPairs[3].second);
uvec2 texture00DimensionsHeight = patchCoverageHeight.textureTransformPairs[0].first->dimensions().xy();
uvec2 texture10DimensionsHeight = patchCoverageHeight.textureTransformPairs[1].first->dimensions().xy();
uvec2 texture01DimensionsHeight = patchCoverageHeight.textureTransformPairs[2].first->dimensions().xy();
uvec2 texture11DimensionsHeight = patchCoverageHeight.textureTransformPairs[3].first->dimensions().xy();
_programObjectGlobalRendering->setUniform("texture00DimensionsHeight", texture00DimensionsHeight);
_programObjectGlobalRendering->setUniform("texture10DimensionsHeight", texture10DimensionsHeight);
_programObjectGlobalRendering->setUniform("texture01DimensionsHeight", texture01DimensionsHeight);
_programObjectGlobalRendering->setUniform("texture11DimensionsHeight", texture11DimensionsHeight);
// Pick the first color texture
auto colorTextureProviders = _tileProviderManager->getActiveColorTextureProviders();
auto tileProviderColor = colorTextureProviders[0];
PatchCoverage patchCoverageColor = _patchCoverageProvider.getCoverage(newPatch, tileProviderColor);
// Bind and use the texture
ghoul::opengl::TextureUnit texUnitColor00;
texUnitColor00.activate();
patchCoverageColor.textureTransformPairs[0].first->bind(); // tile00
_programObjectGlobalRendering->setUniform("textureSamplerColor00", texUnitColor00);
ghoul::opengl::TextureUnit texUnitColor10;
texUnitColor10.activate();
patchCoverageColor.textureTransformPairs[1].first->bind(); // tile10
_programObjectGlobalRendering->setUniform("textureSamplerColor10", texUnitColor10);
ghoul::opengl::TextureUnit texUnitColor01;
texUnitColor01.activate();
patchCoverageColor.textureTransformPairs[2].first->bind(); // tile01
_programObjectGlobalRendering->setUniform("textureSamplerColor01", texUnitColor01);
ghoul::opengl::TextureUnit texUnitColor11;
texUnitColor11.activate();
patchCoverageColor.textureTransformPairs[3].first->bind(); // tile11
_programObjectGlobalRendering->setUniform("textureSamplerColor11", texUnitColor11);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileColor00",
patchCoverageColor.textureTransformPairs[0].second);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileColor10",
patchCoverageColor.textureTransformPairs[1].second);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileColor01",
patchCoverageColor.textureTransformPairs[2].second);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileColor11",
patchCoverageColor.textureTransformPairs[3].second);
uvec2 texture00DimensionsColor = patchCoverageColor.textureTransformPairs[0].first->dimensions().xy();
uvec2 texture10DimensionsColor = patchCoverageColor.textureTransformPairs[1].first->dimensions().xy();
uvec2 texture01DimensionsColor = patchCoverageColor.textureTransformPairs[2].first->dimensions().xy();
uvec2 texture11DimensionsColor = patchCoverageColor.textureTransformPairs[3].first->dimensions().xy();
_programObjectGlobalRendering->setUniform("texture00DimensionsColor", texture00DimensionsColor);
_programObjectGlobalRendering->setUniform("texture10DimensionsColor", texture10DimensionsColor);
_programObjectGlobalRendering->setUniform("texture01DimensionsColor", texture01DimensionsColor);
_programObjectGlobalRendering->setUniform("texture11DimensionsColor", texture11DimensionsColor);
_programObjectGlobalRendering->setUniform(
"modelViewProjectionTransform",
data.camera.projectionMatrix() * viewTransform * modelTransform);
_programObjectGlobalRendering->setUniform("segmentsPerPatch", segmentsPerPatch);
_programObjectGlobalRendering->setUniform("minLatLon", vec2(newPatch.southWestCorner().toLonLatVec2()));
_programObjectGlobalRendering->setUniform("lonLatScalingFactor", vec2(patchSize.toLonLatVec2()));
_programObjectGlobalRendering->setUniform("radiiSquared", vec3(ellipsoid.radiiSquared()));
_programObjectGlobalRendering->setUniform("contraction", contraction);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// render
_grid->geometry().drawUsingActiveProgram();
// disable shader
_programObjectGlobalRendering->deactivate();
}
void ClipMapPatchRenderer::renderPatchLocally(
const Geodetic2& patchSize,
const RenderData& data,
const Ellipsoid& ellipsoid)
{
// activate shader
_programObjectLocalRendering->activate();
using namespace glm;
mat4 viewTransform = data.camera.combinedViewMatrix();
// TODO : Model transform should be fetched as a matrix directly.
mat4 modelTransform = translate(mat4(1), data.position.vec3());
mat4 modelViewTransform = viewTransform * modelTransform;
// Snap patch position
int segmentsPerPatch = _grid->segments();
Geodetic2 stepSize = Geodetic2(
patchSize.lat / segmentsPerPatch,
patchSize.lon / segmentsPerPatch);
ivec2 patchesToCoverGlobe = ivec2(
M_PI / patchSize.lat + 0.5,
M_PI * 2 / patchSize.lon + 0.5);
Geodetic2 cameraPosLatLon = ellipsoid.cartesianToGeodetic2(data.camera.position().dvec3());
ivec2 intSnapCoord = ivec2(
cameraPosLatLon.lat / (M_PI * 2) * segmentsPerPatch * patchesToCoverGlobe.y,
cameraPosLatLon.lon / (M_PI)* segmentsPerPatch * patchesToCoverGlobe.x);
Geodetic2 newPatchCenter = Geodetic2(
stepSize.lat * intSnapCoord.x,
stepSize.lon * intSnapCoord.y);
GeodeticPatch newPatch(
newPatchCenter,
Geodetic2(patchSize.lat / 2, patchSize.lon / 2));
ivec2 contraction = ivec2(intSnapCoord.y % 2, intSnapCoord.x % 2);
// Get global positions of the four control points
Vec3 patchSw = ellipsoid.cartesianSurfacePosition(newPatch.southWestCorner());
Vec3 patchSe = ellipsoid.cartesianSurfacePosition(newPatch.southEastCorner());
Vec3 patchNw = ellipsoid.cartesianSurfacePosition(newPatch.northWestCorner());
Vec3 patchNe = ellipsoid.cartesianSurfacePosition(newPatch.northEastCorner());
// Transform all control points to camera space
patchSw = Vec3(dmat4(modelViewTransform) * glm::dvec4(patchSw, 1));
patchSe = Vec3(dmat4(modelViewTransform) * glm::dvec4(patchSe, 1));
patchNw = Vec3(dmat4(modelViewTransform) * glm::dvec4(patchNw, 1));
patchNe = Vec3(dmat4(modelViewTransform) * glm::dvec4(patchNe, 1));
// Send control points to shader
_programObjectLocalRendering->setUniform("p00", vec3(patchSw));
_programObjectLocalRendering->setUniform("p10", vec3(patchSe));
_programObjectLocalRendering->setUniform("p01", vec3(patchNw));
_programObjectLocalRendering->setUniform("p11", vec3(patchNe));
vec3 patchNormal = normalize(cross(patchSe - patchSw, patchNw - patchSw));
_programObjectLocalRendering->setUniform("patchNormal", patchNormal);
// For now just pick the first one from height maps
auto heightMapProviders = _tileProviderManager->getActiveHeightMapProviders();
auto tileProviderHeight = heightMapProviders[0];
PatchCoverage patchCoverageHeight = _patchCoverageProvider.getCoverage(newPatch, tileProviderHeight);
// Bind and use the texture
ghoul::opengl::TextureUnit texUnitHeight00;
texUnitHeight00.activate();
patchCoverageHeight.textureTransformPairs[0].first->bind(); // tile00
_programObjectLocalRendering->setUniform("textureSamplerHeight00", texUnitHeight00);
ghoul::opengl::TextureUnit texUnitHeight10;
texUnitHeight10.activate();
patchCoverageHeight.textureTransformPairs[1].first->bind(); // tile10
_programObjectLocalRendering->setUniform("textureSamplerHeight10", texUnitHeight10);
ghoul::opengl::TextureUnit texUnitHeight01;
texUnitHeight01.activate();
patchCoverageHeight.textureTransformPairs[2].first->bind(); // tile01
_programObjectLocalRendering->setUniform("textureSamplerHeight01", texUnitHeight01);
ghoul::opengl::TextureUnit texUnitHeight11;
texUnitHeight11.activate();
patchCoverageHeight.textureTransformPairs[3].first->bind(); // tile11
_programObjectLocalRendering->setUniform("textureSamplerHeight11", texUnitHeight11);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileHeight00",
patchCoverageHeight.textureTransformPairs[0].second);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileHeight10",
patchCoverageHeight.textureTransformPairs[1].second);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileHeight01",
patchCoverageHeight.textureTransformPairs[2].second);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileHeight11",
patchCoverageHeight.textureTransformPairs[3].second);
uvec2 texture00DimensionsHeight = patchCoverageHeight.textureTransformPairs[0].first->dimensions().xy();
uvec2 texture10DimensionsHeight = patchCoverageHeight.textureTransformPairs[1].first->dimensions().xy();
uvec2 texture01DimensionsHeight = patchCoverageHeight.textureTransformPairs[2].first->dimensions().xy();
uvec2 texture11DimensionsHeight = patchCoverageHeight.textureTransformPairs[3].first->dimensions().xy();
_programObjectLocalRendering->setUniform("texture00DimensionsHeight", texture00DimensionsHeight);
_programObjectLocalRendering->setUniform("texture10DimensionsHeight", texture10DimensionsHeight);
_programObjectLocalRendering->setUniform("texture01DimensionsHeight", texture01DimensionsHeight);
_programObjectLocalRendering->setUniform("texture11DimensionsHeight", texture11DimensionsHeight);
// Pick the first color texture
auto colorTextureProviders = _tileProviderManager->getActiveColorTextureProviders();
auto tileProviderColor = colorTextureProviders[0];
PatchCoverage patchCoverageColor = _patchCoverageProvider.getCoverage(newPatch, tileProviderColor);
// Bind and use the texture
ghoul::opengl::TextureUnit texUnitColor00;
texUnitColor00.activate();
patchCoverageColor.textureTransformPairs[0].first->bind(); // tile00
_programObjectLocalRendering->setUniform("textureSamplerColor00", texUnitColor00);
ghoul::opengl::TextureUnit texUnitColor10;
texUnitColor10.activate();
patchCoverageColor.textureTransformPairs[1].first->bind(); // tile10
_programObjectLocalRendering->setUniform("textureSamplerColor10", texUnitColor10);
ghoul::opengl::TextureUnit texUnitColor01;
texUnitColor01.activate();
patchCoverageColor.textureTransformPairs[2].first->bind(); // tile01
_programObjectLocalRendering->setUniform("textureSamplerColor01", texUnitColor01);
ghoul::opengl::TextureUnit texUnitColor11;
texUnitColor11.activate();
patchCoverageColor.textureTransformPairs[3].first->bind(); // tile11
_programObjectLocalRendering->setUniform("textureSamplerColor11", texUnitColor11);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileColor00",
patchCoverageColor.textureTransformPairs[0].second);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileColor10",
patchCoverageColor.textureTransformPairs[1].second);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileColor01",
patchCoverageColor.textureTransformPairs[2].second);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileColor11",
patchCoverageColor.textureTransformPairs[3].second);
uvec2 texture00DimensionsColor = patchCoverageColor.textureTransformPairs[0].first->dimensions().xy();
uvec2 texture10DimensionsColor = patchCoverageColor.textureTransformPairs[1].first->dimensions().xy();
uvec2 texture01DimensionsColor = patchCoverageColor.textureTransformPairs[2].first->dimensions().xy();
uvec2 texture11DimensionsColor = patchCoverageColor.textureTransformPairs[3].first->dimensions().xy();
_programObjectLocalRendering->setUniform("texture00DimensionsColor", texture00DimensionsColor);
_programObjectLocalRendering->setUniform("texture10DimensionsColor", texture10DimensionsColor);
_programObjectLocalRendering->setUniform("texture01DimensionsColor", texture01DimensionsColor);
_programObjectLocalRendering->setUniform("texture11DimensionsColor", texture11DimensionsColor);
_programObjectLocalRendering->setUniform(
"projectionTransform",
data.camera.projectionMatrix());
_programObjectLocalRendering->setUniform("segmentsPerPatch", segmentsPerPatch);
_programObjectLocalRendering->setUniform("contraction", contraction);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
// render
_grid->geometry().drawUsingActiveProgram();
// disable shader
_programObjectLocalRendering->deactivate();
}
} // namespace openspace

View File

@@ -34,10 +34,9 @@
#include <modules/globebrowsing/geodetics/geodetic2.h>
#include <modules/globebrowsing/geodetics/ellipsoid.h>
#include <modules/globebrowsing/meshes/grid.h>
#include <modules/globebrowsing/meshes/clipmapgrid.h>
//#include <modules/globebrowsing/rendering/frustumculler.h>
#include <modules/globebrowsing/other/patchcoverageprovider.h>
#include <modules/globebrowsing/other/tileprovidermanager.h>
#include <modules/globebrowsing/other/layeredtextureshaderprovider.h>
#include <modules/globebrowsing/globes/chunknode.h>
@@ -95,35 +94,6 @@ namespace openspace {
class ClipMapPatchRenderer : public PatchRenderer {
public:
ClipMapPatchRenderer(
shared_ptr<ClipMapGrid> grid,
shared_ptr<TileProviderManager> tileProviderManager);
~ClipMapPatchRenderer();
void renderPatch(
const Geodetic2& patchSize,
const RenderData& data,
const Ellipsoid& ellipsoid);
private:
void renderPatchGlobally(
const Geodetic2& patchSize,
const RenderData& data,
const Ellipsoid& ellipsoid);
void renderPatchLocally(
const Geodetic2& patchSize,
const RenderData& data,
const Ellipsoid& ellipsoid);
unique_ptr<ProgramObject> _programObjectGlobalRendering;
unique_ptr<ProgramObject> _programObjectLocalRendering;
PatchCoverageProvider _patchCoverageProvider;
shared_ptr<ClipMapGrid> _grid;
};
} // namespace openspace

View File

@@ -1,92 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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. *
****************************************************************************************/
/*
// Heightmap coverage
uniform sampler2D textureSamplerHeight00;
uniform sampler2D textureSamplerHeight10;
uniform sampler2D textureSamplerHeight01;
uniform sampler2D textureSamplerHeight11;
uniform mat3 uvTransformPatchToTileHeight00;
uniform mat3 uvTransformPatchToTileHeight10;
uniform mat3 uvTransformPatchToTileHeight01;
uniform mat3 uvTransformPatchToTileHeight11;
*/
// Colortexture coverage
uniform sampler2D textureSamplerColor00;
uniform sampler2D textureSamplerColor10;
uniform sampler2D textureSamplerColor01;
uniform sampler2D textureSamplerColor11;
uniform mat3 uvTransformPatchToTileColor00;
uniform mat3 uvTransformPatchToTileColor10;
uniform mat3 uvTransformPatchToTileColor01;
uniform mat3 uvTransformPatchToTileColor11;
uniform uvec2 texture00DimensionsColor;
uniform uvec2 texture10DimensionsColor;
uniform uvec2 texture01DimensionsColor;
uniform uvec2 texture11DimensionsColor;
//uniform int segmentsPerPatch;
in vec4 vs_position;
in vec3 fs_position;
in vec2 fs_uv;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
Fragment getFragment() {
Fragment frag;
frag.color = vec4(0);
vec4 color00, color10, color01, color11;
vec2 uv00 = vec2(uvTransformPatchToTileColor00 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv10 = vec2(uvTransformPatchToTileColor10 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv01 = vec2(uvTransformPatchToTileColor01 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv11 = vec2(uvTransformPatchToTileColor11 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 d00 = 1 / vec2(texture00DimensionsColor);
vec2 d10 = 1 / vec2(texture10DimensionsColor);
vec2 d01 = 1 / vec2(texture01DimensionsColor);
vec2 d11 = 1 / vec2(texture11DimensionsColor);
if (uv00.x > -d00.x && uv00.x < 1 + d00.x && uv00.y > -d00.y && uv00.y < 1 + d00.y)
color00 = texture(textureSamplerColor00, uv00);
if (uv10.x > -d10.x && uv10.x < 1 + d10.x && uv10.y > -d10.y && uv10.y < 1 + d10.y)
color10 = texture(textureSamplerColor10, uv10);
if (uv01.x > -d01.x && uv01.x < 1 + d01.x && uv01.y > -d01.y && uv01.y < 1 + d01.y)
color01 = texture(textureSamplerColor01, uv01);
if (uv11.x > -d11.x && uv11.x < 1 + d11.x && uv11.y > -d11.y && uv11.y < 1 + d11.y)
color11 = texture(textureSamplerColor11, uv11);
frag.color = max(color00, max(color10, max(color01, color11)));
//frag.color = vec4(frag.color.r, frag.color.r, frag.color.r, 1);
frag.depth = vs_position.w;
return frag;
}

View File

@@ -1,113 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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__
uniform mat4 modelViewProjectionTransform;
uniform vec3 radiiSquared;
uniform vec2 minLatLon;
uniform vec2 lonLatScalingFactor;
uniform ivec2 contraction; // [-1, 1]
uniform int segmentsPerPatch;
uniform sampler2D textureSamplerHeight00;
uniform sampler2D textureSamplerHeight10;
uniform sampler2D textureSamplerHeight01;
uniform sampler2D textureSamplerHeight11;
uniform mat3 uvTransformPatchToTileHeight00;
uniform mat3 uvTransformPatchToTileHeight10;
uniform mat3 uvTransformPatchToTileHeight01;
uniform mat3 uvTransformPatchToTileHeight11;
uniform uvec2 texture00DimensionsHeight;
uniform uvec2 texture10DimensionsHeight;
uniform uvec2 texture01DimensionsHeight;
uniform uvec2 texture11DimensionsHeight;
layout(location = 1) in vec2 in_uv;
out vec4 vs_position;
out vec3 fs_position;
out vec2 fs_uv;
#include "PowerScaling/powerScaling_vs.hglsl"
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
PositionNormalPair globalInterpolation(vec2 uv) {
vec2 lonLatInput;
lonLatInput.y = minLatLon.y + lonLatScalingFactor.y * uv.y; // Lat
lonLatInput.x = minLatLon.x + lonLatScalingFactor.x * uv.x; // Lon
return geodetic2ToCartesian(lonLatInput.y, lonLatInput.x, radiiSquared);;
}
void main()
{
fs_uv = in_uv;
// Contract
vec2 scaledContraction = contraction / float(segmentsPerPatch);
fs_uv += scaledContraction;
fs_uv = clamp(fs_uv, 0, 1);
fs_uv -= scaledContraction;
PositionNormalPair pair = globalInterpolation(fs_uv);
float sampledHeight00 = 0;
float sampledHeight10 = 0;
float sampledHeight01 = 0;
float sampledHeight11 = 0;
vec2 uv00 = vec2(uvTransformPatchToTileHeight00 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv10 = vec2(uvTransformPatchToTileHeight10 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv01 = vec2(uvTransformPatchToTileHeight01 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv11 = vec2(uvTransformPatchToTileHeight11 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 d00 = vec2(1,1) / texture00DimensionsHeight;
vec2 d10 = vec2(1,1) / texture10DimensionsHeight;
vec2 d01 = vec2(1,1) / texture01DimensionsHeight;
vec2 d11 = vec2(1,1) / texture11DimensionsHeight;
if (uv00.x > -d00.x && uv00.x < 1 + d00.x && uv00.y > -d00.y && uv00.y < 1 + d00.y)
sampledHeight00 = texture(textureSamplerHeight00, uv00).r;
if (uv10.x > -d10.x && uv10.x < 1 + d10.x && uv10.y > -d10.y && uv10.y < 1 + d10.y)
sampledHeight10 = texture(textureSamplerHeight10, uv10).r;
if (uv01.x > -d01.x && uv01.x < 1 + d01.x && uv01.y > -d01.y && uv01.y < 1 + d01.y)
sampledHeight01 = texture(textureSamplerHeight01, uv01).r;
if (uv11.x > -d11.x && uv11.x < 1 + d11.x && uv11.y > -d11.y && uv11.y < 1 + d11.y)
sampledHeight11 = texture(textureSamplerHeight11, uv11).r;
float sampledHeight = max(sampledHeight00, max(sampledHeight10, max(sampledHeight01, sampledHeight11)));
pair.position += pair.normal * sampledHeight * pow(2,15);
vec4 position = modelViewProjectionTransform * vec4(pair.position, 1);
fs_position = pair.position;
gl_Position = z_normalization(position);
vs_position = gl_Position;
}

View File

@@ -1,92 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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. *
****************************************************************************************/
/*
// Heightmap coverage
uniform sampler2D textureSamplerHeight00;
uniform sampler2D textureSamplerHeight10;
uniform sampler2D textureSamplerHeight01;
uniform sampler2D textureSamplerHeight11;
uniform mat3 uvTransformPatchToTileHeight00;
uniform mat3 uvTransformPatchToTileHeight10;
uniform mat3 uvTransformPatchToTileHeight01;
uniform mat3 uvTransformPatchToTileHeight11;
*/
// Colortexture coverage
uniform sampler2D textureSamplerColor00;
uniform sampler2D textureSamplerColor10;
uniform sampler2D textureSamplerColor01;
uniform sampler2D textureSamplerColor11;
uniform mat3 uvTransformPatchToTileColor00;
uniform mat3 uvTransformPatchToTileColor10;
uniform mat3 uvTransformPatchToTileColor01;
uniform mat3 uvTransformPatchToTileColor11;
uniform uvec2 texture00DimensionsColor;
uniform uvec2 texture10DimensionsColor;
uniform uvec2 texture01DimensionsColor;
uniform uvec2 texture11DimensionsColor;
//uniform int segmentsPerPatch;
in vec4 vs_position;
in vec3 fs_position;
in vec2 fs_uv;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
Fragment getFragment() {
Fragment frag;
frag.color = vec4(0);
vec4 color00, color10, color01, color11;
vec2 uv00 = vec2(uvTransformPatchToTileColor00 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv10 = vec2(uvTransformPatchToTileColor10 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv01 = vec2(uvTransformPatchToTileColor01 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv11 = vec2(uvTransformPatchToTileColor11 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 d00 = vec2(1,1) / texture00DimensionsColor;
vec2 d10 = vec2(1,1) / texture10DimensionsColor;
vec2 d01 = vec2(1,1) / texture01DimensionsColor;
vec2 d11 = vec2(1,1) / texture11DimensionsColor;
if (uv00.x > -d00.x && uv00.x < 1 + d00.x && uv00.y > -d00.y && uv00.y < 1 + d00.y)
color00 = texture(textureSamplerColor00, uv00);
if (uv10.x > -d10.x && uv10.x < 1 + d10.x && uv10.y > -d10.y && uv10.y < 1 + d10.y)
color10 = texture(textureSamplerColor10, uv10);
if (uv01.x > -d01.x && uv01.x < 1 + d01.x && uv01.y > -d01.y && uv01.y < 1 + d01.y)
color01 = texture(textureSamplerColor01, uv01);
if (uv11.x > -d11.x && uv11.x < 1 + d11.x && uv11.y > -d11.y && uv11.y < 1 + d11.y)
color11 = texture(textureSamplerColor11, uv11);
frag.color = max(color00, max(color10, max(color01, color11)));
//frag.color = vec4(frag.color.r, frag.color.r, 0, 1);
frag.depth = vs_position.w;
return frag;
}

View File

@@ -1,117 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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__
uniform mat4 projectionTransform;
uniform ivec2 contraction; // [-1, 1]
uniform vec3 p00;
uniform vec3 p10;
uniform vec3 p01;
uniform vec3 p11;
uniform vec3 patchNormal;
uniform int segmentsPerPatch;
uniform mat3 uvTransformPatchToTileHeight00;
uniform mat3 uvTransformPatchToTileHeight10;
uniform mat3 uvTransformPatchToTileHeight01;
uniform mat3 uvTransformPatchToTileHeight11;
uniform sampler2D textureSamplerHeight00;
uniform sampler2D textureSamplerHeight10;
uniform sampler2D textureSamplerHeight01;
uniform sampler2D textureSamplerHeight11;
uniform uvec2 texture00DimensionsHeight;
uniform uvec2 texture10DimensionsHeight;
uniform uvec2 texture01DimensionsHeight;
uniform uvec2 texture11DimensionsHeight;
layout(location = 1) in vec2 in_uv;
out vec4 vs_position;
out vec3 fs_position;
out vec2 fs_uv;
#include "PowerScaling/powerScaling_vs.hglsl"
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
vec3 bilinearInterpolation(vec2 uv) {
// Bilinear interpolation
vec3 p0 = (1 - uv.x) * p00 + uv.x * p10;
vec3 p1 = (1 - uv.x) * p01 + uv.x * p11;
vec3 p = (1 - uv.y) * p0 + uv.y * p1;
return p;
}
void main()
{
fs_uv = in_uv;
// Contract
vec2 scaledContraction = contraction / float(segmentsPerPatch);
fs_uv += scaledContraction;
fs_uv = clamp(fs_uv, 0, 1);
fs_uv -= scaledContraction;
// Position in cameraspace
vec3 p = bilinearInterpolation(fs_uv);
float sampledHeight00 = 0;
float sampledHeight10 = 0;
float sampledHeight01 = 0;
float sampledHeight11 = 0;
vec2 uv00 = vec2(uvTransformPatchToTileHeight00 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv10 = vec2(uvTransformPatchToTileHeight10 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv01 = vec2(uvTransformPatchToTileHeight01 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 uv11 = vec2(uvTransformPatchToTileHeight11 * vec3(fs_uv.s, fs_uv.t, 1));
vec2 d00 = vec2(1,1) / texture00DimensionsHeight;
vec2 d10 = vec2(1,1) / texture10DimensionsHeight;
vec2 d01 = vec2(1,1) / texture01DimensionsHeight;
vec2 d11 = vec2(1,1) / texture11DimensionsHeight;
if (uv00.x > -d00.x && uv00.x < 1 + d00.x && uv00.y > -d00.y && uv00.y < 1 + d00.y)
sampledHeight00 = texture(textureSamplerHeight00, uv00).r;
if (uv10.x > -d10.x && uv10.x < 1 + d10.x && uv10.y > -d10.y && uv10.y < 1 + d10.y)
sampledHeight10 = texture(textureSamplerHeight10, uv10).r;
if (uv01.x > -d01.x && uv01.x < 1 + d01.x && uv01.y > -d01.y && uv01.y < 1 + d01.y)
sampledHeight01 = texture(textureSamplerHeight01, uv01).r;
if (uv11.x > -d11.x && uv11.x < 1 + d11.x && uv11.y > -d11.y && uv11.y < 1 + d11.y)
sampledHeight11 = texture(textureSamplerHeight11, uv11).r;
float sampledHeight = max(sampledHeight00, max(sampledHeight10, max(sampledHeight01, sampledHeight11)));
p += patchNormal * sampledHeight * pow(2,15);
vec4 position = projectionTransform * vec4(p, 1);
fs_position = p;
gl_Position = z_normalization(position);
vs_position = gl_Position;
}

View File

@@ -1,71 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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 <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE];
in vec4 fs_position;
in vec2 fs_uv;
vec4 blendOver(vec4 oldColor, vec4 newColor)
{
vec4 toReturn;
toReturn.rgb =
(newColor.rgb * newColor.a + oldColor.rgb * oldColor.a * (1 - newColor.a)) /
(newColor.a + oldColor.a * (1 - newColor.a));
toReturn.a = newColor.a + oldColor.a * (1 - newColor.a);
return toReturn;
}
Fragment getFragment() {
Fragment frag;
for (int i = 0; i < NUMLAYERS_COLORTEXTURE; ++i)
{
vec2 samplePos =
colorTile.uvTransform.uvScale * fs_uv +
colorTile.uvTransform.uvOffset;
vec4 colorSample = texture(colorTile.textureSampler, samplePos);
frag.color = blendOver(frag.color, colorSample);
}
//frag.color.rgb *= 10;
// Sample position overlay
//frag.color = frag.color * 0.9 + 0.2*vec4(samplePos, 0, 1);
// Border overlay
//frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02);
frag.depth = fs_position.w;
return frag;
}

View File

@@ -1,83 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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"
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
#define NUMLAYERS_COLORTEXTURE #{numLayersColor}
#define NUMLAYERS_HEIGHTMAP #{numLayersHeight}
uniform mat4 modelViewProjectionTransform;
uniform vec3 radiiSquared;
uniform vec2 minLatLon;
uniform vec2 lonLatScalingFactor;
uniform TextureTile heightTiles[NUMLAYERS_HEIGHTMAP];
layout(location = 1) in vec2 in_uv;
out vec2 fs_uv;
out vec4 fs_position;
PositionNormalPair globalInterpolation() {
vec2 lonLatInput;
lonLatInput.y = minLatLon.y + lonLatScalingFactor.y * in_uv.y; // Lat
lonLatInput.x = minLatLon.x + lonLatScalingFactor.x * in_uv.x; // Lon
PositionNormalPair positionPairModelSpace = geodetic2ToCartesian(lonLatInput.y, lonLatInput.x, radiiSquared);
return positionPairModelSpace;
}
void main()
{
PositionNormalPair pair = globalInterpolation();
float height = 0;
for (int i = 0; i < NUMLAYERS_HEIGHTMAP; ++i)
{
vec2 samplePos =
heightTiles[i].uvTransform.uvScale * in_uv +
heightTiles[i].uvTransform.uvOffset;
float sampledValue = texture(heightTiles[i].textureSampler, samplePos).r;
// TODO : Some kind of blending here. Now it just writes over
height = (sampledValue *
heightTiles[i].depthTransform.depthScale +
heightTiles[i].depthTransform.depthOffset);
}
// Add the height in the direction of the normal
pair.position += pair.normal * height;
vec4 position = modelViewProjectionTransform * vec4(pair.position, 1);
// Write output
fs_uv = in_uv;
fs_position = z_normalization(position);
gl_Position = fs_position;
}

View File

@@ -1,101 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
uniform 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;
/*
// Heightmap coverage
uniform sampler2D textureSamplerHeight00;
uniform sampler2D textureSamplerHeight10;
uniform sampler2D textureSamplerHeight01;
uniform sampler2D textureSamplerHeight11;
uniform mat3 uvTransformPatchToTileHeight00;
uniform mat3 uvTransformPatchToTileHeight10;
uniform mat3 uvTransformPatchToTileHeight01;
uniform mat3 uvTransformPatchToTileHeight11;
*/
// Colortexture coverage
uniform sampler2D textureSamplerColor00;
uniform sampler2D textureSamplerColor10;
uniform sampler2D textureSamplerColor01;
uniform sampler2D textureSamplerColor11;
uniform mat3 uvTransformPatchToTileColor00;
uniform mat3 uvTransformPatchToTileColor10;
uniform mat3 uvTransformPatchToTileColor01;
uniform mat3 uvTransformPatchToTileColor11;
//uniform int segmentsPerPatch;
in vec4 vs_position;
in vec3 fs_position;
in vec2 fs_uv;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
Fragment getFragment() {
Fragment frag;
frag.color = vec4(0);
vec4 color00, color10, color01, color11;
vec2 uv00 = vec2(uvTransformPatchToTileColor00 * vec3(fs_uv.s, fs_uv.t, 1));
color00 = texture(textureSamplerColor00, uv00);
vec2 uv10 = vec2(uvTransformPatchToTileColor10 * vec3(fs_uv.s, fs_uv.t, 1));
color10 += texture(textureSamplerColor10, uv10);
vec2 uv01 = vec2(uvTransformPatchToTileColor01 * vec3(fs_uv.s, fs_uv.t, 1));
color01 += texture(textureSamplerColor01, uv01);
vec2 uv11 = vec2(uvTransformPatchToTileColor11 * vec3(fs_uv.s, fs_uv.t, 1));
color11 += texture(textureSamplerColor11, uv11);
frag.color = max(color00, max(color10, max(color01, color11))) * 10;
//vec4 uvColor = vec4(fract(fs_uv * segmentsPerPatch), 0.4,1);
//frag.color = frag.color.a < 0.1 ? uvColor * 0.5 : frag.color;
frag.color = vec4(frag.color.r, frag.color.r, frag.color.r, 1);
frag.depth = vs_position.w;
return frag;
}

View File

@@ -1,48 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014 *
* *
* 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__
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
layout(location = 0) in vec4 in_position;
out vec4 vs_position;
out vec2 vs_uv;
#include "PowerScaling/powerScaling_vs.hglsl"
void main()
{
// set variables
vs_position = vec4(in_position.xyz * 60000000.0f, 1);
vec4 tmp = vec4(in_position.xyz * 60000000.0f, 1);
vec4 position = pscTransform(tmp, ModelTransform);
vs_position = tmp;
vs_uv = vec2(0,0);
position = ViewProjection * position;
gl_Position = z_normalization(position);
}

View File

@@ -40,7 +40,7 @@ namespace gui {
void GuiTimeComponent::render() {
float deltaTime = static_cast<float>(Time::ref().deltaTime());
bool changed = ImGui::SliderFloat("Delta Time", &deltaTime, -100.f, 100.f);
bool changed = ImGui::SliderFloat("Delta Time", &deltaTime, -500000.f, 500000.f);
if (changed)
OsEng.scriptEngine().queueScript("openspace.time.setDeltaTime(" + std::to_string(deltaTime) + ")");

View File

@@ -37,6 +37,45 @@ namespace openspace {
Time* Time::_instance = nullptr;
Time::Time()
: _time(-1.0)
, _dt(1.0)
//local copies
, _timeJumped(false)
, _timePaused(false)
, _jockeHasToFixThisLater(false)
//shared copies
, _sharedTime(-1.0)
, _sharedDt(1.0)
, _sharedTimeJumped(false)
//synced copies
, _syncedTime(-1.0)
, _syncedDt(1.0)
, _syncedTimeJumped(false)
{
}
Time::Time(const Time& other)
: _time(other._time)
, _dt(other._dt)
//local copies
, _timeJumped(other._timeJumped)
, _timePaused(other._timePaused)
, _jockeHasToFixThisLater(other._jockeHasToFixThisLater)
//shared copies
, _sharedTime(other._sharedTime)
, _sharedDt(other._sharedDt)
, _sharedTimeJumped(other._sharedTimeJumped)
//synced copies
, _syncedTime(other._syncedTime)
, _syncedDt(other._syncedDt)
, _syncedTimeJumped(other._syncedTimeJumped)
{
}
void Time::initialize() {
ghoul_assert(_instance == nullptr, "Static time must not have been ininitialized");
_instance = new Time();
@@ -99,6 +138,29 @@ std::string Time::currentTimeUTC() const {
return SpiceManager::ref().dateFromEphemerisTime(_syncedTime);
}
std::string Time::ISO8601() const {
std::string datetime = currentTimeUTC();
std::string month = datetime.substr(5, 3);
std::string MM = "";
if (month == "JAN") MM = "01";
else if (month == "FEB") MM = "02";
else if (month == "MAR") MM = "03";
else if (month == "APR") MM = "04";
else if (month == "MAY") MM = "05";
else if (month == "JUN") MM = "06";
else if (month == "JUL") MM = "07";
else if (month == "AUG") MM = "08";
else if (month == "SEP") MM = "09";
else if (month == "OCT") MM = "10";
else if (month == "NOV") MM = "11";
else if (month == "DEC") MM = "12";
else ghoul_assert(false, "Bad month");
datetime.replace(4, 5, "-" + MM + "-");
return datetime;
}
void Time::serialize(SyncBuffer* syncBuffer) {
_syncMutex.lock();