mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 20:21:24 -06:00
Merge branch 'feature/globebrowsing' of github.com:OpenSpace/OpenSpace into feature/globebrowsing
This commit is contained in:
@@ -52,18 +52,23 @@ namespace globebrowsing {
|
||||
|
||||
Vec3 cameraPosition =
|
||||
glm::dvec3(inverseModelTransform * glm::dvec4(data.camera.positionVec3(), 1));
|
||||
|
||||
Geodetic2 pointOnPatch = chunk.surfacePatch().closestPoint(
|
||||
ellipsoid.cartesianToGeodetic2(cameraPosition));
|
||||
Vec3 patchNormal = ellipsoid.geodeticSurfaceNormal(pointOnPatch);
|
||||
Vec3 patchPosition = ellipsoid.cartesianSurfacePosition(pointOnPatch);
|
||||
|
||||
Chunk::BoundingHeights heights = chunk.getBoundingHeights();
|
||||
Scalar heightToChunk = heights.min;
|
||||
|
||||
Vec3 patchPosition = ellipsoid.cartesianSurfacePosition(pointOnPatch);
|
||||
// Offset position according to height
|
||||
patchPosition += patchNormal * heightToChunk;
|
||||
|
||||
Vec3 cameraToChunk = patchPosition - cameraPosition;
|
||||
|
||||
|
||||
// Calculate desired level based on distance
|
||||
Scalar distanceToPatch = glm::length(cameraToChunk);
|
||||
Scalar distance = distanceToPatch -heights.min; // distance to actual minimum heights
|
||||
Scalar distance = distanceToPatch;
|
||||
|
||||
Scalar scaleFactor = globe.generalProperties().lodScaleFactor * ellipsoid.minimumRadius();
|
||||
Scalar projectedScaleFactor = scaleFactor / distance;
|
||||
|
||||
@@ -335,6 +335,7 @@ namespace globebrowsing {
|
||||
// The length of the skirts is proportional to its size
|
||||
programObject->setUniform("skirtLength", min(static_cast<float>(chunk.surfacePatch().halfSize().lat * 1000000), 8700.0f));
|
||||
programObject->setUniform("xSegments", _grid->xSegments());
|
||||
programObject->setUniform("chunkMinHeight", chunk.getBoundingHeights().min);
|
||||
|
||||
if (chunk.owner().debugProperties().showHeightResolution) {
|
||||
programObject->setUniform("vertexResolution", glm::vec2(_grid->xSegments(), _grid->ySegments()));
|
||||
|
||||
@@ -37,6 +37,7 @@ uniform vec3 radiiSquared;
|
||||
uniform vec2 minLatLon;
|
||||
uniform vec2 lonLatScalingFactor;
|
||||
uniform vec3 cameraPosition;
|
||||
uniform float chunkMinHeight;
|
||||
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
@@ -56,9 +57,14 @@ PositionNormalPair globalInterpolation() {
|
||||
|
||||
void main() {
|
||||
PositionNormalPair pair = globalInterpolation();
|
||||
float distToVertexOnEllipsoid = length(pair.position - cameraPosition);
|
||||
float distToVertexOnEllipsoid =
|
||||
length(pair.position + pair.normal * chunkMinHeight - cameraPosition);
|
||||
|
||||
float levelInterpolationParameter = getLevelInterpolationParameter(chunkLevel, distanceScaleFactor, distToVertexOnEllipsoid);
|
||||
float levelInterpolationParameter =
|
||||
getLevelInterpolationParameter(
|
||||
chunkLevel,
|
||||
distanceScaleFactor,
|
||||
distToVertexOnEllipsoid);
|
||||
|
||||
// use level weight for height sampling, and output to fragment shader
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
|
||||
@@ -39,6 +39,7 @@ uniform vec3 p10;
|
||||
uniform vec3 p01;
|
||||
uniform vec3 p11;
|
||||
uniform vec3 patchNormalCameraSpace;
|
||||
uniform float chunkMinHeight;
|
||||
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
@@ -62,9 +63,14 @@ void main() {
|
||||
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
float distToVertexOnEllipsoid = length(p);
|
||||
float levelInterpolationParameter = getLevelInterpolationParameter(chunkLevel, distanceScaleFactor, distToVertexOnEllipsoid);
|
||||
|
||||
float distToVertexOnEllipsoid =
|
||||
length(p + patchNormalCameraSpace * chunkMinHeight);
|
||||
float levelInterpolationParameter =
|
||||
getLevelInterpolationParameter(
|
||||
chunkLevel,
|
||||
distanceScaleFactor,
|
||||
distToVertexOnEllipsoid);
|
||||
|
||||
// use level weight for height sampling, and output to fragment shader
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
|
||||
|
||||
@@ -438,8 +438,24 @@ namespace globebrowsing {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
std::array<double, 6> TileDataset::getGeoTransform() const {
|
||||
std::array<double, 6> padfTransform;
|
||||
CPLErr err = _dataset->GetGeoTransform(&padfTransform[0]);
|
||||
if (err == CE_Failure) {
|
||||
GeodeticPatch globalCoverage(Geodetic2(0,0), Geodetic2(M_PI / 2, M_PI));
|
||||
padfTransform[1] = Angle<Scalar>::fromRadians(
|
||||
globalCoverage.size().lon).asDegrees() / _dataset->GetRasterXSize();
|
||||
padfTransform[5] = -Angle<Scalar>::fromRadians(
|
||||
globalCoverage.size().lat).asDegrees() / _dataset->GetRasterYSize();
|
||||
padfTransform[0] = Angle<Scalar>::fromRadians(
|
||||
globalCoverage.getCorner(Quad::NORTH_WEST).lon).asDegrees();
|
||||
padfTransform[3] = Angle<Scalar>::fromRadians(
|
||||
globalCoverage.getCorner(Quad::NORTH_WEST).lat).asDegrees();
|
||||
padfTransform[2] = 0;
|
||||
padfTransform[4] = 0;
|
||||
}
|
||||
return padfTransform;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// ReadTileData helper functions //
|
||||
@@ -447,11 +463,8 @@ namespace globebrowsing {
|
||||
|
||||
PixelCoordinate TileDataset::geodeticToPixel(const Geodetic2& geo) const {
|
||||
|
||||
double padfTransform[6];
|
||||
CPLErr err = _dataset->GetGeoTransform(padfTransform);
|
||||
|
||||
ghoul_assert(err != CE_Failure, "Failed to get transform");
|
||||
|
||||
std::array<double, 6> padfTransform = getGeoTransform();
|
||||
|
||||
Scalar Y = Angle<Scalar>::fromRadians(geo.lat).asDegrees();
|
||||
Scalar X = Angle<Scalar>::fromRadians(geo.lon).asDegrees();
|
||||
|
||||
@@ -484,10 +497,9 @@ namespace globebrowsing {
|
||||
}
|
||||
|
||||
Geodetic2 TileDataset::pixelToGeodetic(const PixelCoordinate& p) const {
|
||||
double padfTransform[6];
|
||||
CPLErr err = _dataset->GetGeoTransform(padfTransform);
|
||||
ghoul_assert(err != CE_Failure, "Failed to get transform");
|
||||
std::array<double, 6> padfTransform = getGeoTransform();
|
||||
Geodetic2 geodetic;
|
||||
// Should be using radians and not degrees?
|
||||
geodetic.lon = padfTransform[0] + p.x * padfTransform[1] + p.y * padfTransform[2];
|
||||
geodetic.lat = padfTransform[3] + p.x * padfTransform[4] + p.y * padfTransform[5];
|
||||
return geodetic;
|
||||
|
||||
@@ -147,6 +147,15 @@ namespace globebrowsing {
|
||||
// ReadTileData helper functions //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
Returns the geo transform from raster space to projection coordinates as defined
|
||||
by GDAL.
|
||||
|
||||
If the transform is not available, the function returns a transform to map
|
||||
the pixel coordinates to cover the whole geodetic lat long space.
|
||||
*/
|
||||
std::array<double, 6> getGeoTransform() const;
|
||||
|
||||
PixelCoordinate geodeticToPixel(const Geodetic2& geo) const;
|
||||
Geodetic2 pixelToGeodetic(const PixelCoordinate& p) const;
|
||||
IODescription getIODescription(const TileIndex& tileIndex) const;
|
||||
@@ -189,4 +198,4 @@ namespace globebrowsing {
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
|
||||
#endif // __TILE_DATASET_H__
|
||||
#endif // __TILE_DATASET_H__
|
||||
|
||||
Reference in New Issue
Block a user