Fix problem with edges between tiles in clipmap rendering.

This commit is contained in:
Kalle Bladin
2016-05-04 21:42:51 -04:00
parent cc4c035f6b
commit 338dfcfe4c
6 changed files with 142 additions and 62 deletions

View File

@@ -196,16 +196,12 @@ namespace openspace {
uninitedTexture->texFormat.glFormat,
uninitedTexture->glType,
Texture::FilterMode::Linear,
Texture::WrappingMode::ClampToBorder);
Texture::WrappingMode::ClampToEdge);
// The texture should take ownership of the data
std::shared_ptr<Texture> texture = std::shared_ptr<Texture>(tex);
texture->uploadTexture();
/*
texture->setWrapping(ghoul::opengl::Texture::WrappingMode::ClampToBorder);
texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear);
*/
return texture;
}

View File

@@ -267,53 +267,59 @@ namespace openspace {
// For now just pick the first one from height maps
auto heightMapProviders = _tileProviderManager->heightMapProviders();
auto tileProviderHeight = heightMapProviders.begin()->second;
PatchCoverage patchCoverage = _patchCoverageProvider.getCoverage(newPatch, tileProviderHeight);
PatchCoverage patchCoverageHeight = _patchCoverageProvider.getCoverage(newPatch, tileProviderHeight);
// Bind and use the texture
ghoul::opengl::TextureUnit texUnitHeight00;
texUnitHeight00.activate();
patchCoverage.textureTransformPairs[0].first->bind(); // tile00
patchCoverageHeight.textureTransformPairs[0].first->bind(); // tile00
_programObjectGlobalRendering->setUniform("textureSamplerHeight00", texUnitHeight00);
ghoul::opengl::TextureUnit texUnitHeight10;
texUnitHeight10.activate();
patchCoverage.textureTransformPairs[1].first->bind(); // tile10
patchCoverageHeight.textureTransformPairs[1].first->bind(); // tile10
_programObjectGlobalRendering->setUniform("textureSamplerHeight10", texUnitHeight10);
ghoul::opengl::TextureUnit texUnitHeight01;
texUnitHeight01.activate();
patchCoverage.textureTransformPairs[2].first->bind(); // tile01
patchCoverageHeight.textureTransformPairs[2].first->bind(); // tile01
_programObjectGlobalRendering->setUniform("textureSamplerHeight01", texUnitHeight01);
ghoul::opengl::TextureUnit texUnitHeight11;
texUnitHeight11.activate();
patchCoverage.textureTransformPairs[3].first->bind(); // tile11
patchCoverageHeight.textureTransformPairs[3].first->bind(); // tile11
_programObjectGlobalRendering->setUniform("textureSamplerHeight11", texUnitHeight11);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileHeight00",
patchCoverage.textureTransformPairs[0].second);
patchCoverageHeight.textureTransformPairs[0].second);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileHeight10",
patchCoverage.textureTransformPairs[1].second);
patchCoverageHeight.textureTransformPairs[1].second);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileHeight01",
patchCoverage.textureTransformPairs[2].second);
patchCoverageHeight.textureTransformPairs[2].second);
_programObjectGlobalRendering->setUniform(
"uvTransformPatchToTileHeight11",
patchCoverage.textureTransformPairs[3].second);
patchCoverageHeight.textureTransformPairs[3].second);
uvec2 texture00DimensionsHeight = patchCoverageHeight.textureTransformPairs[0].first->dimensions().xy;
uvec2 texture10DimensionsHeight = patchCoverageHeight.textureTransformPairs[1].first->dimensions().xy;
uvec2 texture01DimensionsHeight = patchCoverageHeight.textureTransformPairs[2].first->dimensions().xy;
uvec2 texture11DimensionsHeight = patchCoverageHeight.textureTransformPairs[3].first->dimensions().xy;
_programObjectGlobalRendering->setUniform("texture00DimensionsHeight", texture00DimensionsHeight);
_programObjectGlobalRendering->setUniform("texture10DimensionsHeight", texture10DimensionsHeight);
_programObjectGlobalRendering->setUniform("texture01DimensionsHeight", texture01DimensionsHeight);
_programObjectGlobalRendering->setUniform("texture11DimensionsHeight", texture11DimensionsHeight);
@@ -358,6 +364,15 @@ namespace openspace {
patchCoverageColor.textureTransformPairs[3].second);
uvec2 texture00DimensionsColor = patchCoverageColor.textureTransformPairs[0].first->dimensions().xy;
uvec2 texture10DimensionsColor = patchCoverageColor.textureTransformPairs[1].first->dimensions().xy;
uvec2 texture01DimensionsColor = patchCoverageColor.textureTransformPairs[2].first->dimensions().xy;
uvec2 texture11DimensionsColor = patchCoverageColor.textureTransformPairs[3].first->dimensions().xy;
_programObjectGlobalRendering->setUniform("texture00DimensionsColor", texture00DimensionsColor);
_programObjectGlobalRendering->setUniform("texture10DimensionsColor", texture10DimensionsColor);
_programObjectGlobalRendering->setUniform("texture01DimensionsColor", texture01DimensionsColor);
_programObjectGlobalRendering->setUniform("texture11DimensionsColor", texture11DimensionsColor);
@@ -443,47 +458,54 @@ namespace openspace {
// For now just pick the first one from height maps
auto heightMapProviders = _tileProviderManager->heightMapProviders();
auto tileProviderHeight = heightMapProviders.begin()->second;
PatchCoverage patchCoverage = _patchCoverageProvider.getCoverage(newPatch, tileProviderHeight);
PatchCoverage patchCoverageHeight = _patchCoverageProvider.getCoverage(newPatch, tileProviderHeight);
// Bind and use the texture
ghoul::opengl::TextureUnit texUnitHeight00;
texUnitHeight00.activate();
patchCoverage.textureTransformPairs[0].first->bind(); // tile00
patchCoverageHeight.textureTransformPairs[0].first->bind(); // tile00
_programObjectLocalRendering->setUniform("textureSamplerHeight00", texUnitHeight00);
ghoul::opengl::TextureUnit texUnitHeight10;
texUnitHeight10.activate();
patchCoverage.textureTransformPairs[1].first->bind(); // tile10
patchCoverageHeight.textureTransformPairs[1].first->bind(); // tile10
_programObjectLocalRendering->setUniform("textureSamplerHeight10", texUnitHeight10);
ghoul::opengl::TextureUnit texUnitHeight01;
texUnitHeight01.activate();
patchCoverage.textureTransformPairs[2].first->bind(); // tile01
patchCoverageHeight.textureTransformPairs[2].first->bind(); // tile01
_programObjectLocalRendering->setUniform("textureSamplerHeight01", texUnitHeight01);
ghoul::opengl::TextureUnit texUnitHeight11;
texUnitHeight11.activate();
patchCoverage.textureTransformPairs[3].first->bind(); // tile11
patchCoverageHeight.textureTransformPairs[3].first->bind(); // tile11
_programObjectLocalRendering->setUniform("textureSamplerHeight11", texUnitHeight11);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileHeight00",
patchCoverage.textureTransformPairs[0].second);
patchCoverageHeight.textureTransformPairs[0].second);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileHeight10",
patchCoverage.textureTransformPairs[1].second);
patchCoverageHeight.textureTransformPairs[1].second);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileHeight01",
patchCoverage.textureTransformPairs[2].second);
patchCoverageHeight.textureTransformPairs[2].second);
_programObjectLocalRendering->setUniform(
"uvTransformPatchToTileHeight11",
patchCoverage.textureTransformPairs[3].second);
patchCoverageHeight.textureTransformPairs[3].second);
uvec2 texture00DimensionsHeight = patchCoverageHeight.textureTransformPairs[0].first->dimensions().xy;
uvec2 texture10DimensionsHeight = patchCoverageHeight.textureTransformPairs[1].first->dimensions().xy;
uvec2 texture01DimensionsHeight = patchCoverageHeight.textureTransformPairs[2].first->dimensions().xy;
uvec2 texture11DimensionsHeight = patchCoverageHeight.textureTransformPairs[3].first->dimensions().xy;
_programObjectLocalRendering->setUniform("texture00DimensionsHeight", texture00DimensionsHeight);
_programObjectLocalRendering->setUniform("texture10DimensionsHeight", texture10DimensionsHeight);
_programObjectLocalRendering->setUniform("texture01DimensionsHeight", texture01DimensionsHeight);
_programObjectLocalRendering->setUniform("texture11DimensionsHeight", texture11DimensionsHeight);
@@ -529,8 +551,15 @@ namespace openspace {
"uvTransformPatchToTileColor11",
patchCoverageColor.textureTransformPairs[3].second);
uvec2 texture00DimensionsColor = patchCoverageColor.textureTransformPairs[0].first->dimensions().xy;
uvec2 texture10DimensionsColor = patchCoverageColor.textureTransformPairs[1].first->dimensions().xy;
uvec2 texture01DimensionsColor = patchCoverageColor.textureTransformPairs[2].first->dimensions().xy;
uvec2 texture11DimensionsColor = patchCoverageColor.textureTransformPairs[3].first->dimensions().xy;
_programObjectLocalRendering->setUniform("texture00DimensionsColor", texture00DimensionsColor);
_programObjectLocalRendering->setUniform("texture10DimensionsColor", texture10DimensionsColor);
_programObjectLocalRendering->setUniform("texture01DimensionsColor", texture01DimensionsColor);
_programObjectLocalRendering->setUniform("texture11DimensionsColor", texture11DimensionsColor);
_programObjectLocalRendering->setUniform(

View File

@@ -43,6 +43,10 @@ uniform mat3 uvTransformPatchToTileColor00;
uniform mat3 uvTransformPatchToTileColor10;
uniform mat3 uvTransformPatchToTileColor01;
uniform mat3 uvTransformPatchToTileColor11;
uniform uvec2 texture00DimensionsColor;
uniform uvec2 texture10DimensionsColor;
uniform uvec2 texture01DimensionsColor;
uniform uvec2 texture11DimensionsColor;
//uniform int segmentsPerPatch;
@@ -60,16 +64,23 @@ Fragment getFragment() {
vec4 color00, color10, color01, color11;
vec2 uv00 = vec2(uvTransformPatchToTileColor00 * vec3(fs_uv.s, fs_uv.t, 1));
color00 = texture(textureSamplerColor00, uv00);
vec2 uv10 = vec2(uvTransformPatchToTileColor10 * vec3(fs_uv.s, fs_uv.t, 1));
color10 += texture(textureSamplerColor10, uv10);
vec2 uv01 = vec2(uvTransformPatchToTileColor01 * vec3(fs_uv.s, fs_uv.t, 1));
color01 += texture(textureSamplerColor01, uv01);
vec2 uv11 = vec2(uvTransformPatchToTileColor11 * vec3(fs_uv.s, fs_uv.t, 1));
color11 += texture(textureSamplerColor11, uv11);
vec2 d00 = 1 / vec2(texture00DimensionsColor);
vec2 d10 = 1 / vec2(texture10DimensionsColor);
vec2 d01 = 1 / vec2(texture01DimensionsColor);
vec2 d11 = 1 / vec2(texture11DimensionsColor);
if (uv00.x > -d00.x && uv00.x < 1 + d00.x && uv00.y > -d00.y && uv00.y < 1 + d00.y)
color00 = texture(textureSamplerColor00, uv00);
if (uv10.x > -d10.x && uv10.x < 1 + d10.x && uv10.y > -d10.y && uv10.y < 1 + d10.y)
color10 = texture(textureSamplerColor10, uv10);
if (uv01.x > -d01.x && uv01.x < 1 + d01.x && uv01.y > -d01.y && uv01.y < 1 + d01.y)
color01 = texture(textureSamplerColor01, uv01);
if (uv11.x > -d11.x && uv11.x < 1 + d11.x && uv11.y > -d11.y && uv11.y < 1 + d11.y)
color11 = texture(textureSamplerColor11, uv11);
frag.color = max(color00, max(color10, max(color01, color11))) * 10;
frag.color = vec4(frag.color.r, frag.color.r, frag.color.r, 1);

View File

@@ -22,7 +22,6 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
uniform mat4 modelViewProjectionTransform;
@@ -34,15 +33,18 @@ uniform ivec2 contraction; // [-1, 1]
uniform int segmentsPerPatch;
uniform mat3 uvTransformPatchToTileHeight00;
uniform mat3 uvTransformPatchToTileHeight10;
uniform mat3 uvTransformPatchToTileHeight01;
uniform mat3 uvTransformPatchToTileHeight11;
uniform sampler2D textureSamplerHeight00;
uniform sampler2D textureSamplerHeight10;
uniform sampler2D textureSamplerHeight01;
uniform sampler2D textureSamplerHeight11;
uniform mat3 uvTransformPatchToTileHeight00;
uniform mat3 uvTransformPatchToTileHeight10;
uniform mat3 uvTransformPatchToTileHeight01;
uniform mat3 uvTransformPatchToTileHeight11;
uniform uvec2 texture00DimensionsHeight;
uniform uvec2 texture10DimensionsHeight;
uniform uvec2 texture01DimensionsHeight;
uniform uvec2 texture11DimensionsHeight;
layout(location = 1) in vec2 in_uv;
@@ -73,16 +75,31 @@ void main()
PositionNormalPair pair = globalInterpolation(fs_uv);
float sampledHeight00, sampledHeight10, sampledHeight01, sampledHeight11;
float sampledHeight00 = 0;
float sampledHeight10 = 0;
float sampledHeight01 = 0;
float sampledHeight11 = 0;
vec2 uv00 = vec2(uvTransformPatchToTileHeight00 * vec3(fs_uv.s, fs_uv.t, 1));
sampledHeight00 = texture(textureSamplerHeight00, uv00).r;
vec2 uv10 = vec2(uvTransformPatchToTileHeight10 * vec3(fs_uv.s, fs_uv.t, 1));
sampledHeight10 = texture(textureSamplerHeight10, uv10).r;
vec2 uv01 = vec2(uvTransformPatchToTileHeight01 * vec3(fs_uv.s, fs_uv.t, 1));
sampledHeight01 = texture(textureSamplerHeight01, uv01).r;
vec2 uv11 = vec2(uvTransformPatchToTileHeight11 * vec3(fs_uv.s, fs_uv.t, 1));
sampledHeight11 = texture(textureSamplerHeight11, uv11).r;
vec2 d00 = vec2(1,1) / texture00DimensionsHeight;
vec2 d10 = vec2(1,1) / texture10DimensionsHeight;
vec2 d01 = vec2(1,1) / texture01DimensionsHeight;
vec2 d11 = vec2(1,1) / texture11DimensionsHeight;
if (uv00.x > -d00.x && uv00.x < 1 + d00.x && uv00.y > -d00.y && uv00.y < 1 + d00.y)
sampledHeight00 = texture(textureSamplerHeight00, uv00).r;
if (uv10.x > -d10.x && uv10.x < 1 + d10.x && uv10.y > -d10.y && uv10.y < 1 + d10.y)
sampledHeight10 = texture(textureSamplerHeight10, uv10).r;
if (uv01.x > -d01.x && uv01.x < 1 + d01.x && uv01.y > -d01.y && uv01.y < 1 + d01.y)
sampledHeight01 = texture(textureSamplerHeight01, uv01).r;
if (uv11.x > -d11.x && uv11.x < 1 + d11.x && uv11.y > -d11.y && uv11.y < 1 + d11.y)
sampledHeight11 = texture(textureSamplerHeight11, uv11).r;
float sampledHeight = max(sampledHeight00, max(sampledHeight10, max(sampledHeight01, sampledHeight11)));

View File

@@ -43,6 +43,10 @@ uniform mat3 uvTransformPatchToTileColor00;
uniform mat3 uvTransformPatchToTileColor10;
uniform mat3 uvTransformPatchToTileColor01;
uniform mat3 uvTransformPatchToTileColor11;
uniform uvec2 texture00DimensionsColor;
uniform uvec2 texture10DimensionsColor;
uniform uvec2 texture01DimensionsColor;
uniform uvec2 texture11DimensionsColor;
//uniform int segmentsPerPatch;
@@ -60,19 +64,26 @@ Fragment getFragment() {
vec4 color00, color10, color01, color11;
vec2 uv00 = vec2(uvTransformPatchToTileColor00 * vec3(fs_uv.s, fs_uv.t, 1));
color00 = texture(textureSamplerColor00, uv00);
vec2 uv10 = vec2(uvTransformPatchToTileColor10 * vec3(fs_uv.s, fs_uv.t, 1));
color10 += texture(textureSamplerColor10, uv10);
vec2 uv01 = vec2(uvTransformPatchToTileColor01 * vec3(fs_uv.s, fs_uv.t, 1));
color01 += texture(textureSamplerColor01, uv01);
vec2 uv11 = vec2(uvTransformPatchToTileColor11 * vec3(fs_uv.s, fs_uv.t, 1));
color11 += texture(textureSamplerColor11, uv11);
vec2 d00 = vec2(1,1) / texture00DimensionsColor;
vec2 d10 = vec2(1,1) / texture10DimensionsColor;
vec2 d01 = vec2(1,1) / texture01DimensionsColor;
vec2 d11 = vec2(1,1) / texture11DimensionsColor;
if (uv00.x > -d00.x && uv00.x < 1 + d00.x && uv00.y > -d00.y && uv00.y < 1 + d00.y)
color00 = texture(textureSamplerColor00, uv00);
if (uv10.x > -d10.x && uv10.x < 1 + d10.x && uv10.y > -d10.y && uv10.y < 1 + d10.y)
color10 = texture(textureSamplerColor10, uv10);
if (uv01.x > -d01.x && uv01.x < 1 + d01.x && uv01.y > -d01.y && uv01.y < 1 + d01.y)
color01 = texture(textureSamplerColor01, uv01);
if (uv11.x > -d11.x && uv11.x < 1 + d11.x && uv11.y > -d11.y && uv11.y < 1 + d11.y)
color11 = texture(textureSamplerColor11, uv11);
frag.color = max(color00, max(color10, max(color01, color11))) * 10;
frag.color = vec4(frag.color.r, frag.color.r, frag.color.r, 1);
frag.color = vec4(frag.color.r, frag.color.r, 0, 1);
frag.depth = vs_position.w;

View File

@@ -41,11 +41,14 @@ uniform mat3 uvTransformPatchToTileHeight00;
uniform mat3 uvTransformPatchToTileHeight10;
uniform mat3 uvTransformPatchToTileHeight01;
uniform mat3 uvTransformPatchToTileHeight11;
uniform sampler2D textureSamplerHeight00;
uniform sampler2D textureSamplerHeight10;
uniform sampler2D textureSamplerHeight01;
uniform sampler2D textureSamplerHeight11;
uniform uvec2 texture00DimensionsHeight;
uniform uvec2 texture10DimensionsHeight;
uniform uvec2 texture01DimensionsHeight;
uniform uvec2 texture11DimensionsHeight;
layout(location = 1) in vec2 in_uv;
@@ -78,16 +81,29 @@ void main()
// Position in cameraspace
vec3 p = bilinearInterpolation(fs_uv);
float sampledHeight00, sampledHeight10, sampledHeight01, sampledHeight11;
float sampledHeight00 = 0;
float sampledHeight10 = 0;
float sampledHeight01 = 0;
float sampledHeight11 = 0;
vec2 uv00 = vec2(uvTransformPatchToTileHeight00 * vec3(fs_uv.s, fs_uv.t, 1));
sampledHeight00 = texture(textureSamplerHeight00, uv00).r;
vec2 uv10 = vec2(uvTransformPatchToTileHeight10 * vec3(fs_uv.s, fs_uv.t, 1));
sampledHeight10 = texture(textureSamplerHeight10, uv10).r;
vec2 uv01 = vec2(uvTransformPatchToTileHeight01 * vec3(fs_uv.s, fs_uv.t, 1));
sampledHeight01 = texture(textureSamplerHeight01, uv01).r;
vec2 uv11 = vec2(uvTransformPatchToTileHeight11 * vec3(fs_uv.s, fs_uv.t, 1));
sampledHeight11 = texture(textureSamplerHeight11, uv11).r;
vec2 d00 = vec2(1,1) / texture00DimensionsHeight;
vec2 d10 = vec2(1,1) / texture10DimensionsHeight;
vec2 d01 = vec2(1,1) / texture01DimensionsHeight;
vec2 d11 = vec2(1,1) / texture11DimensionsHeight;
if (uv00.x > -d00.x && uv00.x < 1 + d00.x && uv00.y > -d00.y && uv00.y < 1 + d00.y)
sampledHeight00 = texture(textureSamplerHeight00, uv00).r;
if (uv10.x > -d10.x && uv10.x < 1 + d10.x && uv10.y > -d10.y && uv10.y < 1 + d10.y)
sampledHeight10 = texture(textureSamplerHeight10, uv10).r;
if (uv01.x > -d01.x && uv01.x < 1 + d01.x && uv01.y > -d01.y && uv01.y < 1 + d01.y)
sampledHeight01 = texture(textureSamplerHeight01, uv01).r;
if (uv11.x > -d11.x && uv11.x < 1 + d11.x && uv11.y > -d11.y && uv11.y < 1 + d11.y)
sampledHeight11 = texture(textureSamplerHeight11, uv11).r;
float sampledHeight = max(sampledHeight00, max(sampledHeight10, max(sampledHeight01, sampledHeight11)));