This commit is contained in:
Erik Broberg
2016-05-13 15:19:37 -04:00
11 changed files with 179 additions and 107 deletions

View File

@@ -98,6 +98,7 @@ source_group("Source Files" FILES ${SOURCE_FILES})
set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/shaders/ellipsoid.hglsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/texturetile.hglsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalchunkedlodpatch_vs.glsl
${CMAKE_CURRENT_SOURCE_DIR}/shaders/globalchunkedlodpatch_fs.glsl

View File

@@ -106,14 +106,11 @@ namespace openspace {
}
auto center = _surfacePatch.center();
Vec3 globePosition = myRenderData.position.dvec3();
Vec3 patchPosition = globePosition + ellipsoid.cartesianSurfacePosition(center);
Vec3 cameraPosition = myRenderData.camera.position().dvec3();
Geodetic2 pointOnPatch = _surfacePatch.closestPoint(
ellipsoid.cartesianToGeodetic2(cameraPosition));
Vec3 globePosition = myRenderData.position.dvec3();
Vec3 patchPosition = globePosition + ellipsoid.cartesianSurfacePosition(pointOnPatch);
Vec3 cameraToChunk = patchPosition - cameraPosition;

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;
}
TileDepthTransform 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 TileDepthTransform
{
float depthScale;
float depthOffset;
};
struct TileUvTransform
{
glm::vec2 uvOffset;
glm::vec2 uvScale;
@@ -54,7 +60,7 @@ namespace openspace {
struct Tile {
std::shared_ptr<Texture> texture;
TileTextureTransform transform;
TileUvTransform uvTransform;
};
/**
@@ -69,8 +75,8 @@ namespace openspace {
Tile getMostHiResTile(ChunkIndex chunkIndex);
std::shared_ptr<Texture> getOrStartFetchingTile(ChunkIndex chunkIndex);
std::shared_ptr<Texture> getDefaultTexture();
TileDepthTransform depthTransform();
void prerender();
@@ -110,6 +116,7 @@ namespace openspace {
std::shared_ptr<Texture> _defaultTexture;
int _tileLevelDifference;
TileDepthTransform _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 {
@@ -150,11 +150,14 @@ namespace openspace {
ghoul::opengl::TextureUnit texUnitHeight;
texUnitHeight.activate();
heightTile.texture->bind();
_programObjectGlobalRendering->setUniform("textureSamplerHeight", texUnitHeight);
_programObjectGlobalRendering->setUniform("heightTile.textureSampler", texUnitHeight);
_programObjectGlobalRendering->setUniform("heightSamplingScale", heightTile.transform.uvScale);
_programObjectGlobalRendering->setUniform("heightSamplingOffset", heightTile.transform.uvOffset);
_programObjectGlobalRendering->setUniform("heightTile.uvTransform.uvScale", heightTile.uvTransform.uvScale);
_programObjectGlobalRendering->setUniform("heightTile.uvTransform.uvOffset", heightTile.uvTransform.uvOffset);
TileDepthTransform depthTransformHeight = tileProviderHeight->depthTransform();
_programObjectGlobalRendering->setUniform("heightTile.depthTransform.depthScale", depthTransformHeight.depthScale);
_programObjectGlobalRendering->setUniform("heightTile.depthTransform.depthOffset", depthTransformHeight.depthOffset);
// Pick the first color texture
@@ -167,10 +170,9 @@ namespace openspace {
ghoul::opengl::TextureUnit texUnitColor;
texUnitColor.activate();
colorTile.texture->bind();
_programObjectGlobalRendering->setUniform("textureSamplerColor", texUnitColor);
_programObjectGlobalRendering->setUniform("colorSamplingScale", colorTile.transform.uvScale);
_programObjectGlobalRendering->setUniform("colorSamplingOffset", colorTile.transform.uvOffset);
_programObjectGlobalRendering->setUniform("colorTile.textureSampler", texUnitColor);
_programObjectGlobalRendering->setUniform("colorTile.uvTransform.uvScale", colorTile.uvTransform.uvScale);
_programObjectGlobalRendering->setUniform("colorTile.uvTransform.uvOffset", colorTile.uvTransform.uvOffset);
Geodetic2 swCorner = chunk.surfacePatch().southWestCorner();
auto patchSize = chunk.surfacePatch().size();
@@ -218,9 +220,13 @@ namespace openspace {
ghoul::opengl::TextureUnit texUnitHeight;
texUnitHeight.activate();
heightTile.texture->bind();
_programObjectLocalRendering->setUniform("textureSamplerHeight", texUnitHeight);
_programObjectLocalRendering->setUniform("heightSamplingScale", heightTile.transform.uvScale);
_programObjectLocalRendering->setUniform("heightSamplingOffset", heightTile.transform.uvOffset);
_programObjectLocalRendering->setUniform("heightTile.textureSampler", texUnitHeight);
_programObjectLocalRendering->setUniform("heightTile.uvTransform.uvScale", heightTile.uvTransform.uvScale);
_programObjectLocalRendering->setUniform("heightTile.uvTransform.uvOffset", heightTile.uvTransform.uvOffset);
TileDepthTransform depthTransformHeight = tileProviderHeight->depthTransform();
_programObjectLocalRendering->setUniform("heightTile.depthTransform.depthScale", depthTransformHeight.depthScale);
_programObjectLocalRendering->setUniform("heightTile.depthTransform.depthOffset", depthTransformHeight.depthOffset);
// Pick the first color texture
auto colorTextureProviders = _tileProviderManager->colorTextureProviders();
@@ -232,9 +238,9 @@ namespace openspace {
ghoul::opengl::TextureUnit texUnitColor;
texUnitColor.activate();
colorTile.texture->bind();
_programObjectLocalRendering->setUniform("textureSamplerColor", texUnitColor);
_programObjectLocalRendering->setUniform("colorSamplingScale", colorTile.transform.uvScale);
_programObjectLocalRendering->setUniform("colorSamplingOffset", colorTile.transform.uvOffset);
_programObjectLocalRendering->setUniform("colorTile.textureSampler", texUnitColor);
_programObjectLocalRendering->setUniform("colorTile.uvTransform.uvScale", colorTile.uvTransform.uvScale);
_programObjectLocalRendering->setUniform("colorTile.uvTransform.uvOffset", colorTile.uvTransform.uvOffset);
Geodetic2 sw = chunk.surfacePatch().southWestCorner();
@@ -263,6 +269,7 @@ namespace openspace {
vec3 patchNormalCameraSpace = normalize(
cross(patchSeCameraSpace - patchSwCameraSpace,
patchNwCameraSpace - patchSwCameraSpace));
_programObjectLocalRendering->setUniform(
"patchNormalCameraSpace",
patchNormalCameraSpace);

View File

@@ -22,42 +22,32 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
// Colortexture coverage
uniform sampler2D textureSamplerColor;
uniform vec2 colorSamplingScale;
uniform vec2 colorSamplingOffset;
in vec4 vs_position;
in vec3 fs_position;
in vec2 fs_uv;
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
vec4 borderOverlay(vec2 uv, vec3 borderColor, float borderSize){
vec2 uvOffset = uv - vec2(0.5);
float thres = 0.5 - borderSize/2;
bool isBorder = abs(uvOffset.x) > thres || abs(uvOffset.y) > thres;
vec3 color = isBorder ? borderColor : vec3(0);
return vec4(color, 0);
}
uniform TextureTile colorTile;
in vec4 fs_position;
in vec2 fs_uv;
Fragment getFragment() {
Fragment frag;
vec2 samplePos = colorSamplingScale*fs_uv + colorSamplingOffset;
frag.color = texture(textureSamplerColor, samplePos);
vec2 samplePos =
colorTile.uvTransform.uvScale * fs_uv +
colorTile.uvTransform.uvOffset;
frag.color = texture(colorTile.textureSampler, samplePos);
//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 + borderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02);
frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02);
frag.depth = vs_position.w;
frag.depth = fs_position.w;
return frag;
}

View File

@@ -24,43 +24,51 @@
#version __CONTEXT__
#include "PowerScaling/powerScaling_vs.hglsl"
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
uniform mat4 modelViewProjectionTransform;
uniform vec3 radiiSquared;
uniform vec2 minLatLon;
uniform vec2 lonLatScalingFactor;
uniform sampler2D textureSamplerHeight;
uniform vec2 heightSamplingScale;
uniform vec2 heightSamplingOffset;
uniform TextureTile heightTile;
layout(location = 1) in vec2 in_UV;
layout(location = 1) in vec2 in_uv;
out vec4 vs_position;
out vec2 fs_uv;
#include "PowerScaling/powerScaling_vs.hglsl"
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
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
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()
{
fs_uv = in_UV;
PositionNormalPair pair = globalInterpolation();
vec2 samplePos = heightSamplingScale*in_UV + heightSamplingOffset;
float sampledHeight = texture(textureSamplerHeight, samplePos).r;
pair.position += pair.normal * sampledHeight * pow(2,15);
vec2 samplePos =
heightTile.uvTransform.uvScale * in_uv +
heightTile.uvTransform.uvOffset;
float sampledHeight = texture(heightTile.textureSampler, samplePos).r;
pair.position +=
pair.normal *
(sampledHeight *
heightTile.depthTransform.depthScale +
heightTile.depthTransform.depthOffset);
vec4 position = modelViewProjectionTransform * vec4(pair.position, 1);
vs_position = z_normalization(position);
gl_Position = vs_position;
// Write output
fs_uv = in_uv;
fs_position = z_normalization(position);
gl_Position = fs_position;
}

View File

@@ -22,36 +22,30 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
// Colortexture coverage
uniform sampler2D textureSamplerColor;
uniform vec2 colorSamplingScale;
uniform vec2 colorSamplingOffset;
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
uniform TextureTile colorTile;
in vec4 fs_position;
in vec2 fs_uv;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
vec4 borderOverlay(vec2 uv, vec3 borderColor, float borderSize){
vec2 uvOffset = uv - vec2(0.5);
float thres = 0.5 - borderSize/2;
bool isBorder = abs(uvOffset.x) > thres || abs(uvOffset.y) > thres;
vec3 color = isBorder ? borderColor : vec3(0);
return vec4(color, 0);
}
Fragment getFragment() {
Fragment frag;
vec2 samplePos = colorSamplingScale * fs_uv + colorSamplingOffset;
frag.color = texture(textureSamplerColor, samplePos);// + vec4(0.5,0,0,0);
vec2 samplePos =
colorTile.uvTransform.uvScale * fs_uv +
colorTile.uvTransform.uvOffset;
frag.color = texture(colorTile.textureSampler, samplePos);
//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 + borderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02);
frag.color = frag.color + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02);
frag.depth = fs_position.w;

View File

@@ -25,6 +25,10 @@
#version __CONTEXT__
#include "PowerScaling/powerScaling_vs.hglsl"
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
#include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl>
uniform mat4 projectionTransform;
// Input points in camera space
@@ -32,21 +36,15 @@ uniform vec3 p00;
uniform vec3 p10;
uniform vec3 p01;
uniform vec3 p11;
uniform vec3 patchNormalCameraSpace;
uniform sampler2D textureSamplerHeight;
uniform vec2 heightSamplingScale;
uniform vec2 heightSamplingOffset;
uniform TextureTile heightTile;
layout(location = 1) in vec2 in_uv;
out vec2 fs_uv;
out vec4 fs_position;
#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;
@@ -57,21 +55,26 @@ vec3 bilinearInterpolation(vec2 uv) {
void main()
{
fs_uv = in_uv;
// Position in cameraspace
vec3 p = bilinearInterpolation(fs_uv);
vec3 p = bilinearInterpolation(in_uv);
// Transform uv coordinates to texture space
vec2 samplePos = heightSamplingScale * in_uv + heightSamplingOffset;
float sampledHeight = texture(textureSamplerHeight, samplePos).r;
vec2 samplePos =
heightTile.uvTransform.uvScale * in_uv +
heightTile.uvTransform.uvOffset;
float sampledHeight = texture(heightTile.textureSampler, samplePos).r;
// Translate the point along normal
p += patchNormalCameraSpace * sampledHeight * pow(2,15);
p += patchNormalCameraSpace *
(sampledHeight *
heightTile.depthTransform.depthScale +
heightTile.depthTransform.depthOffset);
vec4 positionClippingSpace = projectionTransform * vec4(p, 1);
gl_Position = z_normalization(positionClippingSpace);
fs_position = gl_Position;
// Write output
fs_uv = in_uv;
fs_position = z_normalization(positionClippingSpace);
gl_Position = fs_position;
}

View File

@@ -0,0 +1,53 @@
/*****************************************************************************************
* *
* 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. *
****************************************************************************************/
#ifndef TEXTURETILE_HGLSL
#define TEXTURETILE_HGLSL
struct TileDepthTransform {
float depthScale;
float depthOffset;
};
struct TileUvTransform {
vec2 uvOffset;
vec2 uvScale;
};
struct TextureTile {
sampler2D textureSampler;
TileDepthTransform depthTransform;
TileUvTransform uvTransform;
};
vec4 patchBorderOverlay(vec2 uv, vec3 borderColor, float borderSize) {
vec2 uvOffset = uv - vec2(0.5);
float thres = 0.5 - borderSize/2;
bool isBorder = abs(uvOffset.x) > thres || abs(uvOffset.y) > thres;
vec3 color = isBorder ? borderColor : vec3(0);
return vec4(color, 0);
}
#endif // TEXTURETILE_HGLSL