diff --git a/modules/globebrowsing/globes/chunkedlodglobe.h b/modules/globebrowsing/globes/chunkedlodglobe.h index 096ce69cfd..b2d118e492 100644 --- a/modules/globebrowsing/globes/chunkedlodglobe.h +++ b/modules/globebrowsing/globes/chunkedlodglobe.h @@ -95,8 +95,6 @@ namespace openspace { float chunkHeight; // Layered rendering - bool useHeightMap; - bool useColorMap; bool blendHeightMap; bool blendColorMap; diff --git a/modules/globebrowsing/globes/renderableglobe.cpp b/modules/globebrowsing/globes/renderableglobe.cpp index 59991b6d17..1e81432d86 100644 --- a/modules/globebrowsing/globes/renderableglobe.cpp +++ b/modules/globebrowsing/globes/renderableglobe.cpp @@ -61,8 +61,6 @@ namespace openspace { , initChunkVisible(properties::BoolProperty("initChunkVisible", "initChunkVisible", true)) , renderSmallChunksFirst(properties::BoolProperty("renderSmallChunksFirst", "renderSmallChunksFirst", true)) , chunkHeight(properties::FloatProperty("chunkHeight", "chunkHeight", 8700.0f, 0.0f, 8700.0f)) - , useHeightMap(properties::BoolProperty("useHeightMap", "useHeightMap", true)) - , useColorMap(properties::BoolProperty("useColorMap", "useColorMap", true)) , blendHeightMap(properties::BoolProperty("blendHeightMap", "blendHeightMap", true)) , blendColorMap(properties::BoolProperty("blendColorMap", "blendColorMap", true)) { @@ -77,8 +75,6 @@ namespace openspace { addProperty(renderSmallChunksFirst); addProperty(chunkHeight); - addProperty(useHeightMap); - addProperty(useColorMap); addProperty(blendHeightMap); addProperty(blendColorMap); @@ -175,8 +171,6 @@ namespace openspace { _chunkedLodGlobe->initChunkVisible = initChunkVisible.value(); _chunkedLodGlobe->chunkHeight = chunkHeight.value(); - _chunkedLodGlobe->useHeightMap = useHeightMap.value(); - _chunkedLodGlobe->useColorMap = useColorMap.value(); _chunkedLodGlobe->blendHeightMap = blendHeightMap.value(); _chunkedLodGlobe->blendColorMap = blendColorMap.value(); @@ -184,7 +178,6 @@ namespace openspace { _tileProviderManager->colorTextureProviders(); std::vector& heightMapProviders = _tileProviderManager->heightMapProviders(); - for (size_t i = 0; i < colorTextureProviders.size(); i++) { colorTextureProviders[i].isActive = _activeColorLayers[i].value(); diff --git a/modules/globebrowsing/globes/renderableglobe.h b/modules/globebrowsing/globes/renderableglobe.h index 8c5f25f2d3..b1ebbafb28 100644 --- a/modules/globebrowsing/globes/renderableglobe.h +++ b/modules/globebrowsing/globes/renderableglobe.h @@ -75,8 +75,6 @@ public: properties::FloatProperty chunkHeight; // Layered rendering - properties::BoolProperty useHeightMap; - properties::BoolProperty useColorMap; properties::BoolProperty blendHeightMap; properties::BoolProperty blendColorMap; diff --git a/modules/globebrowsing/other/layeredtextureshaderprovider.cpp b/modules/globebrowsing/other/layeredtextureshaderprovider.cpp index fbc1645c8d..6037d34b0d 100644 --- a/modules/globebrowsing/other/layeredtextureshaderprovider.cpp +++ b/modules/globebrowsing/other/layeredtextureshaderprovider.cpp @@ -43,7 +43,6 @@ namespace openspace { lastLayerIndex == other.lastLayerIndex && keyLastLayerIndex == other.keyLastLayerIndex && keyUseThisLayerType == other.keyUseThisLayerType && - useThisLayerType == other.useThisLayerType && keyLayerBlendingEnabled == other.keyLayerBlendingEnabled && layerBlendingEnabled == other.layerBlendingEnabled; } @@ -108,10 +107,12 @@ namespace openspace { // These are used differently within the shaders. auto textureTypes = _preprocessingData.layeredTextureInfo; for (size_t i = 0; i < textureTypes.size(); i++) { + // lastLayerIndex must be at least 0 for the shader to compile, + // the layer type is inactivated by setting useThisLayerType to false shaderDictionary.setValue( - textureTypes[i].keyLastLayerIndex, textureTypes[i].lastLayerIndex); + textureTypes[i].keyLastLayerIndex, glm::max(textureTypes[i].lastLayerIndex, 0)); shaderDictionary.setValue( - textureTypes[i].keyUseThisLayerType, textureTypes[i].useThisLayerType); + textureTypes[i].keyUseThisLayerType, textureTypes[i].lastLayerIndex >= 0); shaderDictionary.setValue( textureTypes[i].keyLayerBlendingEnabled, textureTypes[i].layerBlendingEnabled); } diff --git a/modules/globebrowsing/other/layeredtextureshaderprovider.h b/modules/globebrowsing/other/layeredtextureshaderprovider.h index 4ee38f1537..5b919fa65d 100644 --- a/modules/globebrowsing/other/layeredtextureshaderprovider.h +++ b/modules/globebrowsing/other/layeredtextureshaderprovider.h @@ -43,7 +43,6 @@ namespace openspace { std::string keyUseThisLayerType; std::string keyLayerBlendingEnabled; int lastLayerIndex; - bool useThisLayerType; bool layerBlendingEnabled; bool operator==(const LayeredTextureInfo& other) const; diff --git a/modules/globebrowsing/rendering/patchrenderer.cpp b/modules/globebrowsing/rendering/patchrenderer.cpp index af91ae560a..35b87759fc 100644 --- a/modules/globebrowsing/rendering/patchrenderer.cpp +++ b/modules/globebrowsing/rendering/patchrenderer.cpp @@ -114,6 +114,8 @@ namespace openspace { void ChunkRenderer::renderChunkGlobally(const Chunk& chunk, const RenderData& data){ using namespace glm; + const Ellipsoid& ellipsoid = chunk.owner()->ellipsoid(); + // All providers of tiles auto heightMapProviders = _tileProviderManager->getActiveHeightMapProviders(); auto colorTextureProviders = _tileProviderManager->getActiveColorTextureProviders(); @@ -121,26 +123,18 @@ namespace openspace { int numHeightMapProviders = heightMapProviders.size(); int numColorTextureProviders = colorTextureProviders.size(); - /* - if (numHeightMapProviders == 0 || numColorTextureProviders == 0) { - return; - } - */ - // Create information for the shader provider LayeredTextureInfo layeredTextureInfoHeight; LayeredTextureInfo layeredTextureInfoColor; layeredTextureInfoHeight.keyLastLayerIndex = "lastLayerIndexHeight"; layeredTextureInfoHeight.lastLayerIndex = numHeightMapProviders - 1; layeredTextureInfoHeight.keyUseThisLayerType = "useHeightMap"; - layeredTextureInfoHeight.useThisLayerType = chunk.owner()->useHeightMap; layeredTextureInfoHeight.keyLayerBlendingEnabled = "heightMapBlendingEnabled"; layeredTextureInfoHeight.layerBlendingEnabled = chunk.owner()->blendHeightMap; layeredTextureInfoColor.keyLastLayerIndex = "lastLayerIndexColor"; layeredTextureInfoColor.lastLayerIndex = numColorTextureProviders - 1; layeredTextureInfoColor.keyUseThisLayerType = "useColorTexture"; - layeredTextureInfoColor.useThisLayerType = chunk.owner()->useColorMap; layeredTextureInfoColor.keyLayerBlendingEnabled = "colorTextureBlendingEnabled"; layeredTextureInfoColor.layerBlendingEnabled = chunk.owner()->blendColorMap; @@ -174,174 +168,176 @@ namespace openspace { texUnitColor.resize(numColorTextureProviders); texUnitColorParent1.resize(numColorTextureProviders); texUnitColorParent2.resize(numColorTextureProviders); + + // Go through all the height map providers + int i = 0; + for (auto it = heightMapProviders.begin(); it != heightMapProviders.end(); it++) + { + auto tileProvider = it->get(); + // Get the texture that should be used for rendering + Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); + + if (tile.texture == nullptr) { + // don't render if no tile was available + programObject->deactivate(); + return; + } + TileDepthTransform depthTransform = tileProvider->depthTransform(); - if (layeredTextureInfoHeight.useThisLayerType) { + // The texture needs a unit to sample from + texUnitHeight[i].activate(); + tile.texture->bind(); - // Go through all the color texture providers - int i = 0; - for (auto it = heightMapProviders.begin(); it != heightMapProviders.end(); it++) - { - auto tileProvider = it->get(); - // Get the texture that should be used for rendering - Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); + std::string indexedTileKey = "heightTiles[" + std::to_string(i) + "]"; + // Send uniforms for the tile to the shader + programObject->setUniform(indexedTileKey + ".textureSampler", texUnitHeight[i]); - if (tile.texture == nullptr) { - // don't render if no tile was available - programObject->deactivate(); - return; + programObject->setUniform( + indexedTileKey + ".uvTransform.uvScale", + tile.uvTransform.uvScale); + programObject->setUniform( + indexedTileKey + ".uvTransform.uvOffset", + tile.uvTransform.uvOffset); + + programObject->setUniform( + indexedTileKey + ".depthTransform.depthScale", + depthTransform.depthScale); + programObject->setUniform( + indexedTileKey + ".depthTransform.depthOffset", + depthTransform.depthOffset); + + // If blending is enabled, two more textures are needed + if (layeredTextureInfoHeight.layerBlendingEnabled) { + Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); + Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); + + if (tileParent1.texture == nullptr) { + tileParent1 = tile; } - TileDepthTransform depthTransform = tileProvider->depthTransform(); + if (tileParent2.texture == nullptr) { + tileParent2 = tileParent1; + } + + // Blend tile with two parents + // The texture needs a unit to sample from + texUnitHeightParent1[i].activate(); + tileParent1.texture->bind(); + + std::string indexedTileKeyParent1 = "heightTilesParent1[" + std::to_string(i) + "]"; + // Send uniforms for the tile to the shader + programObject->setUniform(indexedTileKeyParent1 + ".textureSampler", texUnitHeightParent1[i]); + + programObject->setUniform( + indexedTileKeyParent1 + ".uvTransform.uvScale", + tileParent1.uvTransform.uvScale); + programObject->setUniform( + indexedTileKeyParent1 + ".uvTransform.uvOffset", + tileParent1.uvTransform.uvOffset); // The texture needs a unit to sample from - texUnitHeight[i].activate(); - tile.texture->bind(); + texUnitHeightParent2[i].activate(); + tileParent2.texture->bind(); - std::string indexedTileKey = "heightTiles[" + std::to_string(i) + "]"; + std::string indexedTileKeyParent2 = "heightTilesParent2[" + std::to_string(i) + "]"; // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKey + ".textureSampler", texUnitHeight[i]); + programObject->setUniform(indexedTileKeyParent2 + ".textureSampler", texUnitHeightParent2[i]); programObject->setUniform( - indexedTileKey + ".uvTransform.uvScale", - tile.uvTransform.uvScale); + indexedTileKeyParent2 + ".uvTransform.uvScale", + tileParent2.uvTransform.uvScale); programObject->setUniform( - indexedTileKey + ".uvTransform.uvOffset", - tile.uvTransform.uvOffset); - - programObject->setUniform( - indexedTileKey + ".depthTransform.depthScale", - depthTransform.depthScale); - programObject->setUniform( - indexedTileKey + ".depthTransform.depthOffset", - depthTransform.depthOffset); - - // If blending is enabled, two more textures are needed - if (layeredTextureInfoHeight.layerBlendingEnabled) { - Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); - Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); - - if (tileParent1.texture == nullptr) { - tileParent1 = tile; - } - if (tileParent2.texture == nullptr) { - tileParent2 = tileParent1; - } - - // Blend tile with two parents - // The texture needs a unit to sample from - texUnitHeightParent1[i].activate(); - tileParent1.texture->bind(); - - std::string indexedTileKeyParent1 = "heightTilesParent1[" + std::to_string(i) + "]"; - // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKeyParent1 + ".textureSampler", texUnitHeightParent1[i]); - - programObject->setUniform( - indexedTileKeyParent1 + ".uvTransform.uvScale", - tileParent1.uvTransform.uvScale); - programObject->setUniform( - indexedTileKeyParent1 + ".uvTransform.uvOffset", - tileParent1.uvTransform.uvOffset); - - - // The texture needs a unit to sample from - texUnitHeightParent2[i].activate(); - tileParent2.texture->bind(); - - std::string indexedTileKeyParent2 = "heightTilesParent2[" + std::to_string(i) + "]"; - // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKeyParent2 + ".textureSampler", texUnitHeightParent2[i]); - - programObject->setUniform( - indexedTileKeyParent2 + ".uvTransform.uvScale", - tileParent2.uvTransform.uvScale); - programObject->setUniform( - indexedTileKeyParent2 + ".uvTransform.uvOffset", - tileParent2.uvTransform.uvOffset); - } - - i++; + indexedTileKeyParent2 + ".uvTransform.uvOffset", + tileParent2.uvTransform.uvOffset); } + + i++; } - if (layeredTextureInfoColor.useThisLayerType) { + // Go through all the color texture providers + i = 0; + for (auto it = colorTextureProviders.begin(); it != colorTextureProviders.end(); it++) + { + auto tileProvider = it->get(); + // Get the texture that should be used for rendering + Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); - // Go through all the color texture providers - int i = 0; - for (auto it = colorTextureProviders.begin(); it != colorTextureProviders.end(); it++) - { - auto tileProvider = it->get(); - // Get the texture that should be used for rendering - Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); + if (tile.texture == nullptr) { + // don't render if no tile was available + programObject->deactivate(); + return; + } - if (tile.texture == nullptr) { - // don't render if no tile was available - programObject->deactivate(); - return; + // The texture needs a unit to sample from + texUnitColor[i].activate(); + tile.texture->bind(); + + std::string indexedTileKey = "colorTiles[" + std::to_string(i) + "]"; + // Send uniforms for the tile to the shader + programObject->setUniform(indexedTileKey + ".textureSampler", texUnitColor[i]); + + programObject->setUniform( + indexedTileKey + ".uvTransform.uvScale", + tile.uvTransform.uvScale); + programObject->setUniform( + indexedTileKey + ".uvTransform.uvOffset", + tile.uvTransform.uvOffset); + + // If blending is enabled, two more textures are needed + if (layeredTextureInfoColor.layerBlendingEnabled) { + Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); + Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); + + if (tileParent1.texture == nullptr) { + tileParent1 = tile; } + if (tileParent2.texture == nullptr) { + tileParent2 = tileParent1; + } + + // Blend tile with two parents + // The texture needs a unit to sample from + texUnitColorParent1[i].activate(); + tileParent1.texture->bind(); + + std::string indexedTileKeyParent1 = "colorTilesParent1[" + std::to_string(i) + "]"; + // Send uniforms for the tile to the shader + programObject->setUniform(indexedTileKeyParent1 + ".textureSampler", texUnitColorParent1[i]); + + programObject->setUniform( + indexedTileKeyParent1 + ".uvTransform.uvScale", + tileParent1.uvTransform.uvScale); + programObject->setUniform( + indexedTileKeyParent1 + ".uvTransform.uvOffset", + tileParent1.uvTransform.uvOffset); + // The texture needs a unit to sample from - texUnitColor[i].activate(); - tile.texture->bind(); + texUnitColorParent2[i].activate(); + tileParent2.texture->bind(); - std::string indexedTileKey = "colorTiles[" + std::to_string(i) + "]"; + std::string indexedTileKeyParent2 = "colorTilesParent2[" + std::to_string(i) + "]"; // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKey + ".textureSampler", texUnitColor[i]); + programObject->setUniform(indexedTileKeyParent2 + ".textureSampler", texUnitColorParent2[i]); programObject->setUniform( - indexedTileKey + ".uvTransform.uvScale", - tile.uvTransform.uvScale); + indexedTileKeyParent2 + ".uvTransform.uvScale", + tileParent2.uvTransform.uvScale); programObject->setUniform( - indexedTileKey + ".uvTransform.uvOffset", - tile.uvTransform.uvOffset); - - // If blending is enabled, two more textures are needed - if (layeredTextureInfoColor.layerBlendingEnabled) { - Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); - Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); - - if (tileParent1.texture == nullptr) { - tileParent1 = tile; - } - if (tileParent2.texture == nullptr) { - tileParent2 = tileParent1; - } - - // Blend tile with two parents - // The texture needs a unit to sample from - texUnitColorParent1[i].activate(); - tileParent1.texture->bind(); - - std::string indexedTileKeyParent1 = "colorTilesParent1[" + std::to_string(i) + "]"; - // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKeyParent1 + ".textureSampler", texUnitColorParent1[i]); - - programObject->setUniform( - indexedTileKeyParent1 + ".uvTransform.uvScale", - tileParent1.uvTransform.uvScale); - programObject->setUniform( - indexedTileKeyParent1 + ".uvTransform.uvOffset", - tileParent1.uvTransform.uvOffset); - - - // The texture needs a unit to sample from - texUnitColorParent2[i].activate(); - tileParent2.texture->bind(); - - std::string indexedTileKeyParent2 = "colorTilesParent2[" + std::to_string(i) + "]"; - // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKeyParent2 + ".textureSampler", texUnitColorParent2[i]); - - programObject->setUniform( - indexedTileKeyParent2 + ".uvTransform.uvScale", - tileParent2.uvTransform.uvScale); - programObject->setUniform( - indexedTileKeyParent2 + ".uvTransform.uvOffset", - tileParent2.uvTransform.uvOffset); - } - i++; + indexedTileKeyParent2 + ".uvTransform.uvOffset", + tileParent2.uvTransform.uvOffset); } + i++; + } + + // This information is only needed when doing blending + if ((numHeightMapProviders > 0 && layeredTextureInfoHeight.layerBlendingEnabled) || + (numColorTextureProviders > 0 && layeredTextureInfoColor.layerBlendingEnabled)) { + float distanceScaleFactor = chunk.owner()->lodScaleFactor * ellipsoid.minimumRadius(); + programObject->setUniform("cameraPosition", vec3(data.camera.positionVec3())); + programObject->setUniform("distanceScaleFactor", distanceScaleFactor); + programObject->setUniform("chunkLevel", chunk.index().level); } // Calculate other uniform variables needed for rendering @@ -353,7 +349,6 @@ namespace openspace { mat4 viewTransform = data.camera.combinedViewMatrix(); mat4 modelViewProjectionTransform = data.camera.projectionMatrix() * viewTransform * modelTransform; - const Ellipsoid& ellipsoid = chunk.owner()->ellipsoid(); // Upload the uniform variables programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform); @@ -365,15 +360,6 @@ namespace openspace { // The length of the skirts is proportional to its size programObject->setUniform("skirtLength", static_cast(chunk.surfacePatch().halfSize().lat * 1000000)); - // This information is only needed when doing blending - if ((layeredTextureInfoHeight.useThisLayerType && layeredTextureInfoHeight.layerBlendingEnabled) || - (layeredTextureInfoColor.useThisLayerType && layeredTextureInfoColor.layerBlendingEnabled)) { - float distanceScaleFactor = chunk.owner()->lodScaleFactor * ellipsoid.minimumRadius(); - programObject->setUniform("cameraPosition", vec3(data.camera.positionVec3())); - programObject->setUniform("distanceScaleFactor", distanceScaleFactor); - programObject->setUniform("chunkLevel", chunk.index().level); - } - // OpenGL rendering settings glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); @@ -390,6 +376,8 @@ namespace openspace { { using namespace glm; + const Ellipsoid& ellipsoid = chunk.owner()->ellipsoid(); + // All providers of tiles auto heightMapProviders = _tileProviderManager->getActiveHeightMapProviders(); auto colorTextureProviders = _tileProviderManager->getActiveColorTextureProviders(); @@ -397,25 +385,18 @@ namespace openspace { int numHeightMapProviders = heightMapProviders.size(); int numColorTextureProviders = colorTextureProviders.size(); - - if (numHeightMapProviders == 0 || numColorTextureProviders == 0) { - return; - } - // Create information for the shader provider LayeredTextureInfo layeredTextureInfoHeight; LayeredTextureInfo layeredTextureInfoColor; layeredTextureInfoHeight.keyLastLayerIndex = "lastLayerIndexHeight"; layeredTextureInfoHeight.lastLayerIndex = numHeightMapProviders - 1; layeredTextureInfoHeight.keyUseThisLayerType = "useHeightMap"; - layeredTextureInfoHeight.useThisLayerType = chunk.owner()->useHeightMap; layeredTextureInfoHeight.keyLayerBlendingEnabled = "heightMapBlendingEnabled"; layeredTextureInfoHeight.layerBlendingEnabled = chunk.owner()->blendHeightMap; layeredTextureInfoColor.keyLastLayerIndex = "lastLayerIndexColor"; layeredTextureInfoColor.lastLayerIndex = numColorTextureProviders - 1; layeredTextureInfoColor.keyUseThisLayerType = "useColorTexture"; - layeredTextureInfoColor.useThisLayerType = chunk.owner()->useColorMap; layeredTextureInfoColor.keyLayerBlendingEnabled = "colorTextureBlendingEnabled"; layeredTextureInfoColor.layerBlendingEnabled = chunk.owner()->blendColorMap; @@ -450,173 +431,174 @@ namespace openspace { texUnitColorParent1.resize(numColorTextureProviders); texUnitColorParent2.resize(numColorTextureProviders); + // Go through all the height map providers + int i = 0; + for (auto it = heightMapProviders.begin(); it != heightMapProviders.end(); it++) + { + auto tileProvider = it->get(); + // Get the texture that should be used for rendering + Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); - if (layeredTextureInfoHeight.useThisLayerType) { + if (tile.texture == nullptr) { + // don't render if no tile was available + programObject->deactivate(); + return; + } + TileDepthTransform depthTransform = tileProvider->depthTransform(); - // Go through all the color texture providers - int i = 0; - for (auto it = heightMapProviders.begin(); it != heightMapProviders.end(); it++) - { - auto tileProvider = it->get(); - // Get the texture that should be used for rendering - Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); - if (tile.texture == nullptr) { - // don't render if no tile was available - programObject->deactivate(); - return; + // The texture needs a unit to sample from + texUnitHeight[i].activate(); + tile.texture->bind(); + + std::string indexedTileKey = "heightTiles[" + std::to_string(i) + "]"; + // Send uniforms for the tile to the shader + programObject->setUniform(indexedTileKey + ".textureSampler", texUnitHeight[i]); + + programObject->setUniform( + indexedTileKey + ".uvTransform.uvScale", + tile.uvTransform.uvScale); + programObject->setUniform( + indexedTileKey + ".uvTransform.uvOffset", + tile.uvTransform.uvOffset); + + programObject->setUniform( + indexedTileKey + ".depthTransform.depthScale", + depthTransform.depthScale); + programObject->setUniform( + indexedTileKey + ".depthTransform.depthOffset", + depthTransform.depthOffset); + + // If blending is enabled, two more textures are needed + if (layeredTextureInfoHeight.layerBlendingEnabled) { + Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); + Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); + + if (tileParent1.texture == nullptr) { + tileParent1 = tile; } - TileDepthTransform depthTransform = tileProvider->depthTransform(); + if (tileParent2.texture == nullptr) { + tileParent2 = tileParent1; + } + + // Blend tile with two parents + // The texture needs a unit to sample from + texUnitHeightParent1[i].activate(); + tileParent1.texture->bind(); + + std::string indexedTileKeyParent1 = "heightTilesParent1[" + std::to_string(i) + "]"; + // Send uniforms for the tile to the shader + programObject->setUniform(indexedTileKeyParent1 + ".textureSampler", texUnitHeightParent1[i]); + + programObject->setUniform( + indexedTileKeyParent1 + ".uvTransform.uvScale", + tileParent1.uvTransform.uvScale); + programObject->setUniform( + indexedTileKeyParent1 + ".uvTransform.uvOffset", + tileParent1.uvTransform.uvOffset); // The texture needs a unit to sample from - texUnitHeight[i].activate(); - tile.texture->bind(); + texUnitHeightParent2[i].activate(); + tileParent2.texture->bind(); - std::string indexedTileKey = "heightTiles[" + std::to_string(i) + "]"; + std::string indexedTileKeyParent2 = "heightTilesParent2[" + std::to_string(i) + "]"; // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKey + ".textureSampler", texUnitHeight[i]); + programObject->setUniform(indexedTileKeyParent2 + ".textureSampler", texUnitHeightParent2[i]); programObject->setUniform( - indexedTileKey + ".uvTransform.uvScale", - tile.uvTransform.uvScale); + indexedTileKeyParent2 + ".uvTransform.uvScale", + tileParent2.uvTransform.uvScale); programObject->setUniform( - indexedTileKey + ".uvTransform.uvOffset", - tile.uvTransform.uvOffset); - - programObject->setUniform( - indexedTileKey + ".depthTransform.depthScale", - depthTransform.depthScale); - programObject->setUniform( - indexedTileKey + ".depthTransform.depthOffset", - depthTransform.depthOffset); - - // If blending is enabled, two more textures are needed - if (layeredTextureInfoHeight.layerBlendingEnabled) { - Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); - Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); - - if (tileParent1.texture == nullptr) { - tileParent1 = tile; - } - if (tileParent2.texture == nullptr) { - tileParent2 = tileParent1; - } - - // Blend tile with two parents - // The texture needs a unit to sample from - texUnitHeightParent1[i].activate(); - tileParent1.texture->bind(); - - std::string indexedTileKeyParent1 = "heightTilesParent1[" + std::to_string(i) + "]"; - // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKeyParent1 + ".textureSampler", texUnitHeightParent1[i]); - - programObject->setUniform( - indexedTileKeyParent1 + ".uvTransform.uvScale", - tileParent1.uvTransform.uvScale); - programObject->setUniform( - indexedTileKeyParent1 + ".uvTransform.uvOffset", - tileParent1.uvTransform.uvOffset); - - - // The texture needs a unit to sample from - texUnitHeightParent2[i].activate(); - tileParent2.texture->bind(); - - std::string indexedTileKeyParent2 = "heightTilesParent2[" + std::to_string(i) + "]"; - // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKeyParent2 + ".textureSampler", texUnitHeightParent2[i]); - - programObject->setUniform( - indexedTileKeyParent2 + ".uvTransform.uvScale", - tileParent2.uvTransform.uvScale); - programObject->setUniform( - indexedTileKeyParent2 + ".uvTransform.uvOffset", - tileParent2.uvTransform.uvOffset); - } - - i++; + indexedTileKeyParent2 + ".uvTransform.uvOffset", + tileParent2.uvTransform.uvOffset); } + + i++; } - if (layeredTextureInfoColor.useThisLayerType) { + // Go through all the color texture providers + i = 0; + for (auto it = colorTextureProviders.begin(); it != colorTextureProviders.end(); it++) + { + auto tileProvider = it->get(); + // Get the texture that should be used for rendering + Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); - // Go through all the color texture providers - int i = 0; - for (auto it = colorTextureProviders.begin(); it != colorTextureProviders.end(); it++) - { - auto tileProvider = it->get(); - // Get the texture that should be used for rendering - Tile tile = tileProvider->getHighestResolutionTile(chunk.index()); + if (tile.texture == nullptr) { + // don't render if no tile was available + programObject->deactivate(); + return; + } - if (tile.texture == nullptr) { - // don't render if no tile was available - programObject->deactivate(); - return; + // The texture needs a unit to sample from + texUnitColor[i].activate(); + tile.texture->bind(); + + std::string indexedTileKey = "colorTiles[" + std::to_string(i) + "]"; + // Send uniforms for the tile to the shader + programObject->setUniform(indexedTileKey + ".textureSampler", texUnitColor[i]); + + programObject->setUniform( + indexedTileKey + ".uvTransform.uvScale", + tile.uvTransform.uvScale); + programObject->setUniform( + indexedTileKey + ".uvTransform.uvOffset", + tile.uvTransform.uvOffset); + + // If blending is enabled, two more textures are needed + if (layeredTextureInfoColor.layerBlendingEnabled) { + Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); + Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); + + if (tileParent1.texture == nullptr) { + tileParent1 = tile; } + if (tileParent2.texture == nullptr) { + tileParent2 = tileParent1; + } + + // Blend tile with two parents + // The texture needs a unit to sample from + texUnitColorParent1[i].activate(); + tileParent1.texture->bind(); + + std::string indexedTileKeyParent1 = "colorTilesParent1[" + std::to_string(i) + "]"; + // Send uniforms for the tile to the shader + programObject->setUniform(indexedTileKeyParent1 + ".textureSampler", texUnitColorParent1[i]); + + programObject->setUniform( + indexedTileKeyParent1 + ".uvTransform.uvScale", + tileParent1.uvTransform.uvScale); + programObject->setUniform( + indexedTileKeyParent1 + ".uvTransform.uvOffset", + tileParent1.uvTransform.uvOffset); + // The texture needs a unit to sample from - texUnitColor[i].activate(); - tile.texture->bind(); + texUnitColorParent2[i].activate(); + tileParent2.texture->bind(); - std::string indexedTileKey = "colorTiles[" + std::to_string(i) + "]"; + std::string indexedTileKeyParent2 = "colorTilesParent2[" + std::to_string(i) + "]"; // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKey + ".textureSampler", texUnitColor[i]); + programObject->setUniform(indexedTileKeyParent2 + ".textureSampler", texUnitColorParent2[i]); programObject->setUniform( - indexedTileKey + ".uvTransform.uvScale", - tile.uvTransform.uvScale); + indexedTileKeyParent2 + ".uvTransform.uvScale", + tileParent2.uvTransform.uvScale); programObject->setUniform( - indexedTileKey + ".uvTransform.uvOffset", - tile.uvTransform.uvOffset); - - // If blending is enabled, two more textures are needed - if (layeredTextureInfoColor.layerBlendingEnabled) { - Tile tileParent1 = tileProvider->getHighestResolutionTile(chunk.index(), 1); - Tile tileParent2 = tileProvider->getHighestResolutionTile(chunk.index(), 2); - - if (tileParent1.texture == nullptr) { - tileParent1 = tile; - } - if (tileParent2.texture == nullptr) { - tileParent2 = tileParent1; - } - - // Blend tile with two parents - // The texture needs a unit to sample from - texUnitColorParent1[i].activate(); - tileParent1.texture->bind(); - - std::string indexedTileKeyParent1 = "colorTilesParent1[" + std::to_string(i) + "]"; - // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKeyParent1 + ".textureSampler", texUnitColorParent1[i]); - - programObject->setUniform( - indexedTileKeyParent1 + ".uvTransform.uvScale", - tileParent1.uvTransform.uvScale); - programObject->setUniform( - indexedTileKeyParent1 + ".uvTransform.uvOffset", - tileParent1.uvTransform.uvOffset); - - - // The texture needs a unit to sample from - texUnitColorParent2[i].activate(); - tileParent2.texture->bind(); - - std::string indexedTileKeyParent2 = "colorTilesParent2[" + std::to_string(i) + "]"; - // Send uniforms for the tile to the shader - programObject->setUniform(indexedTileKeyParent2 + ".textureSampler", texUnitColorParent2[i]); - - programObject->setUniform( - indexedTileKeyParent2 + ".uvTransform.uvScale", - tileParent2.uvTransform.uvScale); - programObject->setUniform( - indexedTileKeyParent2 + ".uvTransform.uvOffset", - tileParent2.uvTransform.uvOffset); - } - i++; + indexedTileKeyParent2 + ".uvTransform.uvOffset", + tileParent2.uvTransform.uvOffset); } + i++; + } + + // This information is only needed when doing blending + if ((layeredTextureInfoHeight.layerBlendingEnabled && numHeightMapProviders > 0) || + (layeredTextureInfoColor.layerBlendingEnabled && numColorTextureProviders > 0)) { + float distanceScaleFactor = chunk.owner()->lodScaleFactor * chunk.owner()->ellipsoid().minimumRadius(); + programObject->setUniform("distanceScaleFactor", distanceScaleFactor); + programObject->setUniform("chunkLevel", chunk.index().level); } // Calculate other uniform variables needed for rendering @@ -631,8 +613,6 @@ namespace openspace { Geodetic2 nw = chunk.surfacePatch().northWestCorner(); Geodetic2 ne = chunk.surfacePatch().northEastCorner(); - const Ellipsoid& ellipsoid = chunk.owner()->ellipsoid(); - // Get model space positions of the four control points Vec3 patchSwModelSpace = ellipsoid.cartesianSurfacePosition(sw); Vec3 patchSeModelSpace = ellipsoid.cartesianSurfacePosition(se); @@ -667,13 +647,6 @@ namespace openspace { // The length of the skirts is proportional to its size programObject->setUniform("skirtLength", static_cast(chunk.surfacePatch().halfSize().lat * 1000000)); - // This information is only needed when doing blending - if ((layeredTextureInfoHeight.useThisLayerType && layeredTextureInfoHeight.layerBlendingEnabled) || - (layeredTextureInfoColor.useThisLayerType && layeredTextureInfoColor.layerBlendingEnabled)) { - float distanceScaleFactor = chunk.owner()->lodScaleFactor * chunk.owner()->ellipsoid().minimumRadius(); - programObject->setUniform("distanceScaleFactor", distanceScaleFactor); - programObject->setUniform("chunkLevel", chunk.index().level); - } // OpenGL rendering settings glEnable(GL_DEPTH_TEST); diff --git a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl index 88de53d8e0..1743051ef8 100644 --- a/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl +++ b/modules/globebrowsing/shaders/localchunkedlodpatch_fs.glsl @@ -27,9 +27,11 @@ #include "PowerScaling/powerScaling_fs.hglsl" #include "fragment.glsl" +#if USE_COLORTEXTURE uniform TextureTile colorTiles[NUMLAYERS_COLORTEXTURE]; uniform TextureTile colorTilesParent1[NUMLAYERS_COLORTEXTURE]; uniform TextureTile colorTilesParent2[NUMLAYERS_COLORTEXTURE]; +#endif // USE_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 diff --git a/modules/globebrowsing/shaders/texturetilemapping.hglsl b/modules/globebrowsing/shaders/texturetilemapping.hglsl index 24dab52dfb..bc1212ec5d 100644 --- a/modules/globebrowsing/shaders/texturetilemapping.hglsl +++ b/modules/globebrowsing/shaders/texturetilemapping.hglsl @@ -28,6 +28,7 @@ #include <${MODULE_GLOBEBROWSING}/shaders/texturetile.hglsl> #include <${MODULE_GLOBEBROWSING}/shaders/blending.hglsl> +// First layer type from LayeredTextureShaderProvider #ifndef NUMLAYERS_HEIGHTMAP #define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeight} + 1 #endif // NUMLAYERS_HEIGHTMAP @@ -40,9 +41,10 @@ #define HEIGHTMAP_BLENDING_ENABLED #{heightMapBlendingEnabled} #endif // HEIGHTMAP_BLENDING_ENABLED +// Second layer type from LayeredTextureShaderProvider #ifndef NUMLAYERS_COLORTEXTURE #define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColor} + 1 -#endif // NUMLAYERS_HEIGHTMAP +#endif // NUMLAYERS_COLORTEXTURE #ifndef USE_COLORTEXTURE #define USE_COLORTEXTURE #{useColorTexture} @@ -50,7 +52,7 @@ #ifndef COLORTEXTURE_BLENDING_ENABLED #define COLORTEXTURE_BLENDING_ENABLED #{colorTextureBlendingEnabled} -#endif // HEIGHTMAP_BLENDING_ENABLED +#endif // COLORTEXTURE_BLENDING_ENABLED float calculateHeight( const vec2 uv,