From 14eb1c0563334b0cf5a644283be58f2fb7bab0ce Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Thu, 2 Jun 2016 11:16:10 -0400 Subject: [PATCH 1/2] Clean up chunked lod patch shaders. --- .../shaders/globalchunkedlodpatch_fs.glsl | 28 +++------------ .../shaders/globalchunkedlodpatch_vs.glsl | 22 ++++++------ .../shaders/localchunkedlodpatch_fs.glsl | 35 +++++-------------- .../shaders/localchunkedlodpatch_vs.glsl | 23 ++++++------ 4 files changed, 35 insertions(+), 73 deletions(-) diff --git a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl index 69183277db..da595a75f7 100644 --- a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl @@ -37,25 +37,15 @@ uniform TextureTile colorTilesParent2[NUMLAYERS_COLORTEXTURE]; in vec4 fs_position; in vec2 fs_uv; -in vec3 positionWorldSpace; - -uniform vec3 cameraPosition; -uniform float distanceScaleFactor; -uniform int chunkLevel; +in float tileInterpolationParameter; Fragment getFragment() { Fragment frag; - // Calculate desired level based on distance - float distToFrag = length(positionWorldSpace - cameraPosition); - float projectedScaleFactor = distanceScaleFactor / distToFrag; - float desiredLevel = log2(projectedScaleFactor); - - // x increases with distance - float x = chunkLevel - desiredLevel; - float w1 = clamp(1 - x, 0 , 1); - float w2 = (clamp(x, 0 , 1) - clamp(x - 1, 0 , 1)); - float w3 = clamp(x - 1, 0 , 1); + // tileInterpolationParameter increases with distance + float w1 = clamp(1 - tileInterpolationParameter, 0 , 1); + float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1)); + float w3 = clamp(tileInterpolationParameter - 1, 0 , 1); #for j in 1..#{numLayersColor} { @@ -78,14 +68,6 @@ Fragment getFragment() { } #endfor - //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 + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02); - frag.depth = fs_position.w; return frag; diff --git a/modules/globebrowsing/shaders/globalchunkedlodpatch_vs.glsl b/modules/globebrowsing/shaders/globalchunkedlodpatch_vs.glsl index 7e54669ad1..3177e578b7 100644 --- a/modules/globebrowsing/shaders/globalchunkedlodpatch_vs.glsl +++ b/modules/globebrowsing/shaders/globalchunkedlodpatch_vs.glsl @@ -38,7 +38,6 @@ uniform vec2 minLatLon; uniform vec2 lonLatScalingFactor; uniform int xSegments; -uniform int ySegments; uniform float skirtLength; uniform TextureTile heightTiles[NUMLAYERS_HEIGHTMAP]; @@ -53,7 +52,9 @@ layout(location = 1) in vec2 in_uv; out vec2 fs_uv; out vec4 fs_position; -out vec3 positionWorldSpace; +// tileInterpolationParameter 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 +out float tileInterpolationParameter; PositionNormalPair globalInterpolation() { vec2 lonLatInput; @@ -66,20 +67,19 @@ PositionNormalPair globalInterpolation() { void main() { PositionNormalPair pair = globalInterpolation(); - positionWorldSpace = pair.position; float height = 0; - // Calculate desired level based on distance - float distToVertex = length(positionWorldSpace - cameraPosition); - float projectedScaleFactor = distanceScaleFactor / distToVertex; + // Calculate desired level based on distance to the vertex on the ellipsoid + // Before any heightmapping is done + float distToVertexOnEllipsoid = length(pair.position - cameraPosition); + float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid; float desiredLevel = log2(projectedScaleFactor); - // x increases with distance - float x = chunkLevel - desiredLevel; - float w1 = clamp(1 - x, 0 , 1); - float w2 = (clamp(x, 0 , 1) - clamp(x - 1, 0 , 1)); - float w3 = clamp(x - 1, 0 , 1); + tileInterpolationParameter = chunkLevel - desiredLevel; + float w1 = clamp(1 - tileInterpolationParameter, 0 , 1); + float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1)); + float w3 = clamp(tileInterpolationParameter - 1, 0 , 1); #for j in 1..#{numLayersHeight} { diff --git a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl index 1066b3c267..843e0b8ae0 100644 --- a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl @@ -34,26 +34,20 @@ uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE]; uniform TextureTile colorTilesParent1[NUMLAYERS_COLORTEXTURE]; uniform TextureTile colorTilesParent2[NUMLAYERS_COLORTEXTURE]; +// tileInterpolationParameter 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 float tileInterpolationParameter; + in vec4 fs_position; in vec2 fs_uv; -in vec3 positionCameraSpace; - -uniform float distanceScaleFactor; -uniform int chunkLevel; Fragment getFragment() { Fragment frag; - // Calculate desired level based on distance - float distToFrag = length(positionCameraSpace); - float projectedScaleFactor = distanceScaleFactor / distToFrag; - float desiredLevel = log2(projectedScaleFactor); - - // x increases with distance - float x = chunkLevel - desiredLevel; - float w1 = clamp(1 - x, 0 , 1); - float w2 = (clamp(x, 0 , 1) - clamp(x - 1, 0 , 1)); - float w3 = clamp(x - 1, 0 , 1); + // tileInterpolationParameter increases with distance to camera + float w1 = clamp(1 - tileInterpolationParameter, 0 , 1); + float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1)); + float w3 = clamp(tileInterpolationParameter - 1, 0 , 1); #for j in 1..#{numLayersColor} { @@ -77,19 +71,6 @@ Fragment getFragment() { } #endfor - //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 + patchBorderOverlay(fs_uv, vec3(0.5, 0.5, 0.5), 0.02); - frag.depth = fs_position.w; return frag; diff --git a/modules/globebrowsing/shaders/localchunkedlodpatch_vs.glsl b/modules/globebrowsing/shaders/localchunkedlodpatch_vs.glsl index fefd829b79..a4eb06945d 100644 --- a/modules/globebrowsing/shaders/localchunkedlodpatch_vs.glsl +++ b/modules/globebrowsing/shaders/localchunkedlodpatch_vs.glsl @@ -45,7 +45,6 @@ uniform TextureTile heightTilesParent1[NUMLAYERS_HEIGHTMAP]; uniform TextureTile heightTilesParent2[NUMLAYERS_HEIGHTMAP]; uniform int xSegments; -uniform int ySegments; uniform float skirtLength; uniform float distanceScaleFactor; @@ -55,7 +54,9 @@ layout(location = 1) in vec2 in_uv; out vec2 fs_uv; out vec4 fs_position; -out vec3 positionCameraSpace; +// tileInterpolationParameter 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 +out float tileInterpolationParameter; vec3 bilinearInterpolation(vec2 uv) { // Bilinear interpolation @@ -72,18 +73,16 @@ void main() float height = 0; - positionCameraSpace = p; - - // Calculate desired level based on distance - float distToVertex = length(positionCameraSpace); - float projectedScaleFactor = distanceScaleFactor / distToVertex; + // Calculate desired level based on distance to the vertex on the ellipsoid + // Before any heightmapping is done + float distToVertexOnEllipsoid = length(p); + float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid; float desiredLevel = log2(projectedScaleFactor); - // x increases with distance - float x = chunkLevel - desiredLevel; - float w1 = clamp(1 - x, 0 , 1); - float w2 = (clamp(x, 0 , 1) - clamp(x - 1, 0 , 1)); - float w3 = clamp(x - 1, 0 , 1); + tileInterpolationParameter = chunkLevel - desiredLevel; + float w1 = clamp(1 - tileInterpolationParameter, 0 , 1); + float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1)); + float w3 = clamp(tileInterpolationParameter - 1, 0 , 1); #for j in 1..#{numLayersHeight} { From 1e551a9e65aa447327f5e90d4b17b758235f1ffe Mon Sep 17 00:00:00 2001 From: Kalle Bladin Date: Thu, 2 Jun 2016 12:04:07 -0400 Subject: [PATCH 2/2] Change minimum value for lodScaleFactor --- modules/globebrowsing/globes/renderableglobe.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/globebrowsing/globes/renderableglobe.cpp b/modules/globebrowsing/globes/renderableglobe.cpp index ca29c86ece..acfaa23ae0 100644 --- a/modules/globebrowsing/globes/renderableglobe.cpp +++ b/modules/globebrowsing/globes/renderableglobe.cpp @@ -59,7 +59,7 @@ namespace openspace { , doFrustumCulling(properties::BoolProperty("doFrustumCulling", "doFrustumCulling")) , doHorizonCulling(properties::BoolProperty("doHorizonCulling", "doHorizonCulling")) , mergeInvisible(properties::BoolProperty("mergeInvisible", "mergeInvisible", true)) - , lodScaleFactor(properties::FloatProperty("lodScaleFactor", "lodScaleFactor", 5.0f, 0.0f, 20.0f)) + , lodScaleFactor(properties::FloatProperty("lodScaleFactor", "lodScaleFactor", 5.0f, 1.0f, 20.0f)) , initChunkVisible(properties::BoolProperty("initChunkVisible", "initChunkVisible", true)) , renderSmallChunksFirst(properties::BoolProperty("renderSmallChunksFirst", "renderSmallChunksFirst", true)) {