Skip to content

Commit

Permalink
Rex: update so you can set the terrain color and other uniform-based …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
gwaldron committed Sep 25, 2024
1 parent 95a05a1 commit d08447d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 48 deletions.
15 changes: 0 additions & 15 deletions src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.GL4.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
15 changes: 0 additions & 15 deletions src/osgEarthDrivers/engine_rex/RexEngine.NormalMap.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
}
12 changes: 1 addition & 11 deletions src/osgEarthDrivers/engine_rex/RexTerrainEngineNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions src/osgEarthDrivers/engine_rex/TileNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/osgEarthImGui/TerrainGUI
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d08447d

Please sign in to comment.