Using scaling and offset for heightmap based on dataset.

This commit is contained in:
Kalle Bladin
2016-05-12 11:06:49 -04:00
parent 41865bdc92
commit 4e95aaab82
9 changed files with 67 additions and 28 deletions

View File

@@ -97,10 +97,11 @@ namespace openspace {
return WANT_MERGE;
}
auto center = _surfacePatch.center();
Vec3 globePosition = data.position.dvec3();
Vec3 patchPosition = globePosition + ellipsoid.geodetic2ToCartesian(center);
Vec3 cameraPosition = data.camera.position().dvec3();
Geodetic2 pointOnPatch = _surfacePatch.closestPoint(
ellipsoid.cartesianToGeodetic2(cameraPosition));
Vec3 globePosition = data.position.dvec3();
Vec3 patchPosition = globePosition + ellipsoid.geodetic2ToCartesian(pointOnPatch);
Vec3 cameraToChunk = patchPosition - cameraPosition;
Scalar minimumGlobeRadius = ellipsoid.minimumRadius();

View File

@@ -100,15 +100,15 @@ namespace openspace {
int xSize = rasterBand->GetXSize();
int ySize = rasterBand->GetYSize();
CPLErr err = rasterBand->RasterIO(
CPLErr err = rasterBand->RasterIO(
GF_Read,
pixelStart.x, // Begin read x
pixelStart.y, // Begin read y
numPixels.x, // width to read x
numPixels.y, // width to read y
numPixels.x, // width to read x
numPixels.y, // width to read y
imageData + i, // Where to put data
numPixels.x, // width to write x in destination
numPixels.y, // width to write y in destination
numPixels.x, // width to write x in destination
numPixels.y, // width to write y in destination
gdalType, // Type
sizeof(T) * nRasters, // Pixel spacing
0); // Line spacing
@@ -129,13 +129,13 @@ namespace openspace {
delete[] imageData;
glm::uvec3 dims(numPixels.x, numPixels.y, 1);
UninitializedTextureTile::TextureFormat textrureFormat =
UninitializedTextureTile::TextureFormat textureFormat =
getTextureFormat(nRasters, gdalType);
GLuint glType = getGlDataTypeFromGdalDataType(gdalType);
UninitializedTextureTile* uninitedTexPtr = new UninitializedTextureTile(
imageDataYflipped,
dims,
textrureFormat,
textureFormat,
glType,
chunkIndex);
std::shared_ptr<UninitializedTextureTile> uninitedTex =

View File

@@ -91,6 +91,13 @@ namespace openspace {
int sizeLevel0 = firstBand->GetOverview(numOverviews - 1)->GetXSize();
_tileLevelDifference = log2(minimumPixelSize) - log2(sizeLevel0);
GDALDataType gdalType = firstBand->GetRasterDataType();
double maximumValue = (gdalType == GDT_Float32 || gdalType == GDT_Float64) ?
1.0 : firstBand->GetMaximum();
_depthTransform.depthOffset = firstBand->GetOffset();
_depthTransform.depthScale = firstBand->GetScale() * maximumValue;
}
TileProvider::~TileProvider(){
@@ -169,7 +176,7 @@ namespace openspace {
}
}
return { tex, uvOffset, uvScale };
return{ tex, {uvOffset, uvScale } };
}
std::shared_ptr<Texture> TileProvider::getOrStartFetchingTile(ChunkIndex chunkIndex) {
@@ -198,6 +205,11 @@ namespace openspace {
return _defaultTexture;
}
TileTextureDepthTransform TileProvider::depthTransform() {
return _depthTransform;
}
std::shared_ptr<UninitializedTextureTile> TileProvider::getUninitializedTextureTile(
const ChunkIndex& chunkIndex) {

View File

@@ -46,7 +46,13 @@
namespace openspace {
using namespace ghoul::opengl;
struct TileTextureTransform
struct TileTextureDepthTransform
{
float depthScale;
float depthOffset;
};
struct TileTextureUvTransform
{
glm::vec2 uvOffset;
glm::vec2 uvScale;
@@ -54,7 +60,7 @@ namespace openspace {
struct Tile {
std::shared_ptr<Texture> texture;
TileTextureTransform transform;
TileTextureUvTransform uvTransform;
};
/**
@@ -69,8 +75,8 @@ namespace openspace {
Tile getMostHiResTile(ChunkIndex chunkIndex);
std::shared_ptr<Texture> getOrStartFetchingTile(ChunkIndex chunkIndex);
std::shared_ptr<Texture> getDefaultTexture();
TileTextureDepthTransform depthTransform();
void prerender();
@@ -110,6 +116,7 @@ namespace openspace {
std::shared_ptr<Texture> _defaultTexture;
int _tileLevelDifference;
TileTextureDepthTransform _depthTransform;
};
} // namespace openspace

View File

@@ -92,13 +92,13 @@ namespace openspace {
, _grid(grid)
{
_programObjectGlobalRendering = OsEng.renderEngine().buildRenderProgram(
"GlobalClipMapPatch",
"GlobalChunkedLodPatch",
"${MODULE_GLOBEBROWSING}/shaders/globalchunkedlodpatch_vs.glsl",
"${MODULE_GLOBEBROWSING}/shaders/globalchunkedlodpatch_fs.glsl");
ghoul_assert(_programObjectGlobalRendering != nullptr, "Failed to initialize programObject!");
_programObjectLocalRendering = OsEng.renderEngine().buildRenderProgram(
"LocalClipMapPatch",
"LocalChunkedLodPatch",
"${MODULE_GLOBEBROWSING}/shaders/localchunkedlodpatch_vs.glsl",
"${MODULE_GLOBEBROWSING}/shaders/localchunkedlodpatch_fs.glsl");
ghoul_assert(_programObjectLocalRendering != nullptr, "Failed to initialize programObject!");
@@ -113,7 +113,7 @@ namespace openspace {
const Ellipsoid& ellipsoid,
const RenderData& data)
{
if (chunk.index().level < 10) {
if (chunk.index().level < 9) {
renderChunkGlobally(chunk, ellipsoid, data);
}
else {
@@ -152,8 +152,8 @@ namespace openspace {
heightTile.texture->bind();
_programObjectGlobalRendering->setUniform("textureSamplerHeight", texUnitHeight);
_programObjectGlobalRendering->setUniform("heightSamplingScale", heightTile.transform.uvScale);
_programObjectGlobalRendering->setUniform("heightSamplingOffset", heightTile.transform.uvOffset);
_programObjectGlobalRendering->setUniform("heightSamplingScale", heightTile.uvTransform.uvScale);
_programObjectGlobalRendering->setUniform("heightSamplingOffset", heightTile.uvTransform.uvOffset);
@@ -168,9 +168,12 @@ namespace openspace {
texUnitColor.activate();
colorTile.texture->bind();
_programObjectGlobalRendering->setUniform("textureSamplerColor", texUnitColor);
_programObjectGlobalRendering->setUniform("colorSamplingScale", colorTile.transform.uvScale);
_programObjectGlobalRendering->setUniform("colorSamplingOffset", colorTile.transform.uvOffset);
_programObjectGlobalRendering->setUniform("colorSamplingScale", colorTile.uvTransform.uvScale);
_programObjectGlobalRendering->setUniform("colorSamplingOffset", colorTile.uvTransform.uvOffset);
TileTextureDepthTransform depthTransformHeight = tileProviderHeight->depthTransform();
_programObjectGlobalRendering->setUniform("heightSamplingDepthScale", depthTransformHeight.depthScale);
_programObjectGlobalRendering->setUniform("heightSamplingDepthOffset", depthTransformHeight.depthOffset);
Geodetic2 swCorner = chunk.surfacePatch().southWestCorner();
auto patchSize = chunk.surfacePatch().size();
@@ -219,8 +222,12 @@ namespace openspace {
texUnitHeight.activate();
heightTile.texture->bind();
_programObjectLocalRendering->setUniform("textureSamplerHeight", texUnitHeight);
_programObjectLocalRendering->setUniform("heightSamplingScale", heightTile.transform.uvScale);
_programObjectLocalRendering->setUniform("heightSamplingOffset", heightTile.transform.uvOffset);
_programObjectLocalRendering->setUniform("heightSamplingScale", heightTile.uvTransform.uvScale);
_programObjectLocalRendering->setUniform("heightSamplingOffset", heightTile.uvTransform.uvOffset);
TileTextureDepthTransform depthTransformHeight = tileProviderHeight->depthTransform();
_programObjectLocalRendering->setUniform("heightSamplingDepthScale", depthTransformHeight.depthScale);
_programObjectLocalRendering->setUniform("heightSamplingDepthOffset", depthTransformHeight.depthOffset);
// Pick the first color texture
auto colorTextureProviders = _tileProviderManager->colorTextureProviders();
@@ -233,8 +240,8 @@ namespace openspace {
texUnitColor.activate();
colorTile.texture->bind();
_programObjectLocalRendering->setUniform("textureSamplerColor", texUnitColor);
_programObjectLocalRendering->setUniform("colorSamplingScale", colorTile.transform.uvScale);
_programObjectLocalRendering->setUniform("colorSamplingOffset", colorTile.transform.uvOffset);
_programObjectLocalRendering->setUniform("colorSamplingScale", colorTile.uvTransform.uvScale);
_programObjectLocalRendering->setUniform("colorSamplingOffset", colorTile.uvTransform.uvOffset);
Geodetic2 sw = chunk.surfacePatch().southWestCorner();
@@ -263,6 +270,7 @@ namespace openspace {
vec3 patchNormalCameraSpace = normalize(
cross(patchSeCameraSpace - patchSwCameraSpace,
patchNwCameraSpace - patchSwCameraSpace));
_programObjectLocalRendering->setUniform(
"patchNormalCameraSpace",
patchNormalCameraSpace);

View File

@@ -50,6 +50,7 @@ Fragment getFragment() {
vec2 samplePos = colorSamplingScale*fs_uv + colorSamplingOffset;
frag.color = texture(textureSamplerColor, samplePos);
//frag.color.rgb *= 10;
// Sample position overlay
//frag.color = frag.color * 0.9 + 0.2*vec4(samplePos, 0, 1);

View File

@@ -34,6 +34,9 @@ uniform sampler2D textureSamplerHeight;
uniform vec2 heightSamplingScale;
uniform vec2 heightSamplingOffset;
uniform float heightSamplingDepthScale;
uniform float heightSamplingDepthOffset;
layout(location = 1) in vec2 in_UV;
out vec4 vs_position;
@@ -57,7 +60,9 @@ void main()
vec2 samplePos = heightSamplingScale*in_UV + heightSamplingOffset;
float sampledHeight = texture(textureSamplerHeight, samplePos).r;
pair.position += pair.normal * sampledHeight * pow(2,15);
if (sampledHeight < 0)
sampledHeight *= -10000000;
pair.position += pair.normal * (sampledHeight * heightSamplingDepthScale + heightSamplingDepthOffset);
vec4 position = modelViewProjectionTransform * vec4(pair.position, 1);

View File

@@ -46,6 +46,8 @@ Fragment getFragment() {
vec2 samplePos = colorSamplingScale * fs_uv + colorSamplingOffset;
frag.color = texture(textureSamplerColor, samplePos);// + vec4(0.5,0,0,0);
//frag.color.rgb *= 10;
// Sample position overlay
//frag.color = frag.color * 0.9 + 0.2*vec4(samplePos, 0, 1);

View File

@@ -39,6 +39,9 @@ uniform sampler2D textureSamplerHeight;
uniform vec2 heightSamplingScale;
uniform vec2 heightSamplingOffset;
uniform float heightSamplingDepthScale;
uniform float heightSamplingDepthOffset;
layout(location = 1) in vec2 in_uv;
out vec2 fs_uv;
@@ -66,9 +69,9 @@ void main()
vec2 samplePos = heightSamplingScale * in_uv + heightSamplingOffset;
float sampledHeight = texture(textureSamplerHeight, samplePos).r;
// Translate the point along normal
p += patchNormalCameraSpace * sampledHeight * pow(2,15);
p += patchNormalCameraSpace * (sampledHeight * heightSamplingDepthScale + heightSamplingDepthOffset);
vec4 positionClippingSpace = projectionTransform * vec4(p, 1);