Skip to content

Commit

Permalink
Add mapnode option overlay_blending_source with default value 'alpha'…
Browse files Browse the repository at this point in the history
…, legal value 'color', to change the behavior of imageoverlay/draping blending function.
  • Loading branch information
gwaldron committed May 16, 2023
1 parent bae98fe commit 6fc9f66
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/osgEarth/DrapingTechnique
Expand Up @@ -86,6 +86,12 @@ namespace osgEarth { namespace Util
void setOverlayBlending( bool value );
bool getOverlayBlending() const { return _rttBlending; }

/**
* Set the blending function sources to use when overlay blending is true.
* Defaults are GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
*/
void setOverlayBlendingParams(GLenum src, GLenum dst);

/**
* Whether to attach the RTT to camera to the stencil buffer. Default = false.
* Some older cards don't have very good support
Expand Down Expand Up @@ -133,6 +139,8 @@ namespace osgEarth { namespace Util
bool _rttBlending;
bool _attachStencil;
double _maxFarNearRatio;
GLenum _overlaySource = GL_SRC_ALPHA;
GLenum _overlayDestination = GL_ONE_MINUS_SRC_ALPHA;

mutable std::shared_ptr<DrapingManager> _drapingManager;
std::shared_ptr<DrapingManager>& getDrapingManager() { return _drapingManager; }
Expand Down
11 changes: 9 additions & 2 deletions src/osgEarth/DrapingTechnique.cpp
Expand Up @@ -507,11 +507,11 @@ DrapingTechnique::setUpCamera(OverlayDecorator::TechRTTParams& params)
if (Registry::capabilities().supportsGLSL(140u))
{
//Blend Func Separate is only available on OpenGL 1.4 and above
blendFunc = new osg::BlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
blendFunc = new osg::BlendFunc(_overlaySource, _overlayDestination, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
else
{
blendFunc = new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
blendFunc = new osg::BlendFunc(_overlaySource, _overlayDestination);
}

rttStateSet->setAttributeAndModes(blendFunc, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
Expand Down Expand Up @@ -714,6 +714,13 @@ DrapingTechnique::setOverlayBlending( bool value )
}
}

void
DrapingTechnique::setOverlayBlendingParams(GLenum src, GLenum dst)
{
_overlaySource = src;
_overlayDestination = dst;
}

bool
DrapingTechnique::getAttachStencil() const
{
Expand Down
1 change: 1 addition & 0 deletions src/osgEarth/MapNode
Expand Up @@ -66,6 +66,7 @@ namespace osgEarth
OE_OPTION(ProxySettings, proxySettings);
OE_OPTION(bool, enableLighting);
OE_OPTION(bool, overlayBlending);
OE_OPTION(bool, overlayBlendingSource);
OE_OPTION(unsigned, overlayTextureSize);
OE_OPTION(bool, overlayMipMapping);
OE_OPTION(float, overlayResolutionRatio);
Expand Down
8 changes: 8 additions & 0 deletions src/osgEarth/MapNode.cpp
Expand Up @@ -196,6 +196,7 @@ MapNode::Options::getConfig() const
conf.set( "proxy", proxySettings() );
conf.set( "lighting", enableLighting() );
conf.set( "overlay_blending", overlayBlending() );
conf.set( "overlay_blending_source", overlayBlendingSource());
conf.set( "overlay_texture_size", overlayTextureSize() );
conf.set( "overlay_mipmapping", overlayMipMapping() );
conf.set( "overlay_resolution_ratio", overlayResolutionRatio() );
Expand All @@ -215,6 +216,7 @@ MapNode::Options::fromConfig(const Config& conf)
proxySettings().init(ProxySettings());
enableLighting().init(true);
overlayBlending().init(true);
overlayBlendingSource().init("alpha");
overlayMipMapping().init(false);
overlayTextureSize().init(4096);
overlayResolutionRatio().init(3.0f);
Expand All @@ -226,6 +228,7 @@ MapNode::Options::fromConfig(const Config& conf)
conf.get( "proxy", proxySettings() );
conf.get( "lighting", enableLighting() );
conf.get( "overlay_blending", overlayBlending() );
conf.get( "overlay_blending_source", overlayBlendingSource());
conf.get( "overlay_texture_size", overlayTextureSize() );
conf.get( "overlay_mipmapping", overlayMipMapping() );
conf.get( "overlay_resolution_ratio", overlayResolutionRatio() );
Expand Down Expand Up @@ -391,6 +394,11 @@ MapNode::open()
if ( options().overlayBlending().isSet() )
draping->setOverlayBlending( options().overlayBlending().get() );

if (options().overlayBlendingSource().isSetTo("color"))
draping->setOverlayBlendingParams(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
else if (options().overlayBlendingSource().isSetTo("alpha"))
draping->setOverlayBlendingParams(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

if ( envOverlayTextureSize )
draping->setTextureSize( as<int>(envOverlayTextureSize, 1024) );

Expand Down
11 changes: 11 additions & 0 deletions tests/annotation.earth
Expand Up @@ -3,6 +3,10 @@ osgEarth Sample - Annotations
-->
<map name="Annotations Demo">

<options>
<overlay_blending_source>alpha</overlay_blending_source>
</options>

<xi:include href="readymap_imagery.xml"/>
<xi:include href="readymap_elevation.xml"/>

Expand Down Expand Up @@ -183,6 +187,13 @@ osgEarth Sample - Annotations
</imageoverlay>
<label text="ImageOverlay" lat="26" long="-81"/>

<imageoverlay>
<url>../data/fractal.png</url>
<alpha>0.75</alpha>
<geometry>POLYGON((-81 28, -80.5 28, -80.5 28.5, -81 28.5))</geometry>
</imageoverlay>
<label text="ImageOverlay(alpha)" lat="28" long="-81"/>

<local_geometry name="3D geometry">
<geometry>
POLYGON((0 0 0, -25000 0 45000, 0 0 75000, 25000 0 45000))
Expand Down

0 comments on commit 6fc9f66

Please sign in to comment.