diff --git a/modules/globebrowsing/other/layeredtextureshaderprovider.cpp b/modules/globebrowsing/other/layeredtextureshaderprovider.cpp index dbd984511d..ca756c554e 100644 --- a/modules/globebrowsing/other/layeredtextureshaderprovider.cpp +++ b/modules/globebrowsing/other/layeredtextureshaderprovider.cpp @@ -39,7 +39,7 @@ namespace openspace { bool LayeredTextureInfo::operator==(const LayeredTextureInfo& other) const { - return numLayers == other.numLayers && keyNumLayers == other.keyNumLayers; + return lastLayerIndex == other.lastLayerIndex && keyLastLayerIndex == other.keyLastLayerIndex; } bool LayeredTexturePreprocessingData::operator==( @@ -104,7 +104,7 @@ namespace openspace { for (size_t i = 0; i < textureTypes.size(); i++) { shaderDictionary.setValue( - textureTypes[i].keyNumLayers, textureTypes[i].numLayers); + textureTypes[i].keyLastLayerIndex, textureTypes[i].lastLayerIndex); } // Remove old program diff --git a/modules/globebrowsing/other/layeredtextureshaderprovider.h b/modules/globebrowsing/other/layeredtextureshaderprovider.h index ccea9d5f94..05a5d72e16 100644 --- a/modules/globebrowsing/other/layeredtextureshaderprovider.h +++ b/modules/globebrowsing/other/layeredtextureshaderprovider.h @@ -39,8 +39,8 @@ namespace openspace { struct LayeredTextureInfo { - std::string keyNumLayers; - int numLayers; + std::string keyLastLayerIndex; + int lastLayerIndex; bool operator==(const LayeredTextureInfo& other) const; }; diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index a477c5e402..c37fd77446 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -128,10 +128,10 @@ namespace openspace { // Create information for the shader provider LayeredTextureInfo layeredTextureInfoHeight; LayeredTextureInfo layeredTextureInfoColor; - layeredTextureInfoHeight.keyNumLayers = "numLayersHeight"; - layeredTextureInfoHeight.numLayers = numHeightMapProviders; - layeredTextureInfoColor.keyNumLayers = "numLayersColor"; - layeredTextureInfoColor.numLayers = numColorTextureProviders; + layeredTextureInfoHeight.keyLastLayerIndex = "lastLayerIndexHeight"; + layeredTextureInfoHeight.lastLayerIndex = numHeightMapProviders - 1; + layeredTextureInfoColor.keyLastLayerIndex = "lastLayerIndexColor"; + layeredTextureInfoColor.lastLayerIndex = numColorTextureProviders - 1; LayeredTexturePreprocessingData layeredTexturePreprocessingData; layeredTexturePreprocessingData.layeredTextureInfo.push_back( @@ -387,10 +387,10 @@ namespace openspace { // Create information for the shader provider LayeredTextureInfo layeredTextureInfoHeight; LayeredTextureInfo layeredTextureInfoColor; - layeredTextureInfoHeight.keyNumLayers = "numLayersHeight"; - layeredTextureInfoHeight.numLayers = numHeightMapProviders; - layeredTextureInfoColor.keyNumLayers = "numLayersColor"; - layeredTextureInfoColor.numLayers = numColorTextureProviders; + layeredTextureInfoHeight.keyLastLayerIndex = "lastLayerIndexHeight"; + layeredTextureInfoHeight.lastLayerIndex = numHeightMapProviders - 1; + layeredTextureInfoColor.keyLastLayerIndex = "lastLayerIndexColor"; + layeredTextureInfoColor.lastLayerIndex = numColorTextureProviders - 1; LayeredTexturePreprocessingData layeredTexturePreprocessingData; layeredTexturePreprocessingData.layeredTextureInfo.push_back( diff --git a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl index da595a75f7..c323dd162b 100644 --- a/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/globalchunkedlodpatch_fs.glsl @@ -27,8 +27,8 @@ #include "PowerScaling/powerScaling_fs.hglsl" #include "fragment.glsl" -#define NUMLAYERS_COLORTEXTURE #{numLayersColor} -#define NUMLAYERS_HEIGHTMAP #{numLayersHeight} +#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1 +#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1 uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE]; uniform TextureTile colorTilesParent1[NUMLAYERS_COLORTEXTURE]; @@ -47,23 +47,22 @@ Fragment getFragment() { float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1)); float w3 = clamp(tileInterpolationParameter - 1, 0 , 1); - #for j in 1..#{numLayersColor} + #for i in 0..#{lastLayerIndexColor} { - int i = #{j} - 1; vec2 samplePos = - colorTiles[i].uvTransform.uvScale * fs_uv + - colorTiles[i].uvTransform.uvOffset; + colorTiles[#{i}].uvTransform.uvScale * fs_uv + + colorTiles[#{i}].uvTransform.uvOffset; vec2 samplePosParent1 = - colorTilesParent1[i].uvTransform.uvScale * fs_uv + - colorTilesParent1[i].uvTransform.uvOffset; + colorTilesParent1[#{i}].uvTransform.uvScale * fs_uv + + colorTilesParent1[#{i}].uvTransform.uvOffset; vec2 samplePosParent2 = - colorTilesParent2[i].uvTransform.uvScale * fs_uv + - colorTilesParent2[i].uvTransform.uvOffset; + colorTilesParent2[#{i}].uvTransform.uvScale * fs_uv + + colorTilesParent2[#{i}].uvTransform.uvOffset; vec4 colorSample = - w1 * texture(colorTiles[i].textureSampler, samplePos) + - w2 * texture(colorTilesParent1[i].textureSampler, samplePosParent1) + - w3 * texture(colorTilesParent2[i].textureSampler, samplePosParent2); + w1 * texture(colorTiles[#{i}].textureSampler, samplePos) + + w2 * texture(colorTilesParent1[#{i}].textureSampler, samplePosParent1) + + w3 * texture(colorTilesParent2[#{i}].textureSampler, samplePosParent2); frag.color = blendOver(frag.color, colorSample); } #endfor diff --git a/modules/globebrowsing/shaders/globalchunkedlodpatch_vs.glsl b/modules/globebrowsing/shaders/globalchunkedlodpatch_vs.glsl index 3177e578b7..7a34bf989a 100644 --- a/modules/globebrowsing/shaders/globalchunkedlodpatch_vs.glsl +++ b/modules/globebrowsing/shaders/globalchunkedlodpatch_vs.glsl @@ -28,8 +28,8 @@ #include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl> #include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl> -#define NUMLAYERS_COLORTEXTURE #{numLayersColor} -#define NUMLAYERS_HEIGHTMAP #{numLayersHeight} +#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1 +#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1 uniform mat4 modelViewProjectionTransform; uniform vec3 radiiSquared; @@ -81,28 +81,27 @@ void main() float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1)); float w3 = clamp(tileInterpolationParameter - 1, 0 , 1); - #for j in 1..#{numLayersHeight} + #for i in 0..#{lastLayerIndexHeight} { - int i = #{j} - 1; vec2 samplePos = - heightTiles[i].uvTransform.uvScale * in_uv + - heightTiles[i].uvTransform.uvOffset; + heightTiles[#{i}].uvTransform.uvScale * in_uv + + heightTiles[#{i}].uvTransform.uvOffset; vec2 samplePosParent1 = - heightTilesParent1[i].uvTransform.uvScale * in_uv + - heightTilesParent1[i].uvTransform.uvOffset; + heightTilesParent1[#{i}].uvTransform.uvScale * in_uv + + heightTilesParent1[#{i}].uvTransform.uvOffset; vec2 samplePosParent2 = - heightTilesParent2[i].uvTransform.uvScale * in_uv + - heightTilesParent2[i].uvTransform.uvOffset; + heightTilesParent2[#{i}].uvTransform.uvScale * in_uv + + heightTilesParent2[#{i}].uvTransform.uvOffset; float sampledValue = - w1 * texture(heightTiles[i].textureSampler, samplePos).r + - w2 * texture(heightTilesParent1[i].textureSampler, samplePosParent1).r + - w3 * texture(heightTilesParent2[i].textureSampler, samplePosParent2).r; + w1 * texture(heightTiles[#{i}].textureSampler, samplePos).r + + w2 * texture(heightTilesParent1[#{i}].textureSampler, samplePosParent1).r + + w3 * texture(heightTilesParent2[#{i}].textureSampler, samplePosParent2).r; // TODO : Some kind of blending here. Now it just writes over height = (sampledValue * - heightTiles[i].depthTransform.depthScale + - heightTiles[i].depthTransform.depthOffset); + heightTiles[#{i}].depthTransform.depthScale + + heightTiles[#{i}].depthTransform.depthOffset); // Skirts int vertexIDx = gl_VertexID % (xSegments + 3); diff --git a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl index 843e0b8ae0..feb3d06af3 100644 --- a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl @@ -27,8 +27,8 @@ #include "PowerScaling/powerScaling_fs.hglsl" #include "fragment.glsl" -#define NUMLAYERS_COLORTEXTURE #{numLayersColor} -#define NUMLAYERS_HEIGHTMAP #{numLayersHeight} +#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1 +#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1 uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE]; uniform TextureTile colorTilesParent1[NUMLAYERS_COLORTEXTURE]; @@ -49,24 +49,22 @@ Fragment getFragment() { float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1)); float w3 = clamp(tileInterpolationParameter - 1, 0 , 1); - #for j in 1..#{numLayersColor} + #for i in 0..#{lastLayerIndexColor} { - int i = #{j} - 1; - vec2 samplePos = - colorTiles[i].uvTransform.uvScale * fs_uv + - colorTiles[i].uvTransform.uvOffset; + colorTiles[#{i}].uvTransform.uvScale * fs_uv + + colorTiles[#{i}].uvTransform.uvOffset; vec2 samplePosParent1 = - colorTilesParent1[i].uvTransform.uvScale * fs_uv + - colorTilesParent1[i].uvTransform.uvOffset; + colorTilesParent1[#{i}].uvTransform.uvScale * fs_uv + + colorTilesParent1[#{i}].uvTransform.uvOffset; vec2 samplePosParent2 = - colorTilesParent2[i].uvTransform.uvScale * fs_uv + - colorTilesParent2[i].uvTransform.uvOffset; + colorTilesParent2[#{i}].uvTransform.uvScale * fs_uv + + colorTilesParent2[#{i}].uvTransform.uvOffset; vec4 colorSample = - w1 * texture(colorTiles[i].textureSampler, samplePos) + - w2 * texture(colorTilesParent1[i].textureSampler, samplePosParent1) + - w3 * texture(colorTilesParent2[i].textureSampler, samplePosParent2); + w1 * texture(colorTiles[#{i}].textureSampler, samplePos) + + w2 * texture(colorTilesParent1[#{i}].textureSampler, samplePosParent1) + + w3 * texture(colorTilesParent2[#{i}].textureSampler, samplePosParent2); frag.color = blendOver(frag.color, colorSample); } #endfor diff --git a/modules/globebrowsing/shaders/localchunkedlodpatch_vs.glsl b/modules/globebrowsing/shaders/localchunkedlodpatch_vs.glsl index a4eb06945d..fb1daf53e1 100644 --- a/modules/globebrowsing/shaders/localchunkedlodpatch_vs.glsl +++ b/modules/globebrowsing/shaders/localchunkedlodpatch_vs.glsl @@ -28,8 +28,8 @@ #include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl> #include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl> -#define NUMLAYERS_COLORTEXTURE #{numLayersColor} -#define NUMLAYERS_HEIGHTMAP #{numLayersHeight} +#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1 +#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1 uniform mat4 projectionTransform; @@ -84,28 +84,27 @@ void main() float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1)); float w3 = clamp(tileInterpolationParameter - 1, 0 , 1); - #for j in 1..#{numLayersHeight} + #for i in 0..#{lastLayerIndexHeight} { - int i = #{j} - 1; vec2 samplePos = - heightTiles[i].uvTransform.uvScale * in_uv + - heightTiles[i].uvTransform.uvOffset; + heightTiles[#{i}].uvTransform.uvScale * in_uv + + heightTiles[#{i}].uvTransform.uvOffset; vec2 samplePosParent1 = - heightTilesParent1[i].uvTransform.uvScale * in_uv + - heightTilesParent1[i].uvTransform.uvOffset; + heightTilesParent1[#{i}].uvTransform.uvScale * in_uv + + heightTilesParent1[#{i}].uvTransform.uvOffset; vec2 samplePosParent2 = - heightTilesParent2[i].uvTransform.uvScale * in_uv + - heightTilesParent2[i].uvTransform.uvOffset; + heightTilesParent2[#{i}].uvTransform.uvScale * in_uv + + heightTilesParent2[#{i}].uvTransform.uvOffset; float sampledValue = - w1 * texture(heightTiles[i].textureSampler, samplePos).r + - w2 * texture(heightTilesParent1[i].textureSampler, samplePosParent1).r + - w3 * texture(heightTilesParent2[i].textureSampler, samplePosParent2).r; + w1 * texture(heightTiles[#{i}].textureSampler, samplePos).r + + w2 * texture(heightTilesParent1[#{i}].textureSampler, samplePosParent1).r + + w3 * texture(heightTilesParent2[#{i}].textureSampler, samplePosParent2).r; // TODO : Some kind of blending here. Now it just writes over height = (sampledValue * - heightTiles[i].depthTransform.depthScale + - heightTiles[i].depthTransform.depthOffset); + heightTiles[#{i}].depthTransform.depthScale + + heightTiles[#{i}].depthTransform.depthOffset); // Skirts int vertexIDx = gl_VertexID % (xSegments + 3);