Commit a05fac83 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] overlay now blends out automatically after startup.

parent ce9d8241
......@@ -42,6 +42,14 @@
WGEViewerEffectImageOverlay::WGEViewerEffectImageOverlay():
WGEViewerEffect( "Image Overlay", "Blend in some arbitrary image." )
{
m_blendOutAuto = m_properties->addProperty( "Auto Blend-Out",
"Make the overlay blend out automatically after a given amount of time.", true );
m_blendOutDuration = m_properties->addProperty( "Blend-Out Duration",
"Make the overlay blend out after this amount of time in seconds.", 4.0 );
m_blendOutDuration->setMin( 0.0 );
m_blendOutDuration->setMax( 60.0 );
m_image = m_properties->addProperty( "Image", "The Image to use.", WPathHelper::getSharePath() / "GE" / "overlay.png" );
WPropDouble scale = m_properties->addProperty( "Scale", "Scale the image in percent.", 50.0 );
scale->setMin( 0.0 );
......@@ -83,11 +91,28 @@ WGEViewerEffectImageOverlay::WGEViewerEffectImageOverlay():
m_state->addUniform( new WGEPropertyUniform< WPropBool >( "u_toRight", moveToRight ) );
m_state->addUniform( new WGEPropertyUniform< WPropDouble >( "u_overlayOpacity", opacity ) );
m_state->addUniform( new WGEPropertyUniform< WPropBool >( "u_overlayAutoBlendOut", m_blendOutAuto ) );
m_state->addUniform( new WGEPropertyUniform< WPropDouble >( "u_overlayBlendOutDuration", m_blendOutDuration ) );
// add a callback which handles changes in viewport size
m_updater = new Updater();
addUpdateCallback( m_updater );
// also add an animation timer
osg::Uniform* animationTime(
new osg::Uniform(
"u_blendOutTimer", // a name.
0 // initial value, type of this parameter defines the uniform type in GLSL!
)
);
// use the predefined timer callback:
osg::ref_ptr< WGEShaderAnimationCallback > m_animationCallback = new WGEShaderAnimationCallback();
animationTime->setUpdateCallback( m_animationCallback );
// bind to geode
m_geode->getOrCreateStateSet()->addUniform( animationTime );
// bind
m_state->setTextureAttributeAndModes( 0, m_logoTexture, osg::StateAttribute::ON );
}
......
......@@ -29,6 +29,8 @@
#include "core/common/WLogger.h"
#include "callbacks/WGEShaderAnimationCallback.h"
#include "WGEViewerEffect.h"
class WGEViewer;
......@@ -105,6 +107,21 @@ protected:
*/
WPropFilename m_image;
/**
* Enable to blend out the overlay.
*/
WPropBool m_blendOutAuto;
/**
* Time to blend out in seconds.
*/
WPropDouble m_blendOutDuration;
/**
* Animate blend out sequence
*/
osg::ref_ptr< WGEShaderAnimationCallback > m_animationCallback;
/**
* The texture.
*/
......
......@@ -69,6 +69,21 @@ uniform bool u_toTop = false;
*/
uniform float u_overlayOpacity;
/**
* Automatically blend out?
*/
uniform bool u_overlayAutoBlendOut;
/**
* Animation timer. 100 Ticks per sec
*/
uniform int u_blendOutTimer;
/**
* Howe long will it take to blend out? In seconds =
*/
uniform float u_overlayBlendOutDuration;
/**
* Pixel position in [0,1]
*/
......@@ -106,7 +121,12 @@ void main()
// overlay texture
vec4 tex = texture2D( u_overlay, coord );
// auto blend out?
float aSec = float( u_blendOutTimer ) / 100.0;
float autoBlendOut = 1.0 - ( aSec / u_overlayBlendOutDuration );
autoBlendOut = ( float( u_overlayAutoBlendOut ) * autoBlendOut ) + ( 1 - float( u_overlayAutoBlendOut ) );
// use texture coordinate to mix along the cylinder
gl_FragColor = vec4( tex.rgb, u_overlayOpacity * tex.a * valid );
gl_FragColor = vec4( tex.rgb, autoBlendOut* u_overlayOpacity * tex.a * valid );
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment