From d08447db3ca3ed3498dd400520d8cf19e611cc54 Mon Sep 17 00:00:00 2001 From: Glenn Waldron Date: Wed, 25 Sep 2024 11:07:58 -0400 Subject: [PATCH] Rex: update so you can set the terrain color and other uniform-based terrain options dynamically at runtime, and add a color slider to the imgui panel; also clean up some old debugging code in the normal map shaders --- .../engine_rex/RexEngine.NormalMap.GL4.glsl | 15 --------------- .../engine_rex/RexEngine.NormalMap.glsl | 15 --------------- .../engine_rex/RexTerrainEngineNode.cpp | 12 +----------- src/osgEarthDrivers/engine_rex/TileNode.cpp | 18 +++++++++++------- src/osgEarthImGui/TerrainGUI | 7 +++++++ 5 files changed, 19 insertions(+), 48 deletions(-) diff --git a/src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.GL4.glsl b/src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.GL4.glsl index e6f60e2a7a..363da572ad 100644 --- a/src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.GL4.glsl +++ b/src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.GL4.glsl @@ -30,8 +30,6 @@ void oe_rex_normalMapVS(inout vec4 unused) #pragma vp_function oe_rex_normalMapFS, fragment_coloring, 0.1 #pragma import_defines(OE_TERRAIN_RENDER_NORMAL_MAP) -#pragma import_defines(OE_DEBUG_NORMALS) -#pragma import_defines(OE_DEBUG_CURVATURE) in vec3 vp_Normal; in vec3 oe_UpVectorView; @@ -61,17 +59,4 @@ void oe_rex_normalMapFS(inout vec4 color) vp_Normal = normalize( oe_normalMapTBN*N.xyz ); } #endif - -#ifdef OE_DEBUG_CURVATURE - // visualize curvature quantized: - color.rgba = vec4(0, 0, 0, 1); - float curvature = N.w; - if (curvature > 0.0) color.r = curvature; - if (curvature < 0.0) color.g = -curvature; -#endif - -#ifdef OE_DEBUG_NORMALS - // visualize normals: - color.rgb = (N.xyz + 1.0)*0.5; -#endif } diff --git a/src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.glsl b/src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.glsl index 9bbec09e4b..60fa3ea6e3 100644 --- a/src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.glsl +++ b/src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.glsl @@ -45,8 +45,6 @@ void oe_rex_normalMapVS(inout vec4 unused) #pragma vp_order 0.1 #pragma import_defines(OE_TERRAIN_RENDER_NORMAL_MAP) -#pragma import_defines(OE_DEBUG_NORMALS) -#pragma import_defines(OE_DEBUG_CURVATURE) // import terrain SDK vec4 oe_terrain_getNormalAndCurvature(in vec2); @@ -72,17 +70,4 @@ void oe_rex_normalMapFS(inout vec4 color) vec3 tangent = normalize(cross(oe_normal_binormal, oe_UpVectorView)); oe_normalMapTBN = mat3(tangent, oe_normal_binormal, oe_UpVectorView); vp_Normal = normalize(oe_normalMapTBN*N.xyz); - -#ifdef OE_DEBUG_CURVATURE - // visualize curvature quantized: - color.rgba = vec4(0, 0, 0, 1); - float curvature = N.w; - if (curvature > 0.0) color.r = curvature; - if (curvature < 0.0) color.g = -curvature; -#endif - -#ifdef OE_DEBUG_NORMALS - // visualize normals: - color.rgb = (N.xyz + 1.0)*0.5; -#endif } \ No newline at end of file diff --git a/src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp b/src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp index 594fd6211f..b7ff18d5ab 100644 --- a/src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp +++ b/src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp @@ -276,12 +276,6 @@ RexTerrainEngineNode::onSetMap() _morphTerrainSupported = false; } - // Check for normals debugging. - if (::getenv("OSGEARTH_DEBUG_NORMALS")) - getOrCreateStateSet()->setDefine("OE_DEBUG_NORMALS"); - else - if (getStateSet()) getStateSet()->removeDefine("OE_DEBUG_NORMALS"); - // check for normal map generation (required for lighting). _requirements.normalTextures = (options.getUseNormalMaps() == true); @@ -732,11 +726,7 @@ RexTerrainEngineNode::dirtyTerrainOptions() jobs::get_pool(ARENA_LOAD_TILE)->set_concurrency(options.getConcurrency()); - getSurfaceStateSet()->getOrCreateUniform( - "oe_terrain_tess", osg::Uniform::FLOAT)->set(options.getTessellationLevel()); - - getSurfaceStateSet()->getOrCreateUniform( - "oe_terrain_tess_range", osg::Uniform::FLOAT)->set(options.getTessellationRange()); + updateState(); } void diff --git a/src/osgEarthDrivers/engine_rex/TileNode.cpp b/src/osgEarthDrivers/engine_rex/TileNode.cpp index 69f9b2f886..1399f47476 100644 --- a/src/osgEarthDrivers/engine_rex/TileNode.cpp +++ b/src/osgEarthDrivers/engine_rex/TileNode.cpp @@ -347,22 +347,26 @@ TileNode::shouldSubDivide(TerrainCuller* culler, const SelectionInfo& selectionI // allowable on-screen tile size in pixels. if (_context->options().getLODMethod() == LODMethod::SCREEN_SPACE) { - float tileSizeInPixels = -1.0; + // assume the imagery of a tile to be this dimension (pixels). If so, once the + // size of tile geometry on screen exceeds that, it's time to subdivide. + float tileImagerySize = _context->options().getTilePixelSize(); + + float tileGeometrySizeInPixels = -1.0; if (context->getEngine()->getComputeTilePixelSizeCallback()) { - tileSizeInPixels = (context->getEngine()->getComputeTilePixelSizeCallback())(this, *culler->_cv); + tileGeometrySizeInPixels = (context->getEngine()->getComputeTilePixelSizeCallback())(this, *culler->_cv); } - if (tileSizeInPixels <= 0.0) + if (tileGeometrySizeInPixels <= 0.0) { - tileSizeInPixels = _surface->getPixelSizeOnScreen(culler); + tileGeometrySizeInPixels = _surface->getPixelSizeOnScreen(culler); } - float effectivePixelSize = - _context->options().getTilePixelSize() + _context->options().getScreenSpaceError(); + // SSE is the amount of error we are willing to tolerate in the screen space size + float pixelSizeThreshold = tileImagerySize + _context->options().getScreenSpaceError(); - return (tileSizeInPixels > effectivePixelSize); + return (tileGeometrySizeInPixels > pixelSizeThreshold); } // In DISTANCE-TO-EYE mode, use the visibility ranges precomputed in the SelectionInfo. diff --git a/src/osgEarthImGui/TerrainGUI b/src/osgEarthImGui/TerrainGUI index c58ca70674..23bfd19814 100644 --- a/src/osgEarthImGui/TerrainGUI +++ b/src/osgEarthImGui/TerrainGUI @@ -138,6 +138,13 @@ namespace osgEarth } } + Color color = options.getColor(); + if (ImGuiLTable::ColorEdit3("Background", color.ptr())) + { + options.setColor(color); + engine->dirtyTerrainOptions(); + } + if (GLUtils::useNVGL()) { unsigned maxTex = options.getMaxTextureSize();