mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-18 02:49:03 -06:00
Account for tile pixel start offset and size difference when calculating height on globe.
This commit is contained in:
@@ -305,7 +305,12 @@ namespace globebrowsing {
|
||||
if (tile.status != Tile::Status::OK) {
|
||||
return 0;
|
||||
}
|
||||
glm::vec2 transformedUv = uvTransform.uvOffset + uvTransform.uvScale * patchUV;
|
||||
//glm::vec2 transformedUv = uvTransform.uvOffset + uvTransform.uvScale * patchUV;
|
||||
|
||||
glm::vec2 transformedUv = Tile::TileUvToTextureSamplePosition(
|
||||
uvTransform,
|
||||
patchUV,
|
||||
glm::uvec2(tile.texture->dimensions()));
|
||||
|
||||
// Sample and do linear interpolation
|
||||
// (could possibly be moved as a function in ghoul texture)
|
||||
|
||||
@@ -25,6 +25,12 @@
|
||||
#ifndef TEXTURETILE_HGLSL
|
||||
#define TEXTURETILE_HGLSL
|
||||
|
||||
// Must match the values in tiledataset.cpp
|
||||
// (could be set as shader preprocessing data so that multiple definitions
|
||||
// are not needed)
|
||||
#define TILE_PIXEL_START_OFFSET ivec2(-2)
|
||||
#define TILE_PIXEL_SIZE_DIFFERENCE ivec2(4)
|
||||
|
||||
vec4 patchBorderOverlay(vec2 uv, vec3 borderColor, float borderSize) {
|
||||
vec2 uvOffset = uv - vec2(0.5);
|
||||
float thres = 0.5 - borderSize/2;
|
||||
@@ -83,7 +89,8 @@ vec2 compensateSourceTextureSampling(vec2 startOffset, vec2 sizeDiff, const Tile
|
||||
|
||||
vec2 TileUVToTextureSamplePosition(const Tile tile, vec2 tileUV){
|
||||
vec2 uv = tile.uvTransform.uvOffset + tile.uvTransform.uvScale * tileUV;
|
||||
uv = compensateSourceTextureSampling(vec2(-2), vec2(4), tile, uv);
|
||||
uv = compensateSourceTextureSampling(
|
||||
TILE_PIXEL_START_OFFSET, TILE_PIXEL_SIZE_DIFFERENCE, tile, uv);
|
||||
return uv;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,5 +66,30 @@ namespace globebrowsing {
|
||||
return tile;
|
||||
}
|
||||
|
||||
glm::vec2 Tile::compensateSourceTextureSampling(
|
||||
glm::vec2 startOffset,
|
||||
glm::vec2 sizeDiff,
|
||||
glm::uvec2 resolution,
|
||||
glm::vec2 tileUV) {
|
||||
glm::vec2 sourceSize = glm::vec2(resolution) + sizeDiff;
|
||||
glm::vec2 currentSize = glm::vec2(resolution);
|
||||
glm::vec2 sourceToCurrentSize = currentSize / sourceSize;
|
||||
tileUV = sourceToCurrentSize * (tileUV - startOffset / sourceSize);
|
||||
return tileUV;
|
||||
}
|
||||
|
||||
glm::vec2 Tile::TileUvToTextureSamplePosition(
|
||||
const TileUvTransform uvTransform,
|
||||
glm::vec2 tileUV,
|
||||
glm::uvec2 resolution) {
|
||||
glm::vec2 uv = uvTransform.uvOffset + uvTransform.uvScale * tileUV;
|
||||
uv = compensateSourceTextureSampling(
|
||||
TileDataset::tilePixelStartOffset,
|
||||
TileDataset::tilePixelSizeDifference,
|
||||
resolution,
|
||||
uv);
|
||||
return uv;
|
||||
}
|
||||
|
||||
} // namespace globebrowsing
|
||||
} // namespace openspace
|
||||
} // namespace openspace
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct TileUvTransform {
|
||||
glm::vec2 uvOffset;
|
||||
glm::vec2 uvScale;
|
||||
};
|
||||
|
||||
using namespace ghoul::opengl;
|
||||
|
||||
/**
|
||||
@@ -84,6 +89,17 @@ namespace globebrowsing {
|
||||
*/
|
||||
static Tile createPlainTile(const glm::uvec2& size, const glm::uvec4& color);
|
||||
|
||||
static glm::vec2 compensateSourceTextureSampling(
|
||||
glm::vec2 startOffset,
|
||||
glm::vec2 sizeDiff,
|
||||
glm::uvec2 resolution,
|
||||
glm::vec2 tileUV);
|
||||
|
||||
static glm::vec2 TileUvToTextureSamplePosition(
|
||||
const TileUvTransform uvTransform,
|
||||
glm::vec2 tileUV,
|
||||
glm::uvec2 resolution);
|
||||
|
||||
/**
|
||||
* A tile with status unavailable that any user can return to
|
||||
* indicate that a tile was unavailable.
|
||||
|
||||
@@ -34,11 +34,6 @@
|
||||
namespace openspace {
|
||||
namespace globebrowsing {
|
||||
|
||||
struct TileUvTransform {
|
||||
glm::vec2 uvOffset;
|
||||
glm::vec2 uvScale;
|
||||
};
|
||||
|
||||
struct TileAndTransform {
|
||||
Tile tile;
|
||||
TileUvTransform uvTransform;
|
||||
|
||||
Reference in New Issue
Block a user