mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 20:21:24 -06:00
Render vertex and heightmap resolution. Fix offsetted pixel read bug in TileDataset
This commit is contained in:
@@ -282,6 +282,10 @@ namespace openspace {
|
||||
programObject->setUniform("skirtLength", min(static_cast<float>(chunk.surfacePatch().halfSize().lat * 1000000), 8700.0f));
|
||||
programObject->setUniform("xSegments", _grid->xSegments());
|
||||
|
||||
if (tileProviders[LayeredTextures::ColorTextures].size() == 0) {
|
||||
programObject->setUniform("vertexResolution", glm::vec2(_grid->xSegments(), _grid->ySegments()));
|
||||
}
|
||||
|
||||
return programObject;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,12 @@
|
||||
|
||||
#include "fragment.glsl"
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
uniform Tile HeightMaps[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent2[NUMLAYERS_HEIGHTMAP];
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#if USE_COLORTEXTURE
|
||||
uniform Tile ColorTextures[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile ColorTexturesParent1[NUMLAYERS_COLORTEXTURE];
|
||||
@@ -58,6 +64,9 @@ uniform Tile WaterMasksParent1[NUMLAYERS_WATERMASK];
|
||||
uniform Tile WaterMasksParent2[NUMLAYERS_WATERMASK];
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
uniform vec2 vertexResolution;
|
||||
|
||||
|
||||
#if USE_ATMOSPHERE
|
||||
// TODO atmosphere uniforms here
|
||||
#endif // USE_ATMOSPHERE
|
||||
@@ -83,8 +92,12 @@ Fragment getFragment() {
|
||||
ColorTexturesParent2);
|
||||
|
||||
#else
|
||||
vec2 vertexResolution = vec2(64.0);
|
||||
frag.color = calculateDebugColor(fs_uv, fs_position, vertexResolution);
|
||||
vec2 heightResolution = vec2(1,1);
|
||||
#if USE_HEIGHTMAP
|
||||
heightResolution = vec2(textureSize(HeightMaps[0].textureSampler,0));
|
||||
#endif
|
||||
|
||||
frag.color = calculateDebugColor(fs_uv, fs_position, vertexResolution, heightResolution);
|
||||
#endif // USE_COLORTEXTURE
|
||||
|
||||
#if USE_GRAYSCALE_OVERLAY
|
||||
|
||||
@@ -27,6 +27,12 @@
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
uniform Tile HeightMaps[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent2[NUMLAYERS_HEIGHTMAP];
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#if USE_COLORTEXTURE
|
||||
uniform Tile ColorTextures[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile ColorTexturesParent1[NUMLAYERS_COLORTEXTURE];
|
||||
@@ -57,6 +63,8 @@ uniform Tile WaterMasksParent1[NUMLAYERS_WATERMASK];
|
||||
uniform Tile WaterMasksParent2[NUMLAYERS_WATERMASK];
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
uniform vec2 vertexResolution;
|
||||
|
||||
// levelInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// The value increases with the distance from the vertex (or fragment) to the camera
|
||||
in LevelWeights levelWeights;
|
||||
@@ -79,8 +87,11 @@ Fragment getFragment() {
|
||||
ColorTexturesParent1,
|
||||
ColorTexturesParent2);
|
||||
#else
|
||||
vec2 vertexResolution = vec2(64.0);
|
||||
frag.color = calculateDebugColor(fs_uv, fs_position, vertexResolution);
|
||||
vec2 heightResolution = vec2(1,1);
|
||||
#if USE_HEIGHTMAP
|
||||
heightResolution = vec2(textureSize(HeightMaps[0].textureSampler,0));
|
||||
#endif
|
||||
frag.color = calculateDebugColor(fs_uv, fs_position, vertexResolution, heightResolution);
|
||||
#endif // USE_COLORTEXTURE
|
||||
|
||||
|
||||
|
||||
@@ -129,12 +129,12 @@ float gridDots(vec2 uv, vec2 gridResolution){
|
||||
return 1-length(1-uvDotSpace);
|
||||
}
|
||||
|
||||
vec4 calculateDebugColor(vec2 uv, vec4 fragPos, vec2 vertexResolution){
|
||||
vec4 calculateDebugColor(vec2 uv, vec4 fragPos, vec2 vertexResolution, vec2 heightResolution){
|
||||
vec2 uvVertexSpace = fract(vertexResolution * uv);
|
||||
vec3 colorUv = vec3(0.3*uv.x, 0.3*uv.y, 0);
|
||||
vec3 colorDistance = vec3(0, 0, min( 0.4*log(fragPos.w) - 3.9, 1));
|
||||
vec3 colorVertex = (1.0-length(uvVertexSpace)) * vec3(0.5);
|
||||
vec3 colorHeightSample = (gridDots(uv, vertexResolution) > 0.9 ? 1 : 0) * vec3(1,0,0);
|
||||
vec3 colorHeightSample = (gridDots(uv, heightResolution) > 0.9 ? 1 : 0) * vec3(1,0,0);
|
||||
vec3 colorSum = colorUv + colorDistance + colorVertex + colorHeightSample;
|
||||
return vec4(0.5 * colorSum, 1);
|
||||
}
|
||||
|
||||
@@ -71,20 +71,31 @@ struct Tile {
|
||||
TileUvTransform uvTransform;
|
||||
};
|
||||
|
||||
vec2 compensateSourceTextureSampling(vec2 startOffset, vec2 endOffset, const Tile tile, vec2 tileUV){
|
||||
vec2 offset = endOffset - startOffset;
|
||||
vec2 compensateSourceTextureSampling(vec2 startOffset, vec2 sizeDiff, const Tile tile, vec2 tileUV){
|
||||
ivec2 resolution = textureSize(tile.textureSampler, 0);
|
||||
|
||||
vec2 sourceSize = vec2(resolution) + offset;
|
||||
vec2 sourceSize = vec2(resolution) + sizeDiff;
|
||||
vec2 currentSize = vec2(resolution);
|
||||
vec2 oldToNewScale = currentSize / sourceSize;
|
||||
tileUV = oldToNewScale * tileUV + startOffset / sourceSize;
|
||||
vec2 sourceToCurrentSize = currentSize / sourceSize;
|
||||
tileUV = sourceToCurrentSize * (tileUV - startOffset / sourceSize);
|
||||
return tileUV;
|
||||
}
|
||||
|
||||
|
||||
vec2 compensateSourceTextureSampling2(vec2 startOffset, vec2 sizeDiff, const Tile tile, vec2 tileUV){
|
||||
vec2 pixelSizeUV = 1 / (textureSize(tile.textureSampler, 0) + sizeDiff);
|
||||
|
||||
tileUV *= (1 - pixelSizeUV* 2);
|
||||
tileUV += pixelSizeUV;
|
||||
|
||||
return tileUV;
|
||||
}
|
||||
|
||||
vec4 getTexVal(const Tile tile, vec2 tileUV){
|
||||
vec2 samplePos = tile.uvTransform.uvOffset + tile.uvTransform.uvScale * tileUV;
|
||||
vec4 texVal = texture(tile.textureSampler, samplePos);
|
||||
tileUV = tile.uvTransform.uvOffset + tile.uvTransform.uvScale * tileUV;
|
||||
tileUV = compensateSourceTextureSampling(vec2(-1), vec2(2), tile, tileUV);
|
||||
//tileUV = compensateSourceTextureSampling2(vec2(-1), vec2(2), tile, tileUV);
|
||||
vec4 texVal = texture(tile.textureSampler, tileUV);
|
||||
return texVal;
|
||||
}
|
||||
|
||||
|
||||
@@ -182,12 +182,14 @@ namespace openspace {
|
||||
// Tile Dataset //
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const glm::ivec2 TileDataset::tilePixelStartOffset = glm::ivec2(-1, -1);
|
||||
const glm::ivec2 TileDataset::tilePixelSizeDifference = glm::ivec2(2, 2);
|
||||
|
||||
bool TileDataset::GdalHasBeenInitialized = false;
|
||||
|
||||
TileDataset::TileDataset(const std::string& gdalDatasetDesc, int minimumPixelSize,
|
||||
bool doPreprocessing, GLuint dataType)
|
||||
: _minimumPixelSize(minimumPixelSize)
|
||||
, _doPreprocessing(doPreprocessing)
|
||||
: _doPreprocessing(doPreprocessing)
|
||||
, _maxLevel(-1)
|
||||
{
|
||||
if (!GdalHasBeenInitialized) {
|
||||
@@ -284,16 +286,17 @@ namespace openspace {
|
||||
|
||||
char* dataDestination = imageData + (i * _dataLayout.bytesPerDatum);
|
||||
|
||||
int pixelStartX = region.pixelStart.x * pixelSourceScale;
|
||||
int pixelStartY = region.pixelStart.y * pixelSourceScale;
|
||||
int pixelWidthX = region.numPixels.x * pixelSourceScale;
|
||||
int pixelWidthY = region.numPixels.y * pixelSourceScale;
|
||||
int pixelStartX = region.pixelStart.x * pixelSourceScale + tilePixelStartOffset.x;
|
||||
int pixelStartY = region.pixelStart.y * pixelSourceScale + tilePixelStartOffset.y;
|
||||
int pixelWidthX = region.numPixels.x * pixelSourceScale + tilePixelSizeDifference.x;
|
||||
int pixelWidthY = region.numPixels.y * pixelSourceScale + tilePixelSizeDifference.y;
|
||||
|
||||
|
||||
// Clamp to be inside dataset
|
||||
pixelStartX = glm::max(pixelStartX, 0);
|
||||
pixelStartY = glm::max(pixelStartY, 0);
|
||||
pixelWidthX = glm::min(pixelStartX + pixelWidthX, rasterBand->GetXSize()) - pixelStartX;
|
||||
pixelWidthY = glm::min(pixelStartY + pixelWidthY, rasterBand->GetYSize()) - pixelStartY;
|
||||
//pixelStartX = glm::max(pixelStartX, 0);
|
||||
//pixelStartY = glm::max(pixelStartY, 0);
|
||||
//pixelWidthX = glm::min(pixelStartX + pixelWidthX, rasterBand->GetXSize()) - pixelStartX;
|
||||
//pixelWidthY = glm::min(pixelStartY + pixelWidthY, rasterBand->GetYSize()) - pixelStartY;
|
||||
|
||||
CPLErr err = rasterBand->RasterIO(
|
||||
GF_Read,
|
||||
|
||||
@@ -102,6 +102,9 @@ namespace openspace {
|
||||
TileDepthTransform getDepthTransform() const;
|
||||
const TileDataLayout& getDataLayout() const;
|
||||
|
||||
const static glm::ivec2 tilePixelStartOffset;
|
||||
const static glm::ivec2 tilePixelSizeDifference;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -131,7 +134,6 @@ namespace openspace {
|
||||
|
||||
static bool GdalHasBeenInitialized;
|
||||
|
||||
int _minimumPixelSize;
|
||||
int _maxLevel;
|
||||
double _tileLevelDifference;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user