From d9d97b2dbd17407e8cd425e4edf6a14e5c29913f Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Thu, 30 Jun 2016 13:25:22 -0400 Subject: [PATCH] Correctly visualize texture tile resolution and pixel positions --- .../shaders/globalchunkedlodpatch_fs.glsl | 6 ++---- .../shaders/localchunkedlodpatch_fs.glsl | 5 ++--- .../shaders/texturetilemapping.hglsl | 12 ++++++++---- modules/globebrowsing/shaders/tile.hglsl | 18 ++++++------------ 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl index 63949b4d9c..ef91f7d753 100644 --- a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl @@ -92,12 +92,10 @@ Fragment getFragment() { ColorTexturesParent2); #else - vec2 heightResolution = vec2(1,1); + frag.color = calculateDebugColor(fs_uv, fs_position, vertexResolution); #if USE_HEIGHTMAP - heightResolution = vec2(textureSize(HeightMaps[0].textureSampler,0)); + frag.color.r += tileResolution(fs_uv, HeightMaps[0]) > 0.9 ? 1 : 0; #endif - - frag.color = calculateDebugColor(fs_uv, fs_position, vertexResolution, heightResolution); #endif // USE_COLORTEXTURE #if USE_GRAYSCALE_OVERLAY diff --git a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl index ed5aab2668..407b172897 100644 --- a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl @@ -87,11 +87,10 @@ Fragment getFragment() { ColorTexturesParent1, ColorTexturesParent2); #else - vec2 heightResolution = vec2(1,1); + frag.color = calculateDebugColor(fs_uv, fs_position, vertexResolution); #if USE_HEIGHTMAP - heightResolution = vec2(textureSize(HeightMaps[0].textureSampler,0)); + frag.color.r += tileResolution(fs_uv, HeightMaps[0]) > 0.9 ? 1 : 0; #endif - frag.color = calculateDebugColor(fs_uv, fs_position, vertexResolution, heightResolution); #endif // USE_COLORTEXTURE diff --git a/modules/globebrowsing/shaders/texturetilemapping.hglsl b/modules/globebrowsing/shaders/texturetilemapping.hglsl index 874f953afe..b906211ae5 100644 --- a/modules/globebrowsing/shaders/texturetilemapping.hglsl +++ b/modules/globebrowsing/shaders/texturetilemapping.hglsl @@ -123,22 +123,26 @@ vec4 calculateColor( } float gridDots(vec2 uv, vec2 gridResolution){ - vec2 uvVertexSpace = fract(gridResolution * uv); + vec2 uvVertexSpace = fract((gridResolution) * uv) + 0.5; vec2 uvDotSpace = abs(2*(uvVertexSpace-0.5)); return 1-length(1-uvDotSpace); } -vec4 calculateDebugColor(vec2 uv, vec4 fragPos, vec2 vertexResolution, vec2 heightResolution){ +vec4 calculateDebugColor(vec2 uv, vec4 fragPos, vec2 vertexResolution){ 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, heightResolution) > 0.9 ? 1 : 0) * vec3(1,0,0); - vec3 colorSum = colorUv + colorDistance + colorVertex + colorHeightSample; + vec3 colorSum = colorUv + colorDistance + colorVertex; return vec4(0.5 * colorSum, 1); } +float tileResolution(vec2 tileUV, const Tile tile){ + vec2 heightResolution = textureSize(tile.textureSampler, 0); + vec2 uv = TileUVToTextureSamplePosition(tile, tileUV); + return gridDots(uv, heightResolution); +} vec4 calculateNight( diff --git a/modules/globebrowsing/shaders/tile.hglsl b/modules/globebrowsing/shaders/tile.hglsl index 0000a81a61..6cd5403387 100644 --- a/modules/globebrowsing/shaders/tile.hglsl +++ b/modules/globebrowsing/shaders/tile.hglsl @@ -81,21 +81,15 @@ vec2 compensateSourceTextureSampling(vec2 startOffset, vec2 sizeDiff, const Tile 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; +vec2 TileUVToTextureSamplePosition(const Tile tile, vec2 tileUV){ + vec2 uv = tile.uvTransform.uvOffset + tile.uvTransform.uvScale * tileUV; + uv = compensateSourceTextureSampling(vec2(0), vec2(0), tile, uv); + return uv; } vec4 getTexVal(const Tile tile, vec2 tileUV){ - 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); + vec2 samplePosition = TileUVToTextureSamplePosition(tile, tileUV); + vec4 texVal = texture(tile.textureSampler, samplePosition); return texVal; }